From: Daniel Lowrey Date: Thu, 7 May 2015 14:26:56 +0000 (-0400) Subject: Improve ZBLOCK handling with zlib < 1.2.4 X-Git-Tag: PRE_PHP7_NSAPI_REMOVAL~64 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c48817297505b5181321047d0a5704e55a6efd6e;p=php Improve ZBLOCK handling with zlib < 1.2.4 The original commit for this issue (62b1293) assumed Z_BLOCK was only defined in < 1.2.4. However, this flush type *is* defined but is only unavailable for use with deflate(). This new commit correctly checks the ZLIB_VERNUM constant to determine if Z_BLOCK flush is available for the current deflate() operation and triggers an appropriate error as needed. New ZLIB_VERSION and ZLIB_VERNUM constants are also exposed in userland to allow testing this behavior in environments running zlib < 1.2.4 (ZLIB_VERNUM check is needed). --- diff --git a/ext/zlib/tests/deflate_add_basic.phpt b/ext/zlib/tests/deflate_add_basic.phpt index fde22b5a52..05fcb037bd 100644 --- a/ext/zlib/tests/deflate_add_basic.phpt +++ b/ext/zlib/tests/deflate_add_basic.phpt @@ -43,8 +43,8 @@ $flushTypes = [ 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, ]; -/* Z_BLOCK is only defined when built against zlib > 1.2.3 */ -if (defined(ZLIB_BLOCK)) { +/* Z_BLOCK is only available for deflate when built against zlib >= 1.2.4 */ +if (ZLIB_VERNUM >= 0x1240) { $flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK; } diff --git a/ext/zlib/tests/deflate_add_block_v123.phpt b/ext/zlib/tests/deflate_add_block_v123.phpt new file mode 100644 index 0000000000..3fe03f99ba --- /dev/null +++ b/ext/zlib/tests/deflate_add_block_v123.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test deflate_add() errors with ZLIB_BLOCK in zlib < 1.2.4 +--SKIPIF-- += 0x1240) { + print "skip - ZLIB < 1.2.4 required for test"; +} +?> +--FILE-- + +===DONE=== +--EXPECTF-- + +Warning: deflate_add(): zlib >= 1.2.4 required for BLOCK deflate; current version: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/zlib/tests/inflate_add_basic.phpt b/ext/zlib/tests/inflate_add_basic.phpt index 7ef5ef11cb..ff0458e9ef 100644 --- a/ext/zlib/tests/inflate_add_basic.phpt +++ b/ext/zlib/tests/inflate_add_basic.phpt @@ -40,13 +40,9 @@ $flushTypes = [ 'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH, 'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH, 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, + 'ZLIB_BLOCK' => ZLIB_BLOCK, ]; -/* Z_BLOCK is only defined when built against zlib > 1.2.3 */ -if (defined(ZLIB_BLOCK)) { - $flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK; -} - $uncompressed = ""; for ($i=0;$i<(32768*2);$i++) { $uncompressed .= chr(rand(48,125)); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 2b9c016a41..c375613eba 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -46,13 +46,6 @@ #undef gzseek #undef gztell -/* Z_BLOCK was added in zlib 1.2.4 and stable distros (RHEL6, at least) still - * package zlib 1.2.3 - */ -#ifdef Z_BLOCK -#define HAVE_Z_BLOCK 1 -#endif - int le_deflate; int le_inflate; @@ -821,9 +814,7 @@ PHP_FUNCTION(inflate_add) case Z_PARTIAL_FLUSH: case Z_SYNC_FLUSH: case Z_FULL_FLUSH: -#ifdef HAVE_Z_BLOCK case Z_BLOCK: -#endif case Z_FINISH: break; @@ -965,13 +956,16 @@ PHP_FUNCTION(deflate_add) } switch (flush_type) { + case Z_BLOCK: +#if ZLIB_VERNUM < 0x1240L + php_error_docref(NULL, E_WARNING, + "zlib >= 1.2.4 required for BLOCK deflate; current version: %s", ZLIB_VERSION); + RETURN_FALSE; +#endif case Z_NO_FLUSH: case Z_PARTIAL_FLUSH: case Z_SYNC_FLUSH: case Z_FULL_FLUSH: -#ifdef HAVE_Z_BLOCK - case Z_BLOCK: -#endif case Z_FINISH: break; @@ -1279,10 +1273,12 @@ static PHP_MINIT_FUNCTION(zlib) REGISTER_LONG_CONSTANT("ZLIB_PARTIAL_FLUSH", Z_PARTIAL_FLUSH, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_SYNC_FLUSH", Z_SYNC_FLUSH, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_FULL_FLUSH", Z_FULL_FLUSH, CONST_CS|CONST_PERSISTENT); -#ifdef HAVE_Z_BLOCK REGISTER_LONG_CONSTANT("ZLIB_BLOCK", Z_BLOCK, CONST_CS|CONST_PERSISTENT); -#endif REGISTER_LONG_CONSTANT("ZLIB_FINISH", Z_FINISH, CONST_CS|CONST_PERSISTENT); + + REGISTER_STRING_CONSTANT("ZLIB_VERSION", ZLIB_VERSION, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ZLIB_VERNUM", ZLIB_VERNUM, CONST_CS|CONST_PERSISTENT); + REGISTER_INI_ENTRIES(); return SUCCESS; }