php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73944 dictionary option of intflate_init() does not work
Submitted: 2017-01-16 10:05 UTC Modified: 2017-06-06 15:15 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: someone dot wanted dot to dot be dot unknown at gmail dot com Assigned: bwoebi (profile)
Status: Closed Package: Zlib related
PHP Version: 7.1.0 OS: Windows 10 x64
Private report: No CVE-ID: None
 [2017-01-16 10:05 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Description:
------------
I'm writing an unpacker of MSZIP blocks that use deflate compression.
I faced a problem and created a question on stackoverflow (http://stackoverflow.com/questions/41653663/is-there-something-special-in-windows-mszip-format-or-cfdata-in-cab-files), where maintainer of zlib library adviced to use `dictionary` option to pass raw uncompressed data of previous block to decompress next block of data. But Mark Adler says that this option don't work in current php realisation. 

> Looks like a bug. I can't get the dictionary option to work at all, even with strings that don't have nulls.

Test script:
---------------
$in = inflate_init(ZLIB_ENCODING_RAW);
$a = inflate_add($in, file_get_contents('https://github.com/wapmorgan/CabArchive/releases/download/0.0.1-dev/1block'));
echo '1 block: '.strlen($a).PHP_EOL;

$in = inflate_init(ZLIB_ENCODING_RAW, array('dictionary' => str_replace("\00", null, $a)."\00"));
$b = inflate_add($in, file_get_contents('https://github.com/wapmorgan/CabArchive/releases/download/0.0.1-dev/2block'));
echo '2 block: '.($b === false ? 'failed' : strlen($b)).PHP_EOL;

Expected result:
----------------
1 block: 32768
2 block: 32768

Actual result:
--------------
1 block: 32768
2 block: failed

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-16 10:10 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
-Summary: dictionary option does not work +Summary: dictionary option of intflate_init() does not work
 [2017-01-16 10:11 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
change title
 [2017-01-16 11:39 UTC] cmb@php.net
-Assigned To: +Assigned To: bwoebi
 [2017-01-16 11:39 UTC] cmb@php.net
Bob, as you've added the dictionary option[1], could you please
have a look at this.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=dd17e18f>
 [2017-01-23 23:46 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Any update on this?
 [2017-01-25 15:24 UTC] bwoebi@php.net
I'm not sure whether I'm doing it right…
I've commented these lines out:
https://github.com/php/php-src/blob/b38e6a54cf4500780fd8ba68ae66714a0f21dd86/ext/zlib/zlib.c#L767-L780

and called the code with:
$in = inflate_init(ZLIB_ENCODING_RAW, array('dictionary' => $a));

but I still get a data error upon subsequent inflate_add() … so not sure whether the repro is broken or something else in the code.
 [2017-01-27 20:55 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Thanks for attention. Can you test other data set?

$in = inflate_init(ZLIB_ENCODING_RAW);
$a = inflate_add($in, file_get_contents('https://github.com/wapmorgan/CabArchive/releases/download/0.0.1-dev/comp_0-0'));
echo '1 block: '.strlen($a).PHP_EOL;

$in = inflate_init(ZLIB_ENCODING_RAW, array('dictionary' => $a));
$b = inflate_add($in, file_get_contents('https://github.com/wapmorgan/CabArchive/releases/download/0.0.1-dev/comp_0-1'));
echo '2 block: '.($b === false ? 'failed' : strlen($b)).PHP_EOL;
 [2017-02-01 10:42 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Any updates on this?
 [2017-02-01 15:29 UTC] bwoebi@php.net
No idea, still doesn't work. I'd be happy if someone else could look at the relevant code in ext/zlib/zlib.c:764 and following lines...
 [2017-02-01 15:30 UTC] bwoebi@php.net
No idea, still doesn't work. I'd be happy if someone else could look at the relevant code in ext/zlib/zlib.c:764 and following lines...
 [2017-02-06 16:14 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Mark thinks following:
> The current PHP code appears to be calling inflateSetDictionary() only if Z_DICT is returned by deflate. The PHP code should also call inflateSetDictionary() after calling inflateInit2() if raw inflate is being requested. 
http://stackoverflow.com/questions/41653663/is-there-something-special-in-windows-mszip-format-or-cfdata-in-cab-files#comment71289866_41658204
 [2017-02-13 14:48 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Can you try suggestion that Mark made and update zlib module?
 [2017-02-20 11:45 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
What about thinking about this problem?
 [2017-03-31 17:26 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
So, if I could send PR to php source, I'd send a fix.
According to Mark's opinion, it's not very difficult to update source of zlib extension to fix decompressor. May I wait for updates on this issue?
 [2017-06-03 19:37 UTC] someone dot wanted dot to dot be dot unknown at gmail dot net
Nobody interesting in fixing this bug at all?
 [2017-06-06 15:15 UTC] cmb@php.net
> So, if I could send PR to php source, I'd send a fix.

That would be great! You can make a PR against
<https://github.com/php/php-src>.
 [2017-06-17 01:08 UTC] someone dot wanted dot to dot be dot unknown at gmail dot com
Send a PR. Take a look https://github.com/php/php-src/pull/2580
 [2017-06-25 08:58 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fda0a8b735e468f03b32bc099d8f4aa173d2b9f7
Log: Fixed bug #73944 (inflate_init() dictionary option) - add NEWS entry
 [2017-06-25 08:58 UTC] bwoebi@php.net
-Status: Assigned +Status: Closed
 [2017-06-25 13:33 UTC] nikic@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fda0a8b735e468f03b32bc099d8f4aa173d2b9f7
Log: Fixed bug #73944 (inflate_init() dictionary option) - add NEWS entry
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC