com php-src: Remove invalid check of dictionary content and add initialization of dictionary if raw compression used: ext/zlib/tests/bug73944.phpt
ext/zlib/tests/bug73944 _fixture1 ext/zlib/tests/bug73944_fixture2 ext/zlib/zlib.c
| From: | Bob Weinand | Date: | Sun, 25 Jun 2017 08:53:28 +0000 |
| Subject: | com php-src: Remove invalid check of dictionary content and add initialization of dictionary if raw compression used: ext/zlib/tests/bug73944.phpt ext/zlib/tests/bug73944 _fixture1 ext/zlib/tests/bug73944_fixture2 ext/zlib/zlib.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98197@lists.php.net to get a copy of this message | ||
Commit: cd1869bcf2c6dc981133b844d915bd93f82f786c
Author: wapmorgan <wapmorgan@gmail.com> Sat, 24 Jun 2017 22:44:01 +0300
Committer: Bob Weinand <bobwei9@hotmail.com> Sun, 25 Jun 2017 10:53:28 +0200
Parents: 4d6100569b7611ef66086bec96fe8b5046e30ef7
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cd1869bcf2c6dc981133b844d915bd93f82f786c
Log:
Remove invalid check of dictionary content and add initialization of dictionary if raw compression
used
Changed paths:
A ext/zlib/tests/bug73944.phpt
A ext/zlib/tests/bug73944_fixture1
A ext/zlib/tests/bug73944_fixture2
M ext/zlib/zlib.c
Diff:
diff --git a/ext/zlib/tests/bug73944.phpt b/ext/zlib/tests/bug73944.phpt
new file mode 100644
index 0000000..c4291af
--- /dev/null
+++ b/ext/zlib/tests/bug73944.phpt
@@ -0,0 +1,17 @@
+--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
diff --git a/ext/zlib/tests/bug73944_fixture1 b/ext/zlib/tests/bug73944_fixture1
new file mode 100644
index 0000000..badc516
Binary files /dev/null and b/ext/zlib/tests/bug73944_fixture1 differ
diff --git a/ext/zlib/tests/bug73944_fixture2 b/ext/zlib/tests/bug73944_fixture2
new file mode 100644
index 0000000..1a9abd6
Binary files /dev/null and b/ext/zlib/tests/bug73944_fixture2 differ
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 80607b6..b3c1a88 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -761,24 +761,6 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
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);
@@ -894,6 +876,21 @@ PHP_FUNCTION(inflate_init)
}
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);