mirror of
https://github.com/php/php-src.git
synced 2024-10-01 06:46:08 +00:00
c488172975
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).
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
--TEST--
|
|
Test incremental deflate_add() functionality
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded("zlib")) {
|
|
print "skip - ZLIB extension not loaded";
|
|
}
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
function deflateStream($mode, $flushSize, $flushType) {
|
|
$buffer = "";
|
|
$deflated = null;
|
|
$resource = deflate_init($mode);
|
|
|
|
while (true) {
|
|
$dataToCompress = yield $deflated;
|
|
if (isset($dataToCompress)) {
|
|
$buffer .= $dataToCompress;
|
|
if (strlen($buffer) >= $flushSize) {
|
|
$deflated = deflate_add($resource, $buffer, $flushType);
|
|
$buffer = "";
|
|
} else {
|
|
$deflated = null;
|
|
}
|
|
} else {
|
|
$deflated = deflate_add($resource, $buffer, ZLIB_FINISH);
|
|
}
|
|
}
|
|
}
|
|
|
|
$modes = [
|
|
'ZLIB_ENCODING_RAW' => ZLIB_ENCODING_RAW,
|
|
'ZLIB_ENCODING_GZIP' => ZLIB_ENCODING_GZIP,
|
|
'ZLIB_ENCODING_DEFLATE' => ZLIB_ENCODING_DEFLATE,
|
|
];
|
|
$flushSizes = [1, 4, 32768];
|
|
$flushTypes = [
|
|
'ZLIB_SYNC_FLUSH' => ZLIB_SYNC_FLUSH,
|
|
'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH,
|
|
'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH,
|
|
'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH,
|
|
];
|
|
|
|
/* Z_BLOCK is only available for deflate when built against zlib >= 1.2.4 */
|
|
if (ZLIB_VERNUM >= 0x1240) {
|
|
$flushTypes['ZLIB_BLOCK'] = ZLIB_BLOCK;
|
|
}
|
|
|
|
foreach ($modes as $modeKey => $mode) {
|
|
foreach ($flushSizes as $flushSize) {
|
|
foreach ($flushTypes as $flushTypeKey => $flushType) {
|
|
$uncompressed = $compressed = "";
|
|
$stream = deflateStream($mode, $flushSize, $flushType);
|
|
foreach (range("a", "z") as $c) {
|
|
$uncompressed .= $c;
|
|
$compressed .= $stream->send($c);
|
|
}
|
|
$compressed .= $stream->send(null);
|
|
if ($uncompressed !== zlib_decode($compressed)) {
|
|
echo "Error: {$modeKey} | {$flushSize} | {$flushTypeKey}\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
===DONE===
|
|
--EXPECTF--
|
|
===DONE===
|