Commit e4324fb
committed
[pdata/pprofile] MergeTo: reserve index 0 of empty destination dictionary tables
Motivation:
Profiles.MergeTo remaps entries from the source dictionary into the
destination dictionary but never reserves index 0 of each destination
table for that table's zero value. profiles.proto requires that "the
element at index 0 MUST be the zero value for the dictionary's element
type" (e.g. "" for string_table), since every unset reference (e.g. an
unset Strindex) resolves to it. When the destination dictionary starts
out empty, the first entry switched over lands at index 0 instead of
the zero value, producing a non-conformant dictionary in which unset
references silently resolve to real data. This is a data-correctness
bug, not a crash: MergeTo itself does not panic or error. Concretely,
if the first string merged into an empty destination is some real
value (e.g. a semconv attribute key), any function/location that had
an unset filename/name (Strindex == 0) will report that unrelated
string as its filename/name after the merge, as described in the
issue's pprofreceiver-based repro. Destinations that are already
pre-populated with conformant zero values before calling MergeTo (the
existing convention used throughout this package's own tests) are
unaffected, since the fix only seeds tables that are still empty.
Approach:
Add reserveDictionaryZeroValues, called at the top of MergeTo (after
the self-merge no-op check, before switchDictionary runs). It seeds
index 0 of each of the destination dictionary's 7 tables (string,
attribute, function, link, location, mapping, stack) with that table's
zero value, but only for tables that are still empty. A table that
already holds entries is left untouched, since inserting at index 0
would shift every existing index and invalidate references already
pointing into it. This matches the fix suggested in the issue.
Validation:
Added TestProfilesMergeTo_ReservesDictionaryZeroValues, adapted from
the issue's reproduction: it merges a conformant source (whose index 0
in every table is already the zero value, plus one real string at
index 1) into a freshly empty destination, and asserts every
destination table's index-0 entry is the zero value while index 1
still holds the real value. Confirmed the test fails (wrong value,
then an index-out-of-range panic) when profiles_merge.go's fix is
reverted, and passes with it applied.
Ran:
cd pdata/pprofile && go build ./... && go vet ./... && go test ./...
All packages pass, including the existing MergeTo test suite in
profiles_merge_test.go, which already covers destinations that are
pre-populated with zero values by the caller and confirms no
regression there.
Fixes #15661
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>1 parent 52e6bf4 commit e4324fb
3 files changed
Lines changed: 116 additions & 0 deletions
File tree
- .chloggen
- pdata/pprofile
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
588 | 641 | | |
589 | 642 | | |
590 | 643 | | |
| |||
0 commit comments