Skip to content
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

stream: improve view validation on ReadableStreamBYOBRequest.respondWithNewView() #44155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,15 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);

if (stream[kState].state === 'closed') {
if (viewByteLength !== 0)
throw new ERR_INVALID_STATE.TypeError('View is not zero-length');
} else {
assert(stream[kState].state === 'readable');
if (viewByteLength === 0)
throw new ERR_INVALID_STATE.TypeError('View is zero-length');
}

const {
byteOffset,
byteLength,
Expand Down
8 changes: 0 additions & 8 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@
},
"transferable/deserialize-error.window.js": {
"skip": "Browser-specific test"
},
"readable-byte-streams/bad-buffers-and-views.any.js": {
"fail": {
"note": "TODO: implement detached ArrayBuffer support",
"expected": [
"ReadableStream with byte source: respondWithNewView() throws if the supplied view's buffer is zero-length (in the readable state)"
]
}
}
}