-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-13264: fgets() and stream_get_line() do not return false on filter fatal error #18778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bukka
wants to merge
1
commit into
php:PHP-8.3
Choose a base branch
from
bukka:stream_gh13264_filter_fatal_err
base: PHP-8.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,57 @@ | ||
--TEST-- | ||
GH-81475: Memory leak during stream filter failure | ||
GH-13264: fgets() and stream_get_line() do not return false on filter fatal error | ||
--SKIPIF-- | ||
<?php require 'filter_errors.inc'; filter_errors_skipif('zlib.inflate'); ?> | ||
--FILE-- | ||
<?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)); | ||
function create_stream() | ||
{ | ||
// 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'); | ||
|
||
// 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]); | ||
|
||
// Rewind and add the zlib filter | ||
rewind($stream); | ||
stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 15]); | ||
return $stream; | ||
} | ||
|
||
// Read the filtered stream line by line. | ||
// Read the filtered stream line by line using fgets. | ||
$stream = create_stream(); | ||
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); | ||
} | ||
$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); | ||
error_clear_last(); | ||
|
||
// Read the filtered stream line by line using stream_get_line. | ||
$stream = create_stream(); | ||
while (($line = stream_get_line($stream, 0, "\n")) !== 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); | ||
?> | ||
--EXPECTF-- | ||
|
||
Notice: fgets(): zlib: data error in %s on line %d | ||
array(4) { | ||
["type"]=> | ||
int(8) | ||
["message"]=> | ||
string(25) "fgets(): zlib: data error" | ||
["file"]=> | ||
string(%d) "%s" | ||
["line"]=> | ||
int(%d) | ||
} | ||
string(%d) "Hello%s" | ||
|
||
Notice: stream_get_line(): zlib: data error in %s on line %d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a minor copy-paste error in this comment:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will change it before the commit (sparing CI cycles for now :) )