-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web streams respondWithNewView() errors when view.byteOffset != 0 #42851
Comments
@Macil I think you're correct...I did a bit of digging on this issue.
I actually think that the correct value is Further investigation shows that the reference implementation has had some fixes applied 11 months ago: whatwg/streams@033c6d9#diff-db46b8b33e26be52c078fa1540a3516fca7f75af6effb18e9b152efbd114b4bfR1345 It doesn't seem like all of the fixes were applied back to Node. |
It also looks like the |
This also causes teed byte stream to throw when being read with non-zero-offset buffer view because of node/lib/internal/webstreams/readablestream.js Line 1731 in 167d7a9
|
Fixes: #42851 Refs: https://github.com/whatwg/streams/blob/f894acdd417926a2121710803cef593e15127964/reference-implementation/lib/abstract-ops/readable-streams.js#L1756 PR-URL: #46465 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Fixes: #42851 Refs: https://github.com/whatwg/streams/blob/f894acdd417926a2121710803cef593e15127964/reference-implementation/lib/abstract-ops/readable-streams.js#L1756 PR-URL: #46465 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Fixes: #42851 Refs: https://github.com/whatwg/streams/blob/f894acdd417926a2121710803cef593e15127964/reference-implementation/lib/abstract-ops/readable-streams.js#L1756 PR-URL: #46465 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Version
v18.0.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
If you call ReadableStreamBYOBRequest.respondWithNewView() with a Uint8Array that has a byteOffset greater than 0, then you get an error, even when the regular required conditions are met (the view's byteOffset equals the byobRequest.view's byteOffset, it refers to the same buffer, etc). This makes it impossible to use if the byobRequest.view's byteOffset is greater than 0.
How often does it reproduce? Is there a required condition?
This bug seems to be caused by line 2522 of readablestream.js:
byteLength
is the length of the view, andbytesFilled
is equal to the length of the view in this example (and any other case a read fills up the provided view), so an error would happen whenever the view's byte offset is greater than zero.I assume
byteLength
is supposed to beviewBufferByteLength
instead here, because it doesn't make sense to compare a calculation based on the view's byte offset to the view's length, but it would make sense to compare that calculation to the underlying buffer's length.What is the expected behavior?
Here is the expected output that you get when run in Deno or Chrome:
What do you see instead?
Here is the actual output that you get from Node:
Additional information
I ran into this issue when using code similar to the
readInto()
example inside the Streams standard for filling a buffer using a bring-your-own-buffer mode reader of a stream that made use ofrespondWithNewView()
.This issue can be worked around in some cases by using respond() instead of respondWithNewView(), but this can only be done when the byobRequest.view has not been transferred, which is easily possible if a ReadableStream is constructed that is wrapping another one.
The text was updated successfully, but these errors were encountered: