]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #46426 (3rd parameter offset of stream_get_contents not works for...
authorFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 10:11:52 +0000 (10:11 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 10:11:52 +0000 (10:11 +0000)
NEWS
ext/standard/streamsfuncs.c
ext/standard/tests/streams/bug46426.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 512bebf315c0ec6be78d38ffd496adb8948e262b..1d2d770527f3c018ed97d92b8d087b87d93b6620 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP                                                                        NEWS
 - Fixed ability to use "internal" heaps in extensions. (Arnaud, Dmitry)
 - Updated timezone database to version 2008.9. (Derick)
 
+- Fixed bug #46426 (3rd parameter offset of stream_get_contents not works for 
+  "0"). (Felipe)
 - Fixed bug #46406 (Unregistering nodeclass throws E_FATAL). (Rob)
 - Fixed bug #46389 (NetWare needs small patch for _timezone).
   (patch by guenter@php.net)
index 73a993b4d27f5255fcd1f75b451681a3588dcd58..4a7644d3c37c8711bf1ea99bed2f1b05075c5961 100644 (file)
@@ -406,7 +406,7 @@ PHP_FUNCTION(stream_get_contents)
 
        php_stream_from_zval(stream, &zsrc);
 
-       if (pos > 0 && php_stream_seek(stream, pos, SEEK_SET) < 0) {
+       if (pos >= 0 && php_stream_seek(stream, pos, SEEK_SET) < 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
                RETURN_FALSE;
        }
diff --git a/ext/standard/tests/streams/bug46426.phpt b/ext/standard/tests/streams/bug46426.phpt
new file mode 100644 (file)
index 0000000..05bc9c1
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #46426 (3rd parameter offset of stream_get_contents not works for "0")
+--FILE--
+<?php
+
+$tmp = tmpfile();
+
+fwrite($tmp, "12345");
+
+echo stream_get_contents($tmp, -1, 0);
+echo "\n";
+echo stream_get_contents($tmp, -1, 1);
+echo "\n";
+echo stream_get_contents($tmp, -1, 2);
+
+@unlink($tmp);
+
+?>
+--EXPECT--
+12345
+2345
+345