Skip to content

Commit 202a701

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Remove zero size special case for copy_to_stream
2 parents 8560d16 + b95b553 commit 202a701

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
stream_copy_to_stream() from empty file
3+
--FILE--
4+
<?php
5+
6+
$tmp_empty_file = __FILE__ . ".tmp";
7+
file_put_contents($tmp_empty_file, "");
8+
9+
$in = fopen($tmp_empty_file, 'r');
10+
$out = fopen('php://memory', 'w');
11+
var_dump(stream_copy_to_stream($in, $out));
12+
13+
?>
14+
--CLEAN--
15+
<?php
16+
unlink(__FILE__ . ".tmp");
17+
?>
18+
--EXPECT--
19+
int(0)

main/streams/streams.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
15391539
size_t haveread = 0;
15401540
size_t towrite;
15411541
size_t dummy;
1542-
php_stream_statbuf ssbuf;
15431542

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

1557-
if (php_stream_stat(src, &ssbuf) == 0) {
1558-
if (ssbuf.sb.st_size == 0
1559-
#ifdef S_ISREG
1560-
&& S_ISREG(ssbuf.sb.st_mode)
1561-
#endif
1562-
) {
1563-
*len = 0;
1564-
return SUCCESS;
1565-
}
1566-
}
1567-
15681556
if (php_stream_mmap_possible(src)) {
15691557
char *p;
15701558

@@ -1641,20 +1629,13 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
16411629
writeptr += didwrite;
16421630
}
16431631

1644-
if (maxlen - haveread == 0) {
1632+
if (maxlen && maxlen == haveread) {
16451633
break;
16461634
}
16471635
}
16481636

16491637
*len = haveread;
1650-
1651-
/* we've got at least 1 byte to read.
1652-
* less than 1 is an error */
1653-
1654-
if (haveread > 0 || src->eof) {
1655-
return SUCCESS;
1656-
}
1657-
return FAILURE;
1638+
return SUCCESS;
16581639
}
16591640

16601641
/* Returns the number of bytes moved.

0 commit comments

Comments
 (0)