Permalink
Browse files

Fixed bug #54946 (stream_get_contents infinite loop)

  • Loading branch information...
1 parent 07bcf10 commit 3b030ec75f51ef16347f548853471f7baf48bb5c @bjori bjori committed May 29, 2011
Showing with 44 additions and 0 deletions.
  1. +1 −0 NEWS
  2. +40 −0 ext/standard/tests/streams/bug54946.phpt
  3. +3 −0 main/streams/streams.c
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)
@@ -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
@@ -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;
}

0 comments on commit 3b030ec

Please sign in to comment.