mirror of
https://github.com/php/php-src.git
synced 2026-04-29 19:23:22 +02:00
d59aac58b3
The php_stream_read() and php_stream_write() functions now return an ssize_t value, with negative results indicating failure. Functions like fread() and fwrite() will return false in that case. As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams should not be regarded as error conditions, and be reported as successful zero-length reads/writes instead. The handling of EINTR remains unclear and is internally inconsistent (e.g. some code-paths will automatically retry on EINTR, while some won't). I'm landing this now to make sure the stream wrapper ops API changes make it into 7.4 -- however, if the user-facing changes turn out to be problematic we have the option of clamping negative returns to zero in php_stream_read() and php_stream_write() to restore the old behavior in a relatively non-intrusive manner.
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
--TEST--
|
|
Bug #71263: fread() does not detects decoding errors from filter bzip2.decompress
|
|
--FILE--
|
|
<?php
|
|
|
|
// Should notices be generated?
|
|
|
|
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);
|
|
?>
|
|
--EXPECT--
|
|
Compressed len = 81
|
|
read: bool(false)
|
|
Compressed len = 81
|
|
read: string(0) ""
|
|
Compressed len = 81
|
|
read: bool(false)
|