bz2.decompress/zlib.inflate filter tries to decompress after end of stream
| Bug #46026 | bz2.decompress/zlib.inflate filter tries to decompress after end of stream | ||||
|---|---|---|---|---|---|
| Submitted: | 2008-09-08 22:58 UTC | Modified: | 2009-02-03 19:03 UTC | ||
| From: | Keisial at gmail dot com | Assigned: | cellog (profile) | ||
| Status: | Closed | Package: | Bzip2 Related | ||
| PHP Version: | 5.2CVS-2008-09-08 (snap) | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
[2008-09-08 22:58 UTC] Keisial at gmail dot com
Description: ------------ If the input is larger than the bzip2 stream, bz2_decompress_filter tries to continue decompressing after it has received a BZ_STREAM_END, so bzlib returns BZ_SEQUENCE_ERROR and the stream filter finalises with PSFS_ERR_FATAL, getting no output. Reproduce code: --------------- bz2Decompress.php: <?php $f = fopen($argv[1], "rb"); stream_filter_append($f, "bzip2.decompress"); fpassthru($f); fclose($f); ?> $ echo 'Hello world' > hello.txt $ bzip2 hello.txt $ php bz2Decompress.php hello.txt.bz2 Hello world $ echo '!' >> hello.txt.bz2 $ php bz2Decompress.php hello.txt.bz2 /* No output */ Expected result: ---------------- At least the correctly read data should be returned. Two things can be done on receiving a BZ_STREAM_END: -Setting an EOF flag and remove any further incoming data (allow to continue reading if the filter is removed?). -Reinitialising the decompressing library (approach of the bzip2 utility) so concatenated bzip2 streams can be unbzipped as the concatenation of its output.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2008-09-19 16:47 UTC] Keisial at gmail dot com
[2008-10-11 17:12 UTC] cellog@php.net
[2008-10-11 18:25 UTC] cellog@php.net
In the future, please follow 2 important elements of the coding standards: 1) use tabs instead of spaces 2) always use {} around if/else blocks I had to waste 15 minutes just getting the patch formatted correctly before I could even begin testing it. I don't like wasting time.[2008-10-11 19:08 UTC] cellog@php.net
[2008-10-11 19:15 UTC] cellog@php.net
[2008-10-11 21:54 UTC] Keisial at gmail dot com
Wow, thank you very much. :-) Sorry about the tabs. My editor messed them (I know, I know, real programmers use butterflies...). However, consider doing this: if (SUCCESS == zend_hash_find(HASH_OF(filterparams), "concatenated", sizeof("concatenated"), (void **) &tmpzval) ) { - SEPARATE_ZVAL(tmpzval); - convert_to_boolean_ex(tmpzval); data->expect_concatenated = Z_LVAL_PP(tmpzval); - zval_ptr_dtor(tmpzval); tmpzval = NULL; } There were memory corruption problems with the previous patch, and zval_ptr_dtor seemed to be the source (thanks to rrichards and pajoye for their help on this on irc). Also, the other zval_ptr_dtor below (present there since first version by Sara) would be a "good possible candidate for another possible point of mem corruption".[2009-02-03 19:03 UTC] cellog@php.net