Skip to content

fix(ext/node): read byob views at offset 0 in FileHandle.readableWebStream - #19

Merged
jackspirou merged 1 commit into
nimbus/v2.9.6from
fix/node-filehandle-byob-offset
Sep 24, 2026
Merged

jackspirou merged 1 commit into
nimbus/v2.9.6from
fix/node-filehandle-byob-offset

Conversation

@jackspirou

Copy link
Copy Markdown
Contributor

Summary

FileHandle.readableWebStream() with a byob reader failed when the reader read into a view with a byteOffset greater than 0. The first read worked. The next read threw RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range. It must be <= 0. Received 100.

Root cause. The pull callback in ext/node/polyfills/internal/fs/handle.ts passed the view's byteOffset as the offset argument of FileHandle.read. That argument is relative to the view, not to the view's ArrayBuffer. So fs.read checked byteOffset + length against view.byteLength, and the check failed.

Fix. Pass 0, as Node does since nodejs/node#58842 (commit 2c0ccc0067d, first in v26.10.0). The TypedArrayPrototypeGetByteOffset primordial has no other user in the file, so this change removes its import.

Node v24 and Node before v26.10.0 have the same defect. The fork now reads correctly on every Node lane. No test depends on the old error.

Tests

  • New unit test [node/fs filehandle.readableWebStream] byob reads into views at a byteOffset of one ArrayBuffer. It reads with a byob reader into 100-byte DataViews at increasing offsets of one ArrayBuffer, the same as the new block in Node's test-filehandle-readablestream.js.
    • Before the fix: fails with the RangeError above.
    • After the fix: passes.
  • tests/unit_node/_fs/: 295 passed, 0 failed, 9 ignored.
  • The Node v26.10.0 test/parallel/test-filehandle-readablestream.js, run through the node shim: passes. The build before the fix fails with the same RangeError.
  • dprint check on the changed files and tools/lint.js --js: pass.

Follow-up (not in this PR)

  • The fork node_compat suite is at 26.5.1, so its copy of test-filehandle-readablestream.js does not have the new block yet. Moving the suite to v26.10.0 adds it.

…tream

The byob pull passed the view's byteOffset as the read offset. That
offset is relative to the view, so a view that starts after byte 0 of
its ArrayBuffer failed with ERR_OUT_OF_RANGE ("It must be <= 0"). Pass
0, as Node does since nodejs/node#58842 (v26.10.0).

Add a unit test that reads with a byob reader into 100-byte DataViews at
increasing offsets of one ArrayBuffer. It fails before this change.
@jackspirou
jackspirou merged commit d761a71 into nimbus/v2.9.6 Sep 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant