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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ext/standard/tests/file/stream_copy_to_stream_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
stream_copy_to_stream() from empty file
--FILE--
<?php

$tmp_empty_file = __FILE__ . ".tmp";
file_put_contents($tmp_empty_file, "");

$in = fopen($tmp_empty_file, 'r');
$out = fopen('php://memory', 'w');
var_dump(stream_copy_to_stream($in, $out));

?>
--CLEAN--
<?php
unlink(__FILE__ . ".tmp");
?>
--EXPECT--
int(0)
23 changes: 2 additions & 21 deletions main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
size_t haveread = 0;
size_t towrite;
size_t dummy;
php_stream_statbuf ssbuf;

if (!len) {
len = &dummy;
Expand All @@ -1554,17 +1553,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
maxlen = 0;
}

if (php_stream_stat(src, &ssbuf) == 0) {
if (ssbuf.sb.st_size == 0
#ifdef S_ISREG
&& S_ISREG(ssbuf.sb.st_mode)
#endif
) {
*len = 0;
return SUCCESS;
}
}

if (php_stream_mmap_possible(src)) {
char *p;

Expand Down Expand Up @@ -1641,20 +1629,13 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
writeptr += didwrite;
}

if (maxlen - haveread == 0) {
if (maxlen && maxlen == haveread) {
break;
}
}

*len = haveread;

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

if (haveread > 0 || src->eof) {
return SUCCESS;
}
return FAILURE;
return SUCCESS;
}

/* Returns the number of bytes moved.
Expand Down