php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46147 after stream seek, appending stream filter reads incorrect data
Submitted: 2008-09-22 01:23 UTC Modified: 2008-09-22 01:28 UTC
From: cellog@php.net Assigned: cellog (profile)
Status: Closed Package: Streams related
PHP Version: 5.3CVS-2008-09-22 (CVS) OS: n/a
Private report: No CVE-ID: None
 [2008-09-22 01:23 UTC] cellog@php.net
Description:
------------
appending a stream filter to a stream that has already had data read into its buffer can cause unfiltered data to be read back in.  This is because the data is written to writepos, but read from readpos, and so the buffer should be invalidated (writepos/readpos set to 0) prior to writing back the filtered data.

This bug affects all PHP versions, and will be fixed in 5.2, 5.3, and 6.0 by me, I have a working patch ready to commit momentarily

This bug was causing ext/phar/tests/zip/badalias.phpt to fail

Reproduce code:
---------------
execute within php5/ext/phar/tests/zip:

<?php
$a = fopen(dirname(__FILE__) . '/files/' . "badalias1.phar.zip", 'rb');
fseek($a, 37); // seek to zip header
$b = fread($a, 30);
fseek($a, 82); // seek to file data
stream_filter_append($a, 'zlib.inflate', STREAM_FILTER_READ);
var_dump(fread($a, 8));
?>


Expected result:
----------------
string(8) "hi/there"


Actual result:
--------------
string(8) "&#65533;&#65533;&#65533;/&#65533;H-J"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-22 01:28 UTC] cellog@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC