-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-19685: Segfault when bzip2 filter has invalid parameters #19702
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
alexandre-daubois
wants to merge
1
commit into
php:PHP-8.3
from
alexandre-daubois:stream-append-bz2-failure
+60
−0
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 |
---|---|---|
|
@@ -367,6 +367,10 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi | |
zend_long blocks = zval_get_long(tmpzval); | ||
if (blocks < 1 || blocks > 9) { | ||
php_error_docref(NULL, E_WARNING, "Invalid parameter given for number of blocks to allocate (" ZEND_LONG_FMT ")", blocks); | ||
pefree(data->strm.next_in, persistent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: only if you want, on master only maybe, making a goto label to cover the 3 cases. |
||
pefree(data->strm.next_out, persistent); | ||
pefree(data, persistent); | ||
return NULL; | ||
} else { | ||
blockSize100k = (int) blocks; | ||
} | ||
|
@@ -377,6 +381,10 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi | |
zend_long work = zval_get_long(tmpzval); | ||
if (work < 0 || work > 250) { | ||
php_error_docref(NULL, E_WARNING, "Invalid parameter given for work factor (" ZEND_LONG_FMT ")", work); | ||
pefree(data->strm.next_in, persistent); | ||
pefree(data->strm.next_out, persistent); | ||
pefree(data, persistent); | ||
return NULL; | ||
} else { | ||
workFactor = (int) work; | ||
} | ||
|
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
46 changes: 46 additions & 0 deletions
ext/bz2/tests/bz2_filter_invalid_params.phpt
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
GH-19685: bzip2.compress filter with invalid parameters should fail gracefully | ||
--EXTENSIONS-- | ||
bz2 | ||
--FILE-- | ||
<?php | ||
$stream = fopen('php://memory', 'w+'); | ||
|
||
// too low | ||
$filter = stream_filter_append($stream, 'bzip2.compress', STREAM_FILTER_WRITE, array('blocks' => 0)); | ||
var_dump($filter); | ||
|
||
// too high | ||
$filter = stream_filter_append($stream, 'bzip2.compress', STREAM_FILTER_WRITE, array('blocks' => 10)); | ||
var_dump($filter); | ||
|
||
// too low work | ||
$filter = stream_filter_append($stream, 'bzip2.compress', STREAM_FILTER_WRITE, array('work' => -1)); | ||
var_dump($filter); | ||
|
||
// too high work | ||
$filter = stream_filter_append($stream, 'bzip2.compress', STREAM_FILTER_WRITE, array('work' => 251)); | ||
var_dump($filter); | ||
|
||
fclose($stream); | ||
?> | ||
--EXPECTF-- | ||
Warning: stream_filter_append(): Invalid parameter given for number of blocks to allocate (0) in %s on line %d | ||
|
||
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.compress" in %s on line %d | ||
bool(false) | ||
|
||
Warning: stream_filter_append(): Invalid parameter given for number of blocks to allocate (10) in %s on line %d | ||
|
||
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.compress" in %s on line %d | ||
bool(false) | ||
|
||
Warning: stream_filter_append(): Invalid parameter given for work factor (-1) in %s on line %d | ||
|
||
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.compress" in %s on line %d | ||
bool(false) | ||
|
||
Warning: stream_filter_append(): Invalid parameter given for work factor (251) in %s on line %d | ||
|
||
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.compress" in %s on line %d | ||
bool(false) |
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.