[pdata] Fix CopyTo to deep-copy bytes oneof values - #15622
Open
nuromirg wants to merge 8 commits into
Open
Conversation
Signed-off-by: Nikita Rudakov <nuromirg@proton.me>
Signed-off-by: Nikita Rudakov <nuromirg@proton.me>
dmitryax
approved these changes
Jul 21, 2026
Member
|
Thanks @nuromirg |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15622 +/- ##
=======================================
Coverage 91.04% 91.04%
=======================================
Files 728 728
Lines 48455 48455
=======================================
Hits 44117 44117
Misses 3011 3011
Partials 1327 1327 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
florianl
approved these changes
Jul 21, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
pcommon.Value.CopyToperforms a shallow copy forValueTypeBytes. The destination and sourceValueshare the same backing[]bytearray, so a later mutation of one corrupts the other. This breaks the documented deep-copy contract and propagates to every container that copies anAnyValue(Map.CopyTo,Slice.CopyTo, and any Resource/Scope/attribute copy carrying a bytes value).CopyAnyValuecopies the bytes oneof field by assigning the slice header:so it copies
ptr/len/capfields as well, and the backing array is becoming a shared one.Ref:
opentelemetry-collector/pdata/internal/generated_proto_anyvalue.go
Line 320 in 1a861f0
This PR fixes the
copyOtherpdatagen template to deep-copy bytes oneof fields, matching the existingcopyByteSlicehelper, and regenerates the affected code.Link to tracking issue
Fixes #15621
Testing
Added
TestValue_CopyToBytesIsDeepCopy, which copies a bytesValue, mutates the copy, and asserts the source is unchanged (the same approach I used in the issue). The test fails on the previous code and passes with this fix.Authorship