com php-src: Improve ZBLOCK handling with zlib < 1.2.4: ext/zlib/tests/deflate_add_basic.phpt ext/zlib/tests/de flate_add_block_v123.phpt
ext/zlib/tests/inflat e_add_basic.phpt ext/zlib/zlib.c

From: Date: Thu, 07 May 2015 14:31:41 +0000
Subject: com php-src: Improve ZBLOCK handling with zlib < 1.2.4: ext/zlib/tests/deflate_add_basic.phpt ext/zlib/tests/de flate_add_block_v123.phpt
ext/zlib/tests/inflat e_add_basic.phpt ext/zlib/zlib.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-86649@lists.php.net to get a copy of this message
Commit: c48817297505b5181321047d0a5704e55a6efd6e Author: Daniel Lowrey <rdlowrey@php.net> Thu, 7 May 2015 10:26:56 -0400 Parents: 3cc59b3fa0d2bbea6f5d19eb38668f7b9c30b449 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c48817297505b5181321047d0a5704e55a6efd6e Log: 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). Changed paths: M ext/zlib/tests/deflate_add_basic.phpt A ext/zlib/tests/deflate_add_block_v123.phpt M ext/zlib/tests/inflate_add_basic.phpt M ext/zlib/zlib.c Diff: diff --git a/ext/zlib/tests/deflate_add_basic.phpt b/ext/zlib/tests/deflate_add_basic.phpt index fde22b5..05fcb03 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 0000000..3fe03f9 --- /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-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +if (ZLIB_VERNUM >= 0x1240) { + print "skip - ZLIB < 1.2.4 required for test"; +} +?> +--FILE-- +<?php + +$resource = deflate_init(ZLIB_ENCODING_GZIP); +var_dump(deflate_add($resource, "aaaaaaaaaaaaaaaaaaaaaa", ZLIB_BLOCK)); + +?> +===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 7ef5ef1...ff0458e 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 2b9c016..c375613 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; }

« previous php.cvs (#86649) next »