Repository navigation
Conversation
…ersectMBO#575) A captured indefinite chunk layout was replayed over a changed byte or text string regardless of the new value's length: a shorter value was zero-padded to the old chunk total, a longer value lost its tail, and a text change could split a UTF-8 character — valid CBOR carrying different content, with no error. The layout is now reused only when it still fits: for bytes the chunk sizes must add up to the value's length; for text the same, and every chunk must end on a UTF-8 character boundary. Otherwise the encoder falls back to the default encoding for that string, as integer widths already do. Unchanged values and same-length aligned changes keep their captured layout byte for byte. Tests: 9 new checks in CBOR-with-format.test.ts (shorter/longer bytes and text, UTF-8 split at equal length, byte-identical controls). Full suite: 1687 passed / 75 skipped / 0 failed.
This branch has not been deployed
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.
Fixes #575
Problem
When a byte or text string was decoded as indefinite-length chunks, the captured format kept the chunk sizes. If the value then changed and was encoded with that format, the encoder wrote the old chunk sizes over the new value — valid CBOR carrying different content, with no error:
Text strings behaved the same way:
"x"under the format of"hij"decoded as"x\0\0", and a change could split a UTF-8 character. This is the metadata-hash mismatch from the issue: the SDK hashed the intended value but wrote different bytes.Fix
In
CBOR.ts, a captured indefinite chunk layout is now reused only when it still fits the value, per the issue's prescribed fix:Otherwise the encoder falls back to the default encoding for that string, as integer widths already do under the preservation spec. The definite branch is unchanged —
encodeIntHeaderalready falls back when a preserved width no longer fits. An unchanged value, and a same-length change whose chunks still align, keep their captured layout byte for byte.Tests
Red first, one filter at a time — the shorter-bytes test failed with
expected Uint8Array[170, 0, 0] to deeply equal Uint8Array[170], the longer-bytes test with the tail dropped, and the shorter-text test with'x\0\0'.9 new tests in
CBOR-with-format.test.ts:"héllo"under a mismatched format decodes back to itself; a same-length"xé"whose 2-byte first chunk would split the 2-byteéfalls back; an unchanged string stays byte-identicalFile: 33/33 pass. Full suite: 1687 passed / 75 skipped / 0 failed, test files 101 passed / 1 skipped of 102 (main baseline 1678 + 9 new).
tsc --noEmitand eslint clean. Prettier:CBOR.tsfails the check on unmodified main too, and my version's prettier diff-line count exactly equals main's (304 = 304), so the change adds no new formatting drift; the test file is prettier-clean.Independent builder — not affiliated with the Cardano Foundation, IOG or Intersect.
@Kshot9000 (https://x.com/kshot9000) · ADA: addr1q8hnl6vl5a6k3rw3n5g3jtte696zcl76kfatzv7gpswa9r0dj7fma6klq55y4ffm7tf0em09udnyhuk4ah92pl5x9jpqjae44v
cc @cardano-foundation @IntersectMBO