{{ message }}
Repository navigation
[TS] enforce read bounds in ByteBuffer - #9280
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
Offsets come from the buffer itself when reading untrusted data. The scalar reads indexed the underlying typed array directly, so an out-of-range offset read 'undefined' and NaN-propagated through later arithmetic, and a negative offset wrapped around the typed array silently. __string and __vector could also return silently clamped or out-of-range slices. Adds a checkRead_ guard to the scalar reads and validates the computed targets in __string and __vector, throwing RangeError with a clear message instead. Mirrors the read-bounds enforcement the Swift port adopted (google#9277).
4 tasks done
Author
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.

Problem
The TypeScript
ByteBufferread accessors index the underlying typed array without any bounds validation, and every offset comes from the buffer itself when reading untrusted data (network, files):undefined, which NaN-propagates through later offset arithmetic instead of failing,bytes[-1]→undefined, and computed indices can land anywhere) with no error,__stringwith a length running past the end silently returns a truncated string (subarrayclamps), and a length of0xffffffffbehaves the same way,__vectorreturns a start position beyond the buffer without complaint; element reads then produceundefined.Change
checkRead_(offset, size)guard wired intoreadUint8/readUint16/readInt32(the remaining reads and__offset/__indirect/__vector_len/__unionall flow through these),__stringvalidates the finaloffset + lengthrange and rejects huge unsigned lengths,__vectorvalidates the computed start (an empty vector may start exactly at the end).Out-of-bounds reads now throw
RangeErrorwith a clear message. This mirrors the read-bounds enforcement direction the Swift port has adopted (#9277), applied to the TS port.Test plan
tests/ts/JavaScriptByteBufferBoundsTest.js(registered inTypeScriptTest.py): OOB/negative scalar reads, oversized and negative-length strings, vector start past the end, plus in-bounds and valid-data sanity cases — all passmaster, the same test fails (AssertionError: Missing expected exception) — confirming the previously silent readsJavaScriptTest,JavaScriptFlexBuffersTest,JavaScriptUnionVectorTest,JavaScriptComplexArraysTest,JavaScriptUnionUnderlyingTypeTest,JavaScriptUndefinedForOptionalsall pass after the change (no false positives on valid buffers)tsccompile clean