Skip to content

Fix #80384: limit read buffer size #6444

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

Closed
wants to merge 2 commits into from
Closed

Conversation

adamjseitz
Copy link
Contributor

In the case of a stream with no filters, php_stream_fill_read_buffer
only reads stream->chunk_size into the read buffer. If the stream has
filters attached, it could unnecessarily buffer a large amount of data.

With this change, php_stream_fill_read_buffer only proceeds until either
the requested size or stream->chunk_size is available in the read buffer.

Bug report at https://bugs.php.net/bug.php?id=80384

@cmb69
Copy link
Member

cmb69 commented Nov 23, 2020

This looks reasonable to me, but I'm very reluctant to target PHP-7.3 since 7.3.26 is going to be the last bug fix release, and if that would break something, we couldn't (easily) revert.

Also, consider to add a test (using the string.rot13 filter, or so), which checks that the memory usage is not totally off.

@adamjseitz
Copy link
Contributor Author

Alright, I'll get a test added and update the PR against 7.4 when I get a chance.

@adamjseitz adamjseitz changed the base branch from PHP-7.3 to PHP-7.4 December 2, 2020 00:09
@adamjseitz adamjseitz marked this pull request as draft December 2, 2020 01:47
@nikic
Copy link
Member

nikic commented Dec 7, 2020

Is this marked as a draft intentionally?

@adamjseitz
Copy link
Contributor Author

Is this marked as a draft intentionally?

Yes, there seem to be tests failing on AppVeyor, so I need to figure that out, still.

@cmb69
Copy link
Member

cmb69 commented Dec 15, 2020

The former AppVeyor build ran against PHP-7.3; I just retriggered that CI.

@cmb69
Copy link
Member

cmb69 commented Dec 15, 2020

There is only a single test failure on AppVeyor now. I'll try to have a closer look unless someone beats me to it.

In the case of a stream with no filters, php_stream_fill_read_buffer
only reads stream->chunk_size into the read buffer. If the stream has
filters attached, it could unnecessarily buffer a large amount of data.

With this change, php_stream_fill_read_buffer only proceeds until either
the requested size or stream->chunk_size is available in the read buffer.
@cmb69
Copy link
Member

cmb69 commented Dec 16, 2020

That other test failure is actually to be expected; the test expectations need to be adjusted. It failed only on AppVeyor, because there the diff is applied to the base branch, but on the other CIs the PR is tested as is. I've rebased onto PHP-7.4.

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! The fix looks good to me, but the test could be improved.

@adamjseitz adamjseitz marked this pull request as ready for review December 19, 2020 15:05
@adamjseitz
Copy link
Contributor Author

Thank you for the PR! The fix looks good to me, but the test could be improved.

Thanks for the review, and good feedback. Updated with those fixed.

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you! I'm going to merge, fixing the other test's expectations right away.

@php-pulls php-pulls closed this in 70dfbe0 Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants