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

Ensure checking for 0 length chunk, when we should check for it #71

Merged
merged 1 commit into from
Dec 2, 2016

Conversation

WyriHaximus
Copy link
Member

Fixes #67 (for the third time 🤐 )

The problem occurs when the last bit in the buffer is 0\r\n. Because we parse the length chunk and conclude it is zero thus clearing the buffer before checking for the end we never find the end. By moving that check to before parsing the length chunk we correctly find the end

…fore attempting to extract the length. As the final one will always be zero. Also force one final iteration over the buffer when handling end
@WyriHaximus
Copy link
Member Author

Ping for review @jsor && @clue

@@ -87,6 +87,14 @@ protected function iterateBuffer()
}

if ($this->nextChunkIsLength) {
if (substr($this->buffer, 0, 3) === "0\r\n") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be cleaner to parse this like a normal chunk header in order to support chunk extensions etc. as usual. But I guess this is good as-is because it already fixes a particular bug, so let's get this in first 👍

Copy link
Member Author

@WyriHaximus WyriHaximus Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests already check for end of body extensions: https://github.com/WyriHaximus/http-client/blob/26f43a22e23cc8dc879bbee0c392bbd56b1ce023/tests/DecodeChunkedStreamTest.php#L145 But does it could be a bit better, lets try to get that into v0.4.16, I'll get this out the door in v0.4.15.

@WyriHaximus WyriHaximus self-assigned this Dec 2, 2016
@WyriHaximus WyriHaximus added the bug label Dec 2, 2016
@WyriHaximus WyriHaximus added this to the v0.4.15 milestone Dec 2, 2016
@WyriHaximus WyriHaximus merged commit 4428d56 into reactphp:master Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants