Skip to content

Commit 0814870

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: zlib: Fix memory leak in inflate_add() zlib: no need to free dict on inflate init error
2 parents 16e217e + 73d9145 commit 0814870

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PHP NEWS
2727
- Zlib:
2828
. Fixed memory leak if deflate initialization fails and there is a dict.
2929
(ndossche)
30+
. Fixed memory leak in inflate_add(). (ndossche)
3031

3132
02 Jun 2026, PHP 8.5.7
3233

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
inflate_add(): Z_NEED_DICT returned when no dictionary provided to inflate_init()
3+
--EXTENSIONS--
4+
zlib
5+
--FILE--
6+
<?php
7+
8+
$dict = "the quick brown fox jumps over the lazy dog";
9+
$data = "the quick brown fox";
10+
11+
$dc = deflate_init(ZLIB_ENCODING_DEFLATE, ['dictionary' => $dict]);
12+
$compressed = deflate_add($dc, $data, ZLIB_FINISH);
13+
14+
// Inflate without supplying the dictionary
15+
$ic = inflate_init(ZLIB_ENCODING_DEFLATE);
16+
$result = inflate_add($ic, $compressed, ZLIB_SYNC_FLUSH);
17+
var_dump($result);
18+
19+
?>
20+
--EXPECTF--
21+
Warning: inflate_add(): Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init() in %s on line %d
22+
bool(false)

ext/zlib/zlib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ PHP_FUNCTION(inflate_init)
911911
}
912912

913913
if (inflateInit2(&ctx->Z, encoding) != Z_OK) {
914-
efree(dict);
914+
/* dict is stored in the ctx in the object and will thus be freed by zval_ptr_dtor(). */
915915
zval_ptr_dtor(return_value);
916916
php_error_docref(NULL, E_WARNING, "Failed allocating zlib.inflate context");
917917
RETURN_FALSE;
@@ -1029,6 +1029,7 @@ PHP_FUNCTION(inflate_add)
10291029
}
10301030
break;
10311031
} else {
1032+
zend_string_release_ex(out, false);
10321033
php_error_docref(NULL, E_WARNING, "Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
10331034
RETURN_FALSE;
10341035
}

0 commit comments

Comments
 (0)