- Notifications
You must be signed in to change notification settings - Fork8k
Closed
Description
Description
The following code:
<?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 checksumfseek($stream, -1,SEEK_CUR);fwrite($stream,'1');// Rewind and add the zlib filterrewind($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 falsevar_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 20PHP Stack trace:PHP 1. {main}() /home/nicolas/Source/php/sphinx-inventory-parser/test.php:0PHP 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 20PHP Stack trace:PHP 1. {main}() /home/nicolas/Source/php/sphinx-inventory-parser/test.php:0PHP 2. fgets($stream = resource(5) of type (stream)) /home/nicolas/Source/php/sphinx-inventory-parser/test.php:20
If an error occurs,
false
is returned.
Also note that by replacing10000
with a smaller number, say1000
I get the expected output.
PHP Version
PHP 8.2.12
Operating System
Debian testing