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

Access to reader.readIntoRequests without checking reader type #686

Closed
rombel opened this issue Feb 23, 2017 · 6 comments · Fixed by #698
Closed

Access to reader.readIntoRequests without checking reader type #686

rombel opened this issue Feb 23, 2017 · 6 comments · Fixed by #698
Assignees

Comments

@rombel
Copy link

rombel commented Feb 23, 2017

In ReadableByteStreamControllerRespondInClosedState [1], ReadableStreamGetNumReadIntoRequests is called and checks reader.readIntoRequests, but it is not checked that the reader is a BYOBReader.

This could be checked based on firstDescriptor.readerType, but the purpose of the loop (step 4) may be the processing of all pendingPullIntos objects, in which case I'm not sure the test that involves the number of readIntoRequests is the right one (I may not get all the context here).

[1] https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-in-closed-state

@domenic
Copy link
Member

domenic commented Feb 24, 2017

@tyoshino would you be able to take a look at this?

@domenic
Copy link
Member

domenic commented Mar 8, 2017

Hi @rombel, I'm sorry for the delay. Could you produce a bit of test code that you think might trigger this code path, i.e. a situation where ReadableByteStreamControllerRespondInClosedState is called, but the reader is a non-BYOB reader?

@rombel
Copy link
Author

rombel commented Mar 9, 2017

Hi @domenic, no problem for the delay. If I understand the spec correctly, below sample leads to calling ReadableByteStreamControllerRespondInClosedState with a default reader.

// First create a ReadableStream with a ReadableByteStreamController
// and a specific value for autoAllocateChunkSize.
let controller;
const rs = new ReadableStream({
	autoAllocateChunkSize: 128,
	start: function(c) {
		controller = c;
	},
	type: "bytes"
});

// As autoAllocateChunkSize is defined, calling read() leads to adding
// an item to controller.pendingPullIntos through controller pull() method.
rs.getReader().read();
// Hence, byobRequest can be obtained (step 2 of "get byobRequest").
const br = controller.byobRequest;
controller.close();
// Stream has been closed prior to calling respond() and bytesWritten value
// is 0: therefore, ReadableByteStreamControllerRespondInClosedState is called.
br.respond(0);

@domenic
Copy link
Member

domenic commented Mar 16, 2017

Thanks, I've confirmed this is indeed broken and am working on a fix!

domenic added a commit that referenced this issue Mar 16, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
domenic added a commit that referenced this issue Mar 16, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
domenic added a commit that referenced this issue Mar 16, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
@rombel
Copy link
Author

rombel commented Mar 17, 2017

Thanks!

@domenic domenic self-assigned this Mar 28, 2017
domenic added a commit to web-platform-tests/wpt that referenced this issue Apr 6, 2017
domenic added a commit that referenced this issue Apr 6, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
tyoshino pushed a commit to web-platform-tests/wpt that referenced this issue Apr 20, 2017
@tyoshino tyoshino changed the title Access to reader.readIntoRequests withtout checking reader type Access to reader.readIntoRequests without checking reader type Apr 20, 2017
@tyoshino
Copy link
Member

Thanks rombel. Right. The purpose of the loop is to process all the entries.

As I said at #698 (comment), we need to review all the logic to make sure this functionality is correctly handled everywhere.

domenic added a commit that referenced this issue Apr 21, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
domenic added a commit that referenced this issue Apr 21, 2017
In particular, when autoAllocateChunkSize is in play, there may be a default reader instead. Fixes #686.
hubot pushed a commit to WebKit/WebKit-http that referenced this issue May 23, 2017
https://bugs.webkit.org/show_bug.cgi?id=172288

Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-05-23
Reviewed by Chris Dumez.

Two changes are implemented in this patch:
- Change #1: An issue was reported to GH [1] while working on respondInClosedState
implementation. This issue has now been fixed, and this patch aligns implementation
with spec [2].
- Change #2: In addition, this patch also fixes a bug that went unnoticed as code
is not yet reachable (usage of controller.@reader is not valid and is therefore
replaced by controller.@controlledReadableStream.@reader).

[1] whatwg/streams#686
[2] https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-in-closed-state

No added test as:
- Change #1 does not change behavior;
- Change #2 is not testable as the code is not yet reachable.

* Modules/streams/ReadableByteStreamInternals.js:
(readableByteStreamControllerRespondInClosedState): Aligned with spec.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@217279 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ryanhaddad pushed a commit to WebKit/WebKit that referenced this issue Dec 22, 2020
https://bugs.webkit.org/show_bug.cgi?id=172288

Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-05-23
Reviewed by Chris Dumez.

Two changes are implemented in this patch:
- Change #1: An issue was reported to GH [1] while working on respondInClosedState
implementation. This issue has now been fixed, and this patch aligns implementation
with spec [2].
- Change #2: In addition, this patch also fixes a bug that went unnoticed as code
is not yet reachable (usage of controller.@reader is not valid and is therefore
replaced by controller.@controlledReadableStream.@reader).

[1] whatwg/streams#686
[2] https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond-in-closed-state

No added test as:
- Change #1 does not change behavior;
- Change #2 is not testable as the code is not yet reachable.

* Modules/streams/ReadableByteStreamInternals.js:
(readableByteStreamControllerRespondInClosedState): Aligned with spec.

Canonical link: https://commits.webkit.org/189402@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217279 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants