Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug #54946 (stream_get_contents infinite loop)

  • Loading branch information...
commit 3b030ec75f51ef16347f548853471f7baf48bb5c 1 parent 07bcf10
@bjori bjori authored
View
1  NEWS
@@ -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)
View
40 ext/standard/tests/streams/bug54946.phpt
@@ -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===
+
View
3  main/streams/streams.c
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.