blob: b20bbd8ef1daa57f0e48a6852ba01fdff488bde3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
--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)
|