58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
--TEST--
|
|
Bug #71263: fread() does not report bzip2.decompress errors
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("bz2")) print "skip bz2 extension not loaded"; ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
function test($case) {
|
|
$plain = "The quick brown fox jumps over the lazy dog.";
|
|
$fn = "bug71263.bz2";
|
|
$compressed = (string) bzcompress($plain);
|
|
echo "Compressed len = ", strlen($compressed), "\n";
|
|
|
|
if ($case == 1) {
|
|
// Set a random byte in the middle of the compressed data
|
|
// --> php_bz2_decompress_filter() detects fatal error
|
|
// --> fread() displays empty string then garbage, no errors detected:
|
|
$compressed[strlen($compressed) - 15] = 'X';
|
|
} else if ($case == 2) {
|
|
// Truncate the compressed data
|
|
// --> php_bz2_decompress_filter() does not detect errors,
|
|
// --> fread() displays the empty string:
|
|
$compressed = substr($compressed, 0, strlen($compressed) - 20);
|
|
} else {
|
|
// Corrupted final CRC
|
|
// --> php_bz2_decompress_filter() detects fatal error
|
|
// --> fread() displays an empty string, then the correct plain text, no error detected:
|
|
$compressed[strlen($compressed)-2] = 'X';
|
|
}
|
|
|
|
file_put_contents($fn, $compressed);
|
|
|
|
$r = fopen($fn, "r");
|
|
stream_filter_append($r, 'bzip2.decompress', STREAM_FILTER_READ);
|
|
while (!feof($r)) {
|
|
$s = fread($r, 100);
|
|
echo "read: "; var_dump($s);
|
|
}
|
|
fclose($r);
|
|
unlink($fn);
|
|
}
|
|
|
|
test(1);
|
|
test(2);
|
|
test(3);
|
|
?>
|
|
--EXPECTF--
|
|
Compressed len = 81
|
|
|
|
Notice: fread(): bzip2 decompression failed in %s on line %d
|
|
read: bool(false)
|
|
Compressed len = 81
|
|
read: string(0) ""
|
|
Compressed len = 81
|
|
|
|
Notice: fread(): bzip2 decompression failed in %s on line %d
|
|
read: bool(false)
|