Skip to content

ext/zlib: honor preset dictionary for raw inflate with non-default window#105

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
zlib-raw-dict-window
Closed

ext/zlib: honor preset dictionary for raw inflate with non-default window#105
iliaal wants to merge 1 commit into
PHP-8.4from
zlib-raw-dict-window

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

inflate_init() applies a preset dictionary eagerly for raw streams via inflateSetDictionary(), gated on encoding == PHP_ZLIB_ENCODING_RAW. But encoding is first adjusted by the window size (encoding += 15 - window), so a raw stream opened with a non-default window no longer compares equal to PHP_ZLIB_ENCODING_RAW and the dictionary is silently dropped. Raw streams carry no zlib header and never emit Z_NEED_DICT, so inflate_add()'s deferred dictionary path never applies it either. The deflate side applies the dictionary unconditionally, so deflate_init(ZLIB_ENCODING_RAW, ['window'=>10, 'dictionary'=>$d]) + the matching inflate produced a data error instead of a roundtrip. Gate on the pre-adjustment encoding.

…ndow

inflate_init() applies the preset dictionary eagerly for raw streams via
inflateSetDictionary(), gated on encoding == PHP_ZLIB_ENCODING_RAW. But
encoding is first adjusted by the window size (encoding += 15 - window),
so a raw stream with a non-default window no longer equals
PHP_ZLIB_ENCODING_RAW and the dictionary is silently dropped; raw streams
carry no header and never emit Z_NEED_DICT, so inflate_add()'s deferred
path never applies it either. Gate on the pre-adjustment encoding. The
deflate side already applies the dictionary unconditionally, so the
roundtrip was broken for this case.
@iliaal

iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22381.

@iliaal iliaal closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant