[php-src] Issue #13264: fgets() does not return false on error from a zlib.inflate filtered stream with large content and invalid checksum
| From: | n-peugnet | Date: | Sun, 28 Jan 2024 21:14:54 +0000 |
| Subject: | [php-src] Issue #13264: fgets() does not return false on error from a zlib.inflate filtered stream with large content and invalid checksum | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246354@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13264
Author: n-peugnet
### Description
The following code:
```php
<?php
// Prepare a big enough input so that it is not entirely buffered
$stream = fopen('php://memory', 'r+');
$content = '';
for ($i = 0; $i < 10000; $i++) {
$content .= "Hello $i\n";
}
fwrite($stream, gzcompress($content));
// Mess up the checksum
fseek($stream, -1, SEEK_CUR);
fwrite($stream, '1');
// Rewind and add the zlib filter
rewind($stream);
stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_READ, ['window'
=> 15]);
// Read the filtered stream line by line.
while (($line = fgets($stream)) !== false) {
$error = error_get_last();
if ($error !== null) {
// An error is thrown but fgets didn't return false
var_dump(error_get_last());
var_dump($line);
}
}
fclose($stream);
```
Resulted in this output:
```
PHP Notice: fgets(): zlib: data error in /home/nicolas/Source/php/sphinx-inventory-parser/test.php
on line 20
PHP Stack trace:
PHP 1. {main}() /home/nicolas/Source/php/sphinx-inventory-parser/test.php:0
PHP 2. fgets($stream = resource(5) of type (stream))
/home/nicolas/Source/php/sphinx-inventory-parser/test.php:20
/home/nicolas/Source/php/sphinx-inventory-parser/test.php:24:
array(4) {
'type' =>
int(8)
'message' =>
string(25) "fgets(): zlib: data error"
'file' =>
string(57) "/home/nicolas/Source/php/sphinx-inventory-parser/test.php"
'line' =>
int(20)
}
/home/nicolas/Source/php/sphinx-inventory-parser/test.php:25:
string(7) "Hello 6"
```
But I expected this output instead:
```
PHP Notice: fgets(): zlib: data error in /home/nicolas/Source/php/sphinx-inventory-parser/test.php
on line 20
PHP Stack trace:
PHP 1. {main}() /home/nicolas/Source/php/sphinx-inventory-parser/test.php:0
PHP 2. fgets($stream = resource(5) of type (stream))
/home/nicolas/Source/php/sphinx-inventory-parser/test.php:20
```
Also note that by replacing
10000 with a smaller number, say 1000 I get
the expected output.
### PHP Version
PHP 8.2.12
### Operating System
Debian testing