Fix decode_array double-reading length bytes for arrays with 24+ items - #479
Merged
Conversation
The custom decode_array override in serialization.py called _decode_length to check for indefinite-length arrays, then delegated to the original decode_array which called _decode_length again. For arrays with fewer than 24 items, the length is encoded directly in the subtype (no stream bytes consumed), so the double call was harmless. For 24+ items, CBOR uses multi-byte length encoding (e.g. 98 18 for 24 items) and _decode_length reads from the stream — the second call consumed actual array content as a length byte, corrupting the decode. Replace the _decode_length call with a simple subtype == 31 check, which is sufficient to detect indefinite-length arrays without consuming any bytes from the stream. This bug only affected cbor2pure, not the cbor2 C extension.
cffls
force-pushed
the
fix_decode_array
branch
from
February 28, 2026 03:10
6f70a6d to
d342861
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #479 +/- ##
==========================================
- Coverage 90.61% 90.60% -0.01%
==========================================
Files 34 34
Lines 5155 5154 -1
Branches 781 781
==========================================
- Hits 4671 4670 -1
Misses 305 305
Partials 179 179 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cffls
pushed a commit
that referenced
this pull request
Jun 14, 2026
#493) Adds test_sign_dex_transaction_with_raw_plutus_data_inline_datum using the Liqwid DEX fixture (Conway era, two outputs with complex inline Plutus datums). Asserts full CBOR round-trip, stable tx.id, and that a signature over the body hash verifies correctly — the exact sequence that broke before fixes #474 and #479. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
The custom decode_array override in serialization.py called _decode_length to check for indefinite-length arrays, then delegated to the original decode_array which called _decode_length again. For arrays with fewer than 24 items, the length is encoded directly in the subtype (no stream bytes consumed), so the double call was harmless. For 24+ items, CBOR uses multi-byte length encoding (e.g. 98 18 for 24 items) and _decode_length reads from the stream — the second call consumed actual array content as a length byte, corrupting the decode.
Replace the _decode_length call with a simple subtype == 31 check, which is sufficient to detect indefinite-length arrays without consuming any bytes from the stream.
This bug only affected cbor2pure, not the cbor2 C extension.