#40188 [Opn->Asn]: stream_copy_to_stream() with filters truncates output

From: Date: Mon, 22 Jan 2007 07:17:10 +0000
Subject: #40188 [Opn->Asn]: stream_copy_to_stream() with filters truncates output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107855@lists.php.net to get a copy of this message
 ID:               40188
 Updated by:       tony2001@php.net
 Reported By:      cellog@php.net
-Status:           Open
+Status:           Assigned
 Bug Type:         Streams related
 Operating System: kubuntu linux
 PHP Version:      5.2.0
-Assigned To:      
+Assigned To:      pollita
 New Comment:

Sara, could you look into this?


Previous Comments:
------------------------------------------------------------------------

[2007-01-21 22:07:56] cellog@php.net

Description:
------------
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:
---------------
<?php
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:
----------------
int(5)
int(7)

Actual result:
--------------
int(5)
int(5)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40188&edit=1


Thread (3 messages)

« previous php.bugs (#107855) next »