--- /dev/null
+--TEST--
+Bug #73944: Dictionary option of intflate_init() does not work
+--FILE--
+<?php
+
+$in = inflate_init(ZLIB_ENCODING_RAW, array('dictionary' => str_repeat("\00", 32768)));
+$a = inflate_add($in, file_get_contents(__DIR__.'/bug73944_fixture1'));
+echo '1 block: '.strlen($a).PHP_EOL;
+
+$in = inflate_init(ZLIB_ENCODING_RAW, array('dictionary' => $a));
+$b = inflate_add($in, file_get_contents(__DIR__.'/bug73944_fixture2'));
+echo '2 block: '.($b === false ? 'failed' : strlen($b)).PHP_EOL;
+
+?>
+--EXPECTF--
+1 block: 32768
+2 block: 32768
switch (Z_TYPE_P(option_buffer)) {
case IS_STRING: {
zend_string *str = Z_STR_P(option_buffer);
- int i;
- zend_bool last_null = 1;
-
- for (i = 0; i < ZSTR_LEN(str); i++) {
- if (ZSTR_VAL(str)[i]) {
- last_null = 0;
- } else {
- if (last_null) {
- php_error_docref(NULL, E_WARNING, "dictionary string must not contain empty entries (two consecutive NULL-bytes or one at the very beginning)");
- return 0;
- }
- last_null = 1;
- }
- }
- if (!last_null) {
- php_error_docref(NULL, E_WARNING, "dictionary string must be NULL-byte terminated (each dictionary entry has to be NULL-terminated)");
- }
-
*dict = emalloc(ZSTR_LEN(str));
memcpy(*dict, ZSTR_VAL(str), ZSTR_LEN(str));
*dictlen = ZSTR_LEN(str);
}
if (Z_OK == inflateInit2(ctx, encoding)) {
+ if (encoding == PHP_ZLIB_ENCODING_RAW && dictlen > 0) {
+ php_zlib_context *php_ctx = (php_zlib_context *) ctx;
+ switch (inflateSetDictionary(ctx, (Bytef *) php_ctx->inflateDict, php_ctx->inflateDictlen)) {
+ case Z_OK:
+ efree(php_ctx->inflateDict);
+ php_ctx->inflateDict = NULL;
+ break;
+ case Z_DATA_ERROR:
+ php_error_docref(NULL, E_WARNING, "dictionary does not match expected dictionary (incorrect adler32 hash)");
+ efree(php_ctx->inflateDict);
+ php_ctx->inflateDict = NULL;
+ RETURN_FALSE;
+ EMPTY_SWITCH_DEFAULT_CASE()
+ }
+ }
RETURN_RES(zend_register_resource(ctx, le_inflate));
} else {
efree(ctx);