]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #48307 (stream_copy_to_stream() copies 0 bytes when $source
authorArnaud Le Blanc <lbarnaud@php.net>
Sat, 16 May 2009 20:24:01 +0000 (20:24 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Sat, 16 May 2009 20:24:01 +0000 (20:24 +0000)
is a socket)

NEWS
ext/standard/tests/streams/stream_copy_to_stream_socket.phpt [new file with mode: 0644]
main/streams/streams.c

diff --git a/NEWS b/NEWS
index 790bd9f99e1dff998be5a59fe96cb56365796e42..0542c47e5ce9ee4b2c76f92bc71ab0750d02c117 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,8 @@ PHP                                                                        NEWS
 - Fixed segfault on invalid session.save_path. (Hannes)
 - Fixed leaks in imap when a mail_criteria is used. (Pierre)
 
+- Fixed bug #48307 (stream_copy_to_stream() copies 0 bytes when $source is a 
+  socket). (Arnaud)
 - Fixed bug #48256 (Crash due to double-linking of history.o).
   (tstarling at wikimedia dot org)
 - Fixed bug #48248 (SIGSEGV when access to private property via &__get). 
diff --git a/ext/standard/tests/streams/stream_copy_to_stream_socket.phpt b/ext/standard/tests/streams/stream_copy_to_stream_socket.phpt
new file mode 100644 (file)
index 0000000..7e304b1
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+stream_copy_to_stream() with socket as $source
+--SKIPIF--
+<?php
+$sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+if (!$sockets) die("skip stream_socket_pair");
+?>
+--FILE--
+<?php
+
+$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+$tmp = tmpfile();
+
+fwrite($sockets[0], b"a");
+stream_socket_shutdown($sockets[0], STREAM_SHUT_WR);
+stream_copy_to_stream($sockets[1], $tmp);
+
+fseek($tmp, 0, SEEK_SET);
+var_dump(stream_get_contents($tmp));
+
+stream_copy_to_stream($sockets[1], $tmp);
+
+fseek($tmp, 0, SEEK_SET);
+var_dump(stream_get_contents($tmp));
+
+
+?>
+--EXPECT--
+string(1) "a"
+string(1) "a"
index 8e7fd84cff9abf435e3013db32fdf8a1f16c1bcd..a4b48370ac65f364c6f6c77111e146f784269e0d 100755 (executable)
@@ -1313,11 +1313,8 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s
 
        if (php_stream_stat(src, &ssbuf) == 0) {
                if (ssbuf.sb.st_size == 0
-#ifdef S_ISFIFO
-                && !S_ISFIFO(ssbuf.sb.st_mode)
-#endif
-#ifdef S_ISCHR
-                && !S_ISCHR(ssbuf.sb.st_mode)
+#ifdef S_ISREG
+                       && S_ISREG(ssbuf.sb.st_mode)
 #endif
                ) {
                        *len = 0;