1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 18:23:26 +02:00

Fixed bug #54946 (stream_get_contents infinite loop)

This commit is contained in:
Hannes Magnusson
2011-05-29 12:29:19 +00:00
parent 07bcf1080d
commit 3b030ec75f
3 changed files with 44 additions and 0 deletions
+1
View File
@@ -151,6 +151,7 @@ PHP NEWS
(Felipe)
- Streams:
. Fixed bug #54946 (stream_get_contents infinite loop). (Hannes)
. Fixed bug #54623 (Segfault when when writing to a persistent socket after
closing a copy of the socket). (Gustavo)
+40
View File
@@ -0,0 +1,40 @@
--TEST--
Bug#54946 stream_get_contents infinite loop
--FILE--
<?php
$filename = tempnam(sys_get_temp_dir(), "phpbug");
$stream = fopen($filename, "w"); // w or a
$retval = stream_get_contents($stream, 1, 1);
var_dump($retval);
unlink($filename);
$filename = tempnam(sys_get_temp_dir(), "phpbug2");
$stream = fopen($filename, "a");
$retval = stream_get_contents($stream, 1, 1);
var_dump($retval);
unlink($filename);
$filename = tempnam(sys_get_temp_dir(), "phpbug3");
$stream = fopen($filename, "a");
fseek($stream, 1);
$retval = stream_get_contents($stream, 1);
var_dump($retval);
unlink($filename);
?>
===DONE===
--EXPECT--
string(0) ""
string(0) ""
string(0) ""
===DONE===
+3
View File
@@ -1291,6 +1291,9 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
while ((len < maxlen) && !php_stream_eof(src)) {
ret = php_stream_read(src, ptr, maxlen - len);
if (!ret) {
break;
}
len += ret;
ptr += ret;
}