Skip to content

[pdata] Fix CopyTo to deep-copy bytes oneof values - #15622

Open
nuromirg wants to merge 8 commits into
open-telemetry:mainfrom
nuromirg:pdata-copyto-deepcopy-bytes
Open

[pdata] Fix CopyTo to deep-copy bytes oneof values#15622
nuromirg wants to merge 8 commits into
open-telemetry:mainfrom
nuromirg:pdata-copyto-deepcopy-bytes

Conversation

@nuromirg

Copy link
Copy Markdown

Description

pcommon.Value.CopyTo performs a shallow copy for ValueTypeBytes. The destination and source Value share the same backing []byte array, so a later mutation of one corrupts the other. This breaks the documented deep-copy contract and propagates to every container that copies an AnyValue (Map.CopyTo, Slice.CopyTo, and any Resource/Scope/attribute copy carrying a bytes value).

CopyAnyValue copies the bytes oneof field by assigning the slice header:

ov.BytesValue = t.BytesValue

so it copies ptr/len/cap fields as well, and the backing array is becoming a shared one.

Ref:

This PR fixes the copyOther pdatagen template to deep-copy bytes oneof fields, matching the existing copyByteSlice helper, and regenerates the affected code.

Link to tracking issue

Fixes #15621

Testing

Added TestValue_CopyToBytesIsDeepCopy, which copies a bytes Value, 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

  • I, a human, wrote this pull request description myself.

nuromirg added 2 commits July 21, 2026 01:01
Signed-off-by: Nikita Rudakov <nuromirg@proton.me>
Signed-off-by: Nikita Rudakov <nuromirg@proton.me>
@nuromirg
nuromirg requested review from a team, bogdandrutu and dmitryax as code owners July 20, 2026 22:16
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 20, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: nuromirg / name: Nikita R. (ffb5fcb)
  • ✅ login: nuromirg / name: Nikita Rudakov (9f249de, b558188)

@dmitryax

Copy link
Copy Markdown
Member

Thanks @nuromirg

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.04%. Comparing base (1a861f0) to head (ffb5fcb).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value.CopyTo does not deep-copy bytes values

3 participants