Skip to content

Commit 64760a1

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/zlib: honor preset dictionary for raw inflate with non-default window
2 parents 198ee90 + fb76b3d commit 64760a1

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ PHP NEWS
7878
PROCESS_INFORMATION, an indeterminate comspec pointer after a failed
7979
lookup, and an unchecked CreateFileA() failure. (Ilia Alshanetsky)
8080

81+
- Zlib:
82+
. Fixed inflate_init() dropping the preset dictionary for raw streams with
83+
a non-default window. (Ilia Alshanetsky)
84+
8185

8286
10 Sep 2026, PHP 8.6.0beta3
8387

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
inflate_init(): preset dictionary is honored for raw encoding with a non-default window
3+
--EXTENSIONS--
4+
zlib
5+
--FILE--
6+
<?php
7+
$dict = "the quick brown fox jumps over the lazy dog";
8+
$data = str_repeat($dict . " ", 8);
9+
$opts = ['window' => 10, 'dictionary' => $dict];
10+
11+
$def = deflate_init(ZLIB_ENCODING_RAW, $opts);
12+
$comp = deflate_add($def, $data, ZLIB_FINISH);
13+
14+
$inf = inflate_init(ZLIB_ENCODING_RAW, $opts);
15+
$out = inflate_add($inf, $comp, ZLIB_FINISH);
16+
17+
var_dump($out === $data);
18+
?>
19+
--EXPECT--
20+
bool(true)

ext/zlib/zlib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ PHP_FUNCTION(inflate_init)
943943
ctx->inflateDictlen = dictlen;
944944
ctx->status = Z_OK;
945945

946+
zend_long orig_encoding = encoding;
946947
if (encoding < 0) {
947948
encoding += 15 - window;
948949
} else {
@@ -956,7 +957,7 @@ PHP_FUNCTION(inflate_init)
956957
RETURN_FALSE;
957958
}
958959

959-
if (encoding == PHP_ZLIB_ENCODING_RAW && dictlen > 0) {
960+
if (orig_encoding == PHP_ZLIB_ENCODING_RAW && dictlen > 0) {
960961
switch (inflateSetDictionary(&ctx->Z, (Bytef *) ctx->inflateDict, ctx->inflateDictlen)) {
961962
case Z_OK:
962963
efree(ctx->inflateDict);

0 commit comments

Comments
 (0)