Skip to content

Remove zero size special case for copy_to_stream #6807

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 3 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Mar 25, 2021

This doesn't seem to serve any purpose. Stats are expensive, so doing an unnecessary stat just to short-circuit the zero size case seems rather dubious. It can also break with stream wrappers that return inaccurate sizes (symfony/symfony#40574) and probably can also break with stream filters. I think we should just drop it...

@nikic nikic requested a review from cmb69 March 25, 2021 13:16
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.

I think this is fine, but maybe add a test case for copying an empty file?

@nikic
Copy link
Member Author

nikic commented Mar 25, 2021

Looks like we have a test for copying from an empty stream here: https://github.com/php/php-src/blob/07fa13088e1349f4b5a044faeee57f2b34f6b6e4/ext/standard/tests/streams/bug47997.phpt I didn't spot one for empty files in particular though, so I'll add one.

@nicolas-grekas
Copy link
Contributor

Should this be considered as a bugfix, thus for 7.4?

@nikic nikic force-pushed the stream-copy-size-check branch from 9ed1d94 to 5f63fd8 Compare March 25, 2021 17:44
@cmb69
Copy link
Member

cmb69 commented Mar 25, 2021

I just found that this (22517ce) was introduced as bug fix, where a comment in the bug report claims it would be an issue for platforms not supporting mmap(). However, when I tested on Windows, php_stream_mmap_range() failed, but the rest worked well, so maybe this has been resolved otherwise in the meantime.

@nicolas-grekas
Copy link
Contributor

Maybe not relevant, but the end of the function says:

	/* we've got at least 1 byte to read.
	 * less than 1 is an error */

@nikic
Copy link
Member Author

nikic commented Mar 25, 2021

@nicolas-grekas Good point. This code doesn't actually get reached when the size is zero, but the comment is certainly confusing, and the special handling there is unnecessary. I've simplified that code a bit and dropped the comment.

@nikic nikic closed this in b95b553 Mar 29, 2021
kamil-tekiela pushed a commit to kamil-tekiela/php-src that referenced this pull request Apr 4, 2021
This doesn't seem to serve a purpose anymore. Stats are expensive,
so doing an unnecessary stat just to short-circuit the zero size
case is rather dubious. It can also break with stream wrappers
that return inaccurate sizes (symfony/symfony#40574) and probably
can also break with stream filters.

Drop the special case and adjust code to make it more obvious that
it will still be handled correctly.

Closes phpGH-6807.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants