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

From: Date: Sun, 13 Jul 2008 16:07:23 +0000
Subject: #40188 [Asn->Fbk]: stream_copy_to_stream() with filters truncates output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126619@lists.php.net to get a copy of this message
 ID:               40188
 Updated by:       jani@php.net
 Reported By:      cellog@php.net
-Status:           Assigned
+Status:           Feedback
 Bug Type:         Streams related
 Operating System: kubuntu linux
 PHP Version:      5.2.0
 Assigned To:      pollita
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi




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

[2007-01-22 07:17:10] tony2001@php.net

Sara, could you look into this?

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

[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 (#126619) next »