From 539e77da4350740743c9dd98ee9d89001df90b72 Mon Sep 17 00:00:00 2001 From: Anton Kolesnikov Date: Wed, 26 Mar 2025 14:17:47 +0800 Subject: [PATCH 1/2] fix: drop malformed lines at compaction --- pkg/phlaredb/symdb/rewriter.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/phlaredb/symdb/rewriter.go b/pkg/phlaredb/symdb/rewriter.go index 61502e04c9..9f35438481 100644 --- a/pkg/phlaredb/symdb/rewriter.go +++ b/pkg/phlaredb/symdb/rewriter.go @@ -128,6 +128,10 @@ func (p *partitionRewriter) populateUnresolved(stacktraceIDs []uint32) error { for unresolvedLocs.Next() { location := p.src.Locations[unresolvedLocs.At()] location.MappingId = p.mappings.tryLookup(location.MappingId) + if len(p.src.Functions) == 0 { + location.Line = nil + continue + } for j, line := range location.Line { location.Line[j].FunctionId = p.functions.tryLookup(line.FunctionId) } From f4155313e0e9ad5c8f63a03b0cd537e0964fe1db Mon Sep 17 00:00:00 2001 From: Anton Kolesnikov Date: Mon, 28 Apr 2025 12:23:54 +0800 Subject: [PATCH 2/2] fix: remove invalid locations --- pkg/pprof/pprof.go | 3 ++ pkg/pprof/pprof_test.go | 46 ++++++++++++++---- .../testdata/malformed/no_addr_no_line.pb.gz | Bin 0 -> 1207 bytes 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 pkg/pprof/testdata/malformed/no_addr_no_line.pb.gz diff --git a/pkg/pprof/pprof.go b/pkg/pprof/pprof.go index 3e1f49ebed..c07171d72e 100644 --- a/pkg/pprof/pprof.go +++ b/pkg/pprof/pprof.go @@ -1313,6 +1313,9 @@ func sanitizeProfile(p *profilev1.Profile) { }) // Check locations again, verifying that all functions are valid. p.Location = slices.RemoveInPlace(p.Location, func(x *profilev1.Location, _ int) bool { + if len(x.Line) == 0 && x.Address == 0 { + return true + } for _, line := range x.Line { if line.FunctionId = t[line.FunctionId]; line.FunctionId == 0 { return true diff --git a/pkg/pprof/pprof_test.go b/pkg/pprof/pprof_test.go index fa001b561e..d03e9cddea 100644 --- a/pkg/pprof/pprof_test.go +++ b/pkg/pprof/pprof_test.go @@ -348,9 +348,9 @@ func Test_sanitizeReferences(t *testing.T) { {LocationId: []uint64{3, 2, 1}}, }, Location: []*profilev1.Location{ - {Id: 1, MappingId: 1}, - {Id: 3, MappingId: 5}, - {Id: 2, MappingId: 0}, + {Id: 1, MappingId: 1, Address: 1}, + {Id: 3, MappingId: 5, Address: 2}, + {Id: 2, MappingId: 0, Address: 3}, }, Mapping: []*profilev1.Mapping{ {Id: 1}, @@ -361,8 +361,8 @@ func Test_sanitizeReferences(t *testing.T) { {LocationId: []uint64{2, 1}}, }, Location: []*profilev1.Location{ - {Id: 1, MappingId: 1}, - {Id: 2, MappingId: 2}, + {Id: 1, MappingId: 1, Address: 1}, + {Id: 2, MappingId: 2, Address: 3}, }, Mapping: []*profilev1.Mapping{ {Id: 1}, @@ -379,14 +379,14 @@ func Test_sanitizeReferences(t *testing.T) { {LocationId: []uint64{5}}, }, Location: []*profilev1.Location{ - {Id: 1, MappingId: 1}, - {Id: 0, MappingId: 0}, + {Id: 1, MappingId: 1, Address: 0xa}, + {Id: 0, MappingId: 0, Address: 0xa}, }, }, expected: &profilev1.Profile{ Sample: []*profilev1.Sample{}, Location: []*profilev1.Location{ - {Id: 1, MappingId: 1}, + {Id: 1, MappingId: 1, Address: 0xa}, }, Mapping: []*profilev1.Mapping{ {Id: 1}, @@ -513,10 +513,13 @@ func Test_sanitize_fixtures(t *testing.T) { case filepath.Ext(path) == ".txt": return nil case d.IsDir(): - if d.Name() == "fuzz" { + switch d.Name() { + case "fuzz": + case "malformed": return fs.SkipDir + default: + return nil } - return nil } t.Run(path, func(t *testing.T) { @@ -1604,3 +1607,26 @@ func Test_SetProfileMetadata(t *testing.T) { } require.Equal(t, expected.String(), p.String()) } + +func Test_pprof_zero_addr_no_line_locations(t *testing.T) { + b, err := OpenFile("testdata/malformed/no_addr_no_line.pb.gz") + require.NoError(t, err) + + var found bool + for _, loc := range b.Location { + if len(loc.Line) == 0 && loc.Address == 0 { + found = true + break + } + } + if !found { + t.Fatal("invalid fixture") + } + + b.Normalize() + for _, loc := range b.Location { + if len(loc.Line) == 0 && loc.Address == 0 { + t.Fatal("found location without lines and address") + } + } +} diff --git a/pkg/pprof/testdata/malformed/no_addr_no_line.pb.gz b/pkg/pprof/testdata/malformed/no_addr_no_line.pb.gz new file mode 100644 index 0000000000000000000000000000000000000000..7c13dc4431b1f4eed5df9a4473abd479c91f38ed GIT binary patch literal 1207 zcmV;o1W5ZIiwFP!32ul4|9p>4XdG7($NhR7LC3=RYWz9c%tm;_9cQy}1wgpfl%d@$saQv!ip zl0X7ECOL$VLkQSN;}{dDL)E{2^{4)24h*ePr))E;z-_#J_hw`C>GI{FB9zL*j$5hX z$Y^bBe4Gv$_7AQ%4Hq07E8z`*fEqVB~^@O!QybE0P5kxllkR?tTA4kt`^X z3mlnv`$iwg0!{!nTH>Y8>g2!>GI8UV6|%r42a3qV2k)+s1w-TjAQKT8TjP{D$D z>+4<&N-wXUK+O{E3qbh)kR&8yx)6q6&;46F*pFgNxr5$c0g4;w0Hn!H+m`s39W< z#*m4l#G#5O$$@cXqDmYP4OL(QnYd?>4I}s^qYBiKiH{lCFp9qx$N_;&{Es-)aFZNp zAQM0w#_$BW&_pI8vSA$WGjd=OnJ5v530xuTy7J0f9+q(=g!Hc<5F$pI+I(SjZAH8zurz;D%Wy7N`mXUCDpFZ)TTE6c-D?( zrq@-Z;y}w*vaQ0{_|+{Hw<0Y~vXO_`j`5u^+mX5(<}wS~{-o)dT^&f3hJnn(ZJo(5 z&UKcx)7+m`W?TL#a52-V%5>|$dZ(>TzL;h@RhgDSl3Wk9@#_~K3XcPReN7t^Ch@^V zrgz%ftUpq)AWqWbw~BCgu1gR(=6%sMWPK8|X9-lUU}-!Fu2q#<9+PaXxIdBHdA$J|A|& zcu~qgMUj;LU)GW!RMB!f-}-kq&}kkf@cPs*wwW&XAeT||5Y2<4aB(%sg5t{NN?*r>pkI%m1p1h>gD%7*}Em4;=s_l VcKhzlMtbP?0RV}H*M@-x008=fP-FlA literal 0 HcmV?d00001