Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fgets() does not return false on error from a zlib.inflate filtered stream with large content and invalid checksum #13264

Closed
@n-peugnet

Description

@n-peugnet

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

Asfgets manual says:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp