diff --git a/ext/zlib/tests/zlib_filter_deflate2.phpt b/ext/zlib/tests/zlib_filter_deflate2.phpt new file mode 100644 index 00000000000..764a7606f42 --- /dev/null +++ b/ext/zlib/tests/zlib_filter_deflate2.phpt @@ -0,0 +1,16 @@ +--TEST-- +zlib.deflate (with level parameter set) +--SKIPIF-- + +--FILE-- + 9)); +fwrite($fp, $text); +fclose($fp); + +?> +--EXPECT-- +A Dѫ΍1MBUv_(EL/aP=Pi ;6fCe4U9;w5 m / diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 59fb96895e6..c6146380394 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -370,7 +370,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f if (filterparams) { - zval **tmpzval; + zval **tmpzval, tmp; /* filterparams can either be a scalar value to indicate compression level (shortcut method) Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ @@ -379,8 +379,6 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_ARRAY: case IS_OBJECT: if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) { - zval tmp; - tmp = **tmpzval; zval_copy_ctor(&tmp); convert_to_long(&tmp); @@ -394,8 +392,6 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f } if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) { - zval tmp; - tmp = **tmpzval; zval_copy_ctor(&tmp); convert_to_long(&tmp); @@ -409,6 +405,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f } if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) { + tmp = **tmpzval; + /* Psuedo pass through to catch level validating code */ goto factory_setlevel; } @@ -416,19 +414,16 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_STRING: case IS_DOUBLE: case IS_LONG: - { - zval tmp; - - tmp = *filterparams; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); + tmp = *filterparams; factory_setlevel: - /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ - if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp)); - } else { - level = Z_LVAL(tmp); - } + zval_copy_ctor(&tmp); + convert_to_long(&tmp); + + /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ + if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp)); + } else { + level = Z_LVAL(tmp); } break; default: