-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sanitize pprof references #3218
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
642a49f
fix: sanitize pprof references
kolesnikovae 97ebf88
Merge branch 'main' into fix/validate-pprof-references
kolesnikovae 412c359
fix: zero references test
kolesnikovae 047c7cf
fix: zero string handling
kolesnikovae e83b3df
handle negative string index
kolesnikovae f4f2e82
fix: add nil checks
kolesnikovae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package pprof | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/pprof/profile" | ||
"github.com/stretchr/testify/require" | ||
|
||
profilev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1" | ||
|
@@ -33,51 +35,6 @@ func Test_Merge_Self(t *testing.T) { | |
testhelper.EqualProto(t, p.Profile, m.Profile()) | ||
} | ||
|
||
func Test_Merge_ZeroReferences(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to remove the test as it's no longer valid: invalid elements are discarded at normalization/merge |
||
p, err := OpenFile("testdata/go.cpu.labels.pprof") | ||
require.NoError(t, err) | ||
|
||
t.Run("mappingID=0", func(t *testing.T) { | ||
before := p.Location[10] | ||
p.Location[10].MappingId = 0 | ||
defer func() { | ||
p.Location[10] = before | ||
}() | ||
|
||
var m ProfileMerge | ||
require.NoError(t, m.Merge(p.Profile)) | ||
|
||
testhelper.EqualProto(t, p.Profile, m.Profile()) | ||
}) | ||
|
||
t.Run("locationID=0", func(t *testing.T) { | ||
before := p.Sample[10].LocationId[0] | ||
p.Sample[10].LocationId[0] = 0 | ||
defer func() { | ||
p.Sample[10].LocationId[0] = before | ||
}() | ||
|
||
var m ProfileMerge | ||
require.NoError(t, m.Merge(p.Profile)) | ||
|
||
testhelper.EqualProto(t, p.Profile, m.Profile()) | ||
}) | ||
|
||
t.Run("functionID=0", func(t *testing.T) { | ||
before := p.Location[10].Line[0].FunctionId | ||
p.Location[10].Line[0].FunctionId = 0 | ||
defer func() { | ||
p.Location[10].Line[0].FunctionId = before | ||
}() | ||
|
||
var m ProfileMerge | ||
require.NoError(t, m.Merge(p.Profile)) | ||
|
||
testhelper.EqualProto(t, p.Profile, m.Profile()) | ||
}) | ||
|
||
} | ||
|
||
func Test_Merge_Halves(t *testing.T) { | ||
p, err := OpenFile("testdata/go.cpu.labels.pprof") | ||
require.NoError(t, err) | ||
|
@@ -470,3 +427,41 @@ func TestMergeEmpty(t *testing.T) { | |
}) | ||
require.NoError(t, err) | ||
} | ||
|
||
// Benchmark_Merge_self/pprof.MergeNoClone-10 4174 290190 ns/op | ||
// Benchmark_Merge_self/pprof.Merge-10 2722 421419 ns/op | ||
// Benchmark_Merge_self/profile.Merge-10 802 1417907 ns/op | ||
func Benchmark_Merge_self(b *testing.B) { | ||
d, err := os.ReadFile("testdata/go.cpu.labels.pprof") | ||
require.NoError(b, err) | ||
|
||
b.Run("pprof.MergeNoClone", func(b *testing.B) { | ||
p, err := RawFromBytes(d) | ||
require.NoError(b, err) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
var m ProfileMerge | ||
require.NoError(b, m.MergeNoClone(p.Profile.CloneVT())) | ||
} | ||
}) | ||
|
||
b.Run("pprof.Merge", func(b *testing.B) { | ||
p, err := RawFromBytes(d) | ||
require.NoError(b, err) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
var m ProfileMerge | ||
require.NoError(b, m.Merge(p.Profile.CloneVT())) | ||
} | ||
}) | ||
|
||
b.Run("profile.Merge", func(b *testing.B) { | ||
p, err := profile.ParseData(d) | ||
require.NoError(b, err) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err = profile.Merge([]*profile.Profile{p.Copy()}) | ||
require.NoError(b, err) | ||
} | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason we do it here is that
Merge
might be called withoutNormalize
. It is a fairly expensive operation, but it's better than a failure. Ideally, normalization and sanity checks should be performed at parsing