Skip to content

Commit d29ae33

Browse files
committed
zlib: Fix memory leak in inflate_add()
1 parent d88aaf5 commit d29ae33

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ PHP_FUNCTION(inflate_add)
10261026
}
10271027
break;
10281028
} else {
1029+
zend_string_release_ex(out, false);
10291030
php_error_docref(NULL, E_WARNING, "Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
10301031
RETURN_FALSE;
10311032
}

0 commit comments

Comments
 (0)