Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 4f8832f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Problem
SigmaByteReadersilently invented data when a parse ran past the end of the input:readByte()returnedundefined(typed asnumber) at EOF, soreadBool()quietly becamefalseand the type serializer'sbyte.toString(16)crashed with an unrelatedTypeError.readBytes(n)clamped to whatever remained and advanced the cursor past the end, so fixed-length fields (box/transaction ids, group elements, AVL digests, ErgoTree bodies) parsed as short values instead of failing.readBits(n)read missing bytes as0, inventingfalsebits for truncatedSColl[Boolean]constants.readUInt/readBigUInton[0x80]returned0. The same applied to any length-prefixed field —readI256with a declared length of 5 and only 2 bytes remaining returned a wrongbigintinstead of an error.The reference implementation this mirrors (scorex-util
VLQByteBufferReader) fails closed here:getByte()isByteBuffer.get(throws on underflow) andgetBytes(size)requiressize <= remaining.Fix
readByte,readBytes, andreadBitsnow throw aRangeErrornaming the position and input length when the read would go out of bounds (including a negativereadByteslength, which previously moved the cursor backwards). This makes truncated VLQs and truncated length-prefixed fields fail at the point of the bad read.Deliberate non-changes:
peek()/match()keep their clamping semantics — they don't advance the cursor and the existing tests document peek returning "all bytes if length is greater than available bytes".readVLQ/readBigVLQstill return0for a reader that is empty before the read starts (their existing explicitisEmptycheck); only a VLQ truncated mid-sequence now throws, viareadByte.Tests
Five new tests in
sigmaByteReader.spec.ts, all of which fail on pristinemasterand pass with this change: byte past EOF, byte-slice past the remainder (with the exact remainder still readable), bits past EOF, continuation-truncated VLQs for bothreadUIntandreadBigUInt, and a truncated length-prefixedreadI256.Full monorepo suite: 1137/1137 tests pass (66 files), so no in-repo parse path was relying on the lenient behavior.
@Kshot9000 · Donations (ERG): 9fcM5RWnAjmP4vx5bnW6yohB6H9bLq8sJbaPLHtwZLtQPB32Pvy