Repository navigation
ext/standard: Adds and modifies XFAIL tests for filter bucket leaks #23440
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
NickSdot
wants to merge
1
commit into
php:master
Choose a base branch
from
NickSdot:tests/sfr-xfail-warn
base: master
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.
+198
−4
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
27 changes: 25 additions & 2 deletions
27
ext/standard/tests/filters/stream_filter_register_class_coerce_consumed_by_ref_param.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
27 changes: 25 additions & 2 deletions
27
ext/standard/tests/filters/stream_filter_register_mock_class_filter.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
80 changes: 80 additions & 0 deletions
80
ext/standard/tests/filters/stream_filter_register_unprocessed_buckets.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,80 @@ | ||
| --TEST-- | ||
| stream_filter_register() with classes that leave unprocessed buckets for PSFS_FEED_ME and PSFS_ERR_FATAL | ||
| --SKIPIF-- | ||
| <?php | ||
|
|
||
| // this leaks memory | ||
| // remove SKIPIF section when debug builds report "warn: XFAIL section but test passes" | ||
|
|
||
| if (getenv('SKIP_MSAN')) { | ||
| die('skip requires a leak detector'); | ||
| } | ||
|
|
||
| if (getenv('SKIP_ASAN') && PHP_OS_FAMILY !== 'Windows') { | ||
| die('xfail User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| if (PHP_DEBUG && getenv('USE_ZEND_ALLOC') !== '0') { | ||
| die('xfail User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| if (getenv('USE_ZEND_ALLOC') === '0' && getenv('ZEND_DONT_UNLOAD_MODULES') === '1') { | ||
| die('xleak User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| die('skip requires a leak detector'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class FeedFilter extends php_user_filter | ||
| { | ||
| public function filter($in, $out, &$consumed, bool $closing): int { | ||
| return PSFS_FEED_ME; | ||
| } | ||
| } | ||
|
|
||
| class FatalFilter extends php_user_filter | ||
| { | ||
| private bool $emitted = false; | ||
|
|
||
| public function filter($in, $out, &$consumed, bool $closing): int | ||
| { | ||
| if ($closing && !$this->emitted) { | ||
| $this->emitted = true; | ||
| $bucket = stream_bucket_new($this->stream, "x"); | ||
| stream_bucket_append($out, $bucket); | ||
| } | ||
|
|
||
| return PSFS_ERR_FATAL; | ||
| } | ||
| } | ||
|
|
||
| stream_filter_register("test.feed", FeedFilter::class); | ||
|
|
||
| $stream = fopen("php://memory", "w+"); | ||
| fwrite($stream, "x\nabcdef"); | ||
| rewind($stream); | ||
|
|
||
| var_dump(fgets($stream)); | ||
| var_dump(stream_filter_append($stream, "test.feed", STREAM_FILTER_READ)); | ||
| fclose($stream); | ||
|
|
||
| stream_filter_register("test.fatal", FatalFilter::class); | ||
|
|
||
| $stream = fopen("php://memory", "w+"); | ||
| $filter = stream_filter_append($stream, "test.fatal", STREAM_FILTER_WRITE); | ||
|
|
||
| var_dump(stream_filter_remove($filter)); | ||
| fclose($stream); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| string(2) "x | ||
| " | ||
|
|
||
| Warning: stream_filter_append(): Unprocessed filter buckets remaining on input brigade in %s on line %d | ||
| resource(%d) of type (stream filter) | ||
|
|
||
| Warning: stream_filter_remove(): Unable to flush filter, not removing in %s on line %d | ||
| bool(false) |
68 changes: 68 additions & 0 deletions
68
ext/standard/tests/filters/stream_filter_register_unprocessed_buckets_reentrant.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,68 @@ | ||
| --TEST-- | ||
| stream_filter_register() with a class whose input brigade is modified by a warning handler | ||
| --SKIPIF-- | ||
| <?php | ||
|
|
||
| // this leaks memory | ||
| // remove SKIPIF section when debug builds report "warn: XFAIL section but test passes" | ||
|
|
||
| if (getenv('SKIP_MSAN')) { | ||
| die('skip requires a leak detector'); | ||
| } | ||
|
|
||
| if (getenv('SKIP_ASAN') && PHP_OS_FAMILY !== 'Windows') { | ||
| die('xfail User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| if (PHP_DEBUG && getenv('USE_ZEND_ALLOC') !== '0') { | ||
| die('xfail User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| if (getenv('USE_ZEND_ALLOC') === '0' && getenv('ZEND_DONT_UNLOAD_MODULES') === '1') { | ||
| die('xleak User filters leak unprocessed buckets'); | ||
| } | ||
|
|
||
| die('skip requires a leak detector'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class ReentrantFilter extends php_user_filter | ||
| { | ||
| private bool $firstCall = true; | ||
|
|
||
| public function filter($in, $out, &$consumed, bool $closing): int | ||
| { | ||
| if ($this->firstCall) { | ||
| $this->firstCall = false; | ||
| $GLOBALS['brigade'] = $in; | ||
| $GLOBALS['bucket'] = stream_bucket_new($this->stream, 'refilled'); | ||
| } | ||
|
|
||
| return PSFS_PASS_ON; | ||
| } | ||
| } | ||
|
|
||
| stream_filter_register('test.reentrant', ReentrantFilter::class); | ||
|
|
||
| set_error_handler(static function (int $severity, string $message): bool | ||
| { | ||
| if (str_contains($message, 'Unprocessed filter buckets')) { | ||
| stream_bucket_append($GLOBALS['brigade'], $GLOBALS['bucket']); | ||
| echo "Handled warning\n"; | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
|
|
||
| $stream = fopen('php://memory', 'w+'); | ||
| stream_filter_append($stream, 'test.reentrant', STREAM_FILTER_WRITE); | ||
|
|
||
| var_dump(fwrite($stream, 'input')); | ||
| fclose($stream); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Handled warning | ||
| int(0) | ||
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.
Just a note that this will no longer apply after #24146