Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ext/zlib/tests/inflate_add_no_dict.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
inflate_add(): Z_NEED_DICT returned when no dictionary provided to inflate_init()
--EXTENSIONS--
zlib
--FILE--
<?php

$dict = "the quick brown fox jumps over the lazy dog";
$data = "the quick brown fox";

$dc = deflate_init(ZLIB_ENCODING_DEFLATE, ['dictionary' => $dict]);
$compressed = deflate_add($dc, $data, ZLIB_FINISH);

// Inflate without supplying the dictionary
$ic = inflate_init(ZLIB_ENCODING_DEFLATE);
$result = inflate_add($ic, $compressed, ZLIB_SYNC_FLUSH);
var_dump($result);

?>
--EXPECTF--
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
bool(false)
3 changes: 2 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ PHP_FUNCTION(inflate_init)
}

if (inflateInit2(&ctx->Z, encoding) != Z_OK) {
efree(dict);
/* dict is stored in the ctx in the object and will thus be freed by zval_ptr_dtor(). */
zval_ptr_dtor(return_value);
php_error_docref(NULL, E_WARNING, "Failed allocating zlib.inflate context");
RETURN_FALSE;
Expand Down Expand Up @@ -1026,6 +1026,7 @@ PHP_FUNCTION(inflate_add)
}
break;
} else {
zend_string_release_ex(out, false);
php_error_docref(NULL, E_WARNING, "Inflating this data requires a preset dictionary, please specify it in the options array of inflate_init()");
RETURN_FALSE;
}
Expand Down
Loading