diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 1b2521e2c16dfc..44ac87594001fd 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -2965,7 +2965,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) { if (byteOffset + bytesFilled !== viewByteOffset) throw new ERR_INVALID_ARG_VALUE.RangeError('view', view); - if (bytesFilled + viewByteOffset > byteLength) + if (bytesFilled + viewByteLength > byteLength) throw new ERR_INVALID_ARG_VALUE.RangeError('view', view); if (bufferByteLength !== viewBufferByteLength) diff --git a/test/parallel/test-whatwg-readablestream.js b/test/parallel/test-whatwg-readablestream.js index 85096286d3e613..974b7791a6d68a 100644 --- a/test/parallel/test-whatwg-readablestream.js +++ b/test/parallel/test-whatwg-readablestream.js @@ -1657,3 +1657,33 @@ class Source { reader.read(new DataView(buffer)) .then(common.mustCall()); } + +{ + const stream = new ReadableStream({ + type: 'bytes', + autoAllocateChunkSize: 128, + pull: common.mustCall((controller) => { + const view = controller.byobRequest.view; + const dest = new Uint8Array( + view.buffer, + view.byteOffset, + view.byteLength + ); + dest.fill(1); + controller.byobRequest.respondWithNewView(dest); + }), + }); + + const reader = stream.getReader({ mode: 'byob' }); + + const buffer = new ArrayBuffer(10); + const view = new Uint8Array( + buffer, + 1, + 3 + ); + + reader.read(view).then(common.mustCall(({ value }) => { + assert.deepStrictEqual(value, new Uint8Array([1, 1, 1])); + })); +}