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).
'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;
}
--- /dev/null
+--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===
'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));
#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;
case Z_PARTIAL_FLUSH:
case Z_SYNC_FLUSH:
case Z_FULL_FLUSH:
-#ifdef HAVE_Z_BLOCK
case Z_BLOCK:
-#endif
case Z_FINISH:
break;
}
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;
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;
}