-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/standard: limit maximum number of filter chains #22110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| --TEST-- | ||
| At most 16 filters can be chained in one stream | ||
| --EXTENSIONS-- | ||
| filter | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function createFilterChains($n, $resource) { | ||
| $filter = 'string.toupper'; | ||
| $pipes = 'php://filter/' . implode('|', array_fill(0, $n, $filter)) . "/resource=$resource"; | ||
| $slashes = 'php://filter/' . implode('/', array_fill(0, $n, $filter)) . "/resource=$resource"; | ||
| $resources = str_repeat("php://filter/$filter/resource=", $n) . $resource; | ||
| return [$pipes, $slashes, $resources]; | ||
| } | ||
|
|
||
| echo "# file_get_contents on 16 filters\n"; | ||
| $allowed_read = createFilterChains(16, 'data:text/plain,sixteen'); | ||
| foreach ($allowed_read as $chain) { | ||
| var_dump(file_get_contents($chain)); | ||
| } | ||
|
|
||
| echo "# include on 16 filters\n"; | ||
| $allowed_include = createFilterChains(16, 'php://temp'); | ||
| foreach ($allowed_include as $chain) { | ||
| var_dump(include $chain); | ||
| } | ||
|
|
||
| echo "# file_get_contents on 17 filters\n"; | ||
| $blocked_read = createFilterChains(17, 'data:text/plain,seventeen'); | ||
| foreach ($blocked_read as $chain) { | ||
| var_dump(file_get_contents($chain)); | ||
| } | ||
|
|
||
| echo "# include on 17 filters\n"; | ||
| $blocked_include = createFilterChains(17, 'php://temp'); | ||
| foreach ($blocked_include as $chain) { | ||
| var_dump(include $chain); | ||
| } | ||
|
|
||
| echo "# file_get_contents on 3 filters, max_filter_count=2\n"; | ||
| $ctx = stream_context_create(['filter' => ['max_filter_count' => 2]]); | ||
| $blocked_read = createFilterChains(3, 'data:text/plain,three'); | ||
| foreach ($blocked_read as $chain) { | ||
| var_dump(file_get_contents($chain, false, $ctx)); | ||
| } | ||
|
|
||
| echo "# file_get_contents on 19 filters, max_filter_count=20\n"; | ||
| $ctx = stream_context_create(['filter' => ['max_filter_count' => 20]]); | ||
| $allowed_read = createFilterChains(19, 'data:text/plain,nineteen'); | ||
| foreach ($allowed_read as $chain) { | ||
| var_dump(file_get_contents($chain, false, $ctx)); | ||
| } | ||
|
|
||
| echo "# warning is only given once, even when we add two filters over the limit\n"; | ||
| $blocked_read = createFilterChains(18, 'data:text/plain,eighteen'); | ||
| foreach ($blocked_read as $chain) { | ||
| var_dump(file_get_contents($chain)); | ||
| } | ||
|
|
||
| echo "# warn on too many write filters, even when number of read filters is OK\n"; | ||
| $filter = 'string.toupper'; | ||
| $write_filters = implode('|', array_fill(0, 16, $filter)); | ||
| $fp = fopen("php://filter/write=$write_filters/$filter/resource=php://temp", 'w+'); | ||
| var_dump(is_resource($fp)); | ||
|
|
||
| echo "# setting max_filter_count to -1 disables warning\n"; | ||
| $ctx = stream_context_create(['filter' => ['max_filter_count' => -1]]); | ||
| $allowed_read = createFilterChains(20, 'data:text/plain,twenty'); | ||
| foreach ($allowed_read as $chain) { | ||
| var_dump(file_get_contents($chain, false, $ctx)); | ||
| } | ||
|
|
||
| echo "# many filters with stream_filter_append still works\n"; | ||
| $fp = fopen('data:text/plain,stream_filter_append', 'r'); | ||
| for ($i = 0; $i < 80; $i++) { | ||
| stream_filter_append($fp, 'string.toupper'); | ||
| } | ||
| var_dump(fread($fp, 30)); | ||
| fclose($fp); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| # file_get_contents on 16 filters | ||
| string(7) "SIXTEEN" | ||
| string(7) "SIXTEEN" | ||
| string(7) "SIXTEEN" | ||
| # include on 16 filters | ||
| int(1) | ||
| int(1) | ||
| int(1) | ||
| # file_get_contents on 17 filters | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(9) "SEVENTEEN" | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(9) "SEVENTEEN" | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(9) "SEVENTEEN" | ||
| # include on 17 filters | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| int(1) | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| int(1) | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| int(1) | ||
| # file_get_contents on 3 filters, max_filter_count=2 | ||
|
|
||
| Warning: file_get_contents(): Failed to open stream: too many filters in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: file_get_contents(): Failed to open stream: too many filters in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: file_get_contents(): Failed to open stream: too many filters in %s on line %d | ||
| bool(false) | ||
| # file_get_contents on 19 filters, max_filter_count=20 | ||
| string(8) "NINETEEN" | ||
| string(8) "NINETEEN" | ||
| string(8) "NINETEEN" | ||
| # warning is only given once, even when we add two filters over the limit | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(8) "EIGHTEEN" | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(8) "EIGHTEEN" | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| string(8) "EIGHTEEN" | ||
| # warn on too many write filters, even when number of read filters is OK | ||
|
|
||
| Deprecated: Using more than 16 filters in a php://filter URL is deprecated, set this limit using the stream context option max_filter_count, or use stream_filter_append in %smax_filter_chain.php on line %d | ||
| bool(true) | ||
| # setting max_filter_count to -1 disables warning | ||
| string(6) "TWENTY" | ||
| string(6) "TWENTY" | ||
| string(6) "TWENTY" | ||
| # many filters with stream_filter_append still works | ||
| string(20) "STREAM_FILTER_APPEND" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.