@@ -761,24 +761,6 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
761
761
switch (Z_TYPE_P (option_buffer )) {
762
762
case IS_STRING : {
763
763
zend_string * str = Z_STR_P (option_buffer );
764
- int i ;
765
- zend_bool last_null = 1 ;
766
-
767
- for (i = 0 ; i < ZSTR_LEN (str ); i ++ ) {
768
- if (ZSTR_VAL (str )[i ]) {
769
- last_null = 0 ;
770
- } else {
771
- if (last_null ) {
772
- php_error_docref (NULL , E_WARNING , "dictionary string must not contain empty entries (two consecutive NULL-bytes or one at the very beginning)" );
773
- return 0 ;
774
- }
775
- last_null = 1 ;
776
- }
777
- }
778
- if (!last_null ) {
779
- php_error_docref (NULL , E_WARNING , "dictionary string must be NULL-byte terminated (each dictionary entry has to be NULL-terminated)" );
780
- }
781
-
782
764
* dict = emalloc (ZSTR_LEN (str ));
783
765
memcpy (* dict , ZSTR_VAL (str ), ZSTR_LEN (str ));
784
766
* dictlen = ZSTR_LEN (str );
@@ -894,6 +876,21 @@ PHP_FUNCTION(inflate_init)
894
876
}
895
877
896
878
if (Z_OK == inflateInit2 (ctx , encoding )) {
879
+ if (encoding == PHP_ZLIB_ENCODING_RAW && dictlen > 0 ) {
880
+ php_zlib_context * php_ctx = (php_zlib_context * ) ctx ;
881
+ switch (inflateSetDictionary (ctx , (Bytef * ) php_ctx -> inflateDict , php_ctx -> inflateDictlen )) {
882
+ case Z_OK :
883
+ efree (php_ctx -> inflateDict );
884
+ php_ctx -> inflateDict = NULL ;
885
+ break ;
886
+ case Z_DATA_ERROR :
887
+ php_error_docref (NULL , E_WARNING , "dictionary does not match expected dictionary (incorrect adler32 hash)" );
888
+ efree (php_ctx -> inflateDict );
889
+ php_ctx -> inflateDict = NULL ;
890
+ RETURN_FALSE ;
891
+ EMPTY_SWITCH_DEFAULT_CASE ()
892
+ }
893
+ }
897
894
RETURN_RES (zend_register_resource (ctx , le_inflate ));
898
895
} else {
899
896
efree (ctx );
0 commit comments