|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40188 stream_copy_to_stream() with filters truncates output
Submitted: 2007-01-21 22:07 UTC Modified: 2008-07-21 01:00 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned: pollita (profile)
Status: No Feedback Package: Streams related
PHP Version: 5.2.0 OS: kubuntu linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2007-01-21 22:07 UTC]
This was detected in the phar extension, but can be reproduced with regular php code.

Because _php_stream_read in main/streams/streams.c automatically truncates output from a streams filter to the maximum requested amount, this does not allow the possibility of specifying pre-filter amount of bytes to read.

"new b" is 5 bytes, but zlib deflates it to a 7-byte length.    Because writepos is > toread, it is cut to 5 bytes.

A new flag is needed to specify that we want to read a maximum bytes, not write a maximum bytes.

Although I put "int(7)" in the expected output, I don't expect this output unless a flag is passed that specifically asks to do this.

Reproduce code:
file_put_contents('test1.txt', 'new b/next thing');
$a = fopen('test1.txt', 'rb');
$newa = fopen('test2.txt', 'wb');
stream_filter_append($a, 'zlib.deflate');
$b = stream_copy_to_stream($a, $newa, 5);
var_dump($b, ftell($newa));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-22 07:17 UTC]
Sara, could you look into this?
 [2008-07-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 05:01:33 2024 UTC