php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22538 stream_copy_to_stream() with stream filters produces bogus output
Submitted: 2003-03-04 12:49 UTC Modified: 2003-05-30 10:12 UTC
From: moriyoshi@php.net Assigned: iliaa (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5CVS-2003-03-04 (dev) OS: RedHat Linux 8.0 (glibc-2.3.0)
Private report: No CVE-ID: None
 [2003-03-04 12:49 UTC] moriyoshi@php.net
$ cat Zend/zend.c | php script2.php

produces bogus output, whilst 

$ php script1.php

and

$ php script3.php

work correctly.



script1.php:

<?php
$fin = fopen("Zend/zend.c", "r");
$fout = fopen("/tmp/output", "w");
stream_filter_append($fout, "string.rot13");
stream_copy_to_stream($fin, $fout);
fclose($fin);
fclose($fout);
?>

script2.php:

<?php
$fin = fopen("php://stdin", "r");
$fout = fopen("/tmp/output", "w");
stream_filter_append($fout, "string.rot13");
stream_copy_to_stream($fin, $fout);
fclose($fin);
fclose($fout);
?>

script3.php:

<?php
$fin = fopen("php://stdin", "r");
$fout = fopen("/tmp/output", "w");
stream_filter_append($fin, "string.rot13");
stream_copy_to_stream($fin, $fout);
fclose($fin);
fclose($fout);
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-04 12:56 UTC] moriyoshi@php.net
Correcting a typo.

wrong: $ php script3.php
right: $ cat Zend/zend.c | php script3.php
 [2003-03-17 08:26 UTC] moriyoshi@php.net
Is this a sort of mmap() problem? I have no idea about this problem at all..

 [2003-03-17 12:33 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-03-17 14:30 UTC] moriyoshi@php.net
The bug still persists.

$ php script2.php < Zend/zend.c

is ok, but it doesn't work with piped stream. Please try the following:

$ cat script2.php | php script2.php

 [2003-03-17 14:34 UTC] moriyoshi@php.net
Oops, I forgot to try this one...

script 4:

<?php
$fin = popen("cat Zend/zend.c", "r");
$fout = fopen("/tmp/output", "w");
stream_filter_append($fout, "string.rot13");
stream_copy_to_stream($fin, $fout);
fclose($fin);
fclose($fout);
?>

This results in the same output.

 [2003-03-17 14:58 UTC] moriyoshi@php.net
And, hmm, here's another script to replicate with.
By this script, It turned out that the issue isn't stream_copy_to_stream specific.

<?php
function my_stream_copy_to_stream($fin, $fout) {
    while (!feof($fin)) {
        fwrite($fout, fread($fin, 4096));
    }
}
$fin = fopen("Zend/zend.c", "r");
$fout = fopen("/tmp/output", "w");
stream_filter_append($fout, "string.rot13");
my_stream_copy_to_stream($fin, $fout);
fclose($fin);
fclose($fout);
?>

I don't have enough time to fix this right now, so I thank you for taking your time to look at this one ;-)

 [2003-03-28 10:59 UTC] moriyoshi@php.net
I made a patch for this issue. But not sure if this is the right fix..

Index: main/streams/streams.c
===================================================================
RCS file: /repository/php4/main/streams/streams.c,v
retrieving revision 1.14
diff -u -r1.14 streams.c
--- main/streams/streams.c	20 Mar 2003 01:23:04 -0000	1.14
+++ main/streams/streams.c	28 Mar 2003 16:50:31 -0000
@@ -829,7 +829,7 @@
 			
 			/* Only screw with the buffer if we can seek, otherwise we lose data
 			 * buffered from fifos and sockets */
-			if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && !php_stream_is_filtered(stream)) {
+			if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
 				stream->position += justwrote;
 			}
 		} else {


 [2003-03-31 17:23 UTC] moriyoshi@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC