Repository navigation
fix: parse typed-array and Node Buffer views by their exact byte range - #547
Merged
awatson1978 merged 1 commit intoSep 30, 2026
Merged
Conversation
ReadBufferStream adopted a view's whole backing ArrayBuffer and dropped the byteOffset, so a pooled Uint8Array view either failed the DICM header check against pool junk or silently parsed a neighbouring file's bytes. The Node-only Buffer.offset property also seeded the read offset, which only cancelled out while the whole pool was adopted. The constructor now adopts exactly the viewed byte range, normalized to logical offset 0, and seeds the offset from the source only when it is a BufferStream sub-stream. Closes review finding 1 of the PR #512 review map, and flips the KNOWN GAP #311 pooled-view equivalence test to green. Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
force-pushed
the
core/finding-1-buffer-byteoffset
branch
from
September 30, 2026 11:39
786e011 to
faea45b
Compare
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This was referenced Oct 30, 2026
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.
This closes review finding 1 from the PR #512 review map:
ReadBufferStreammishandled typed-array and Node Buffer views into a shared backing buffer.Some background on why this bites in practice. In Node, a
Bufferis almost never a wholeArrayBuffer— it's a view into a shared allocation pool.fs.readFileSyncon any file below 4096 bytes,Buffer.from(str, "base64"),Buffer.concat(...)results and everybuf.subarray(...)all hand you bytes that start at a nonzerobyteOffsetinside a bigger backing buffer. Browsers hit the same shape whenever aUint8Arrayview is carved out of a larger transfer buffer.ReadBufferStreamgot this wrong in two cooperating ways.SplitDataView.addBufferunwrappedbuffer.bufferand adopted the whole pool, droppingbyteOffset; and the constructor seeded its read offset frombuffer.offset— a property only Node Buffers have (it equalsbyteOffset), so plainUint8Arrayviews and Buffers behaved differently on the same bytes. For a plain view the parse window was pool bytes[0, view.byteLength): junk before the view madereadFilethrow "Invalid DICOM file, expected header is missing" even though the view's own bytes are a perfectly valid file — and when another valid file happened to precede the view in the pool (two files read into one pool — routine in Node),readFilesilently returned the wrong file's dataset. No error, same element count, wrong data.The fix is in the
ReadBufferStreamconstructor: anArrayBuffer.isView(buffer)input is now adopted as exactly its viewed byte range, normalized to logical offset 0, and the read offset no longer reads the Node-onlyBuffer.offsetproperty — the offset seed survives only for the documentedBufferStreamsub-stream pattern, which keepsnew ReadBufferStream(stream, le, { stop })working as before.The regression suite is
test/issues/issue311-node-buffer-footgun.test.js, which already pinned this exact footgun for issues #311/#370: itsKNOWN GAP #311pooled-view-equals-exact-slice test is now unskipped and green, the junk-prefixed-pool test flips from "fails loudly" to "parses the view's own bytes", and a new case pins the NodeBuffer.subarrayshape from the finding. The catalog entry for #311 moves fromgaptogreen. Full suite: 611 passed, 19 skipped, 630 total.On master (0.52): the same constructor line and the same pool-adopting
addBufferare both present, so the pooled plain-view aliasing half of this defect exists there too; the Buffer-specificoffsetseed only cancels out because the whole pool is adopted. The finding is master-applicable as a hotfix candidate.🤖 Generated with Claude Code