Skip to content

fix nested shareable in arrays (python decoder only)#267

Merged
agronholm merged 4 commits intoagronholm:masterfrom
andreer:master
Dec 18, 2025
Merged

fix nested shareable in arrays (python decoder only)#267
agronholm merged 4 commits intoagronholm:masterfrom
andreer:master

Conversation

@andreer
Copy link
Copy Markdown
Contributor

@andreer andreer commented Dec 18, 2025

Changes

The Python decoder's decode_array() was not passing unshared=True when decoding array items, unlike decode_map() which correctly does this. This allowed nested shareable tags (tag 28) inside arrays to overwrite _share_index, causing subsequent shared references (tag 29) to resolve to the wrong object.

# [Tag 28 -> [Tag 28 -> 'a', 'b'], Tag 29 -> 0]
data = bytes.fromhex('82d81c82d81c61616162d81d00')
loads(data)
# Before: [['a', 'b'], 'b']  - shared ref returns 'b' instead of the array
# After:  [['a', 'b'], ['a', 'b']] - both elements are the same list object

The C decoder already handles this correctly.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (in docs/), in case of behavior changes or new
    features
  • You've added a new changelog entry (in docs/versionhistory.rst).

Updating the changelog

If there are no entries after the last release, use **UNRELEASED** as the version.
If, say, your patch fixes issue #123, the entry should look like this:

- Fix big bad boo-boo in the encoder
  (`#123 <https://github.com/agronholm/cbor2/issues/123>`_; PR by @yourgithubaccount)

If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 18, 2025

Coverage Status

coverage: 94.58%. remained the same
when pulling ad1d1ed on andreer:master
into f1d701c on agronholm:master.

@agronholm
Copy link
Copy Markdown
Owner

Please fix the pre-commit errors.

@andreer
Copy link
Copy Markdown
Contributor Author

andreer commented Dec 18, 2025

Will do.

@agronholm agronholm merged commit 403c2ce into agronholm:master Dec 18, 2025
13 checks passed
@agronholm
Copy link
Copy Markdown
Owner

Thanks again!

@agronholm
Copy link
Copy Markdown
Owner

Do you have more PRs coming in the short term, or should I cut a new release now?

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.

3 participants