-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Open
Sjord
wants to merge
14
commits into
php:master
Choose a base branch
from
Sjord:limit_filters
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.
+193
−4
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7731252
Limit the number of filters
jvoisin a315900
Count number of filters, raise deprecation warning
af279cb
Error when max_filter_count is set and exceeded
20f4d64
Use zend_long consistently for filter count
e4ed866
Merge branch 'master' into limit_filters
7cd388b
Use new stream error API
175b1a9
Use zend_long consistently for filter count
0bda81d
Also warn when number of write filters is exceeded
Sjord fc96cf3
Stop adding filters when max_filter_count is reached
Sjord 88dc27e
Split test with headers that show what it's doing
Sjord adb9ef3
Keep count in php_stream_filter_chain
Sjord c133481
Use tabs instead of spaces as indentation
Sjord 4e033c1
Move option retrieval, handle negative max_filter_count
Sjord de3a9d1
Rename php_stream_filter_chain.count to num_filters
Sjord 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 |
|---|---|---|
| @@ -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(php://filter/string.toupper|string.toupper|string.toupper/resource=data:text/plain,three): Failed to open stream: too many filters in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: file_get_contents(php://filter/string.toupper/string.toupper/string.toupper/resource=data:text/plain,three): Failed to open stream: too many filters in %s on line %d | ||
| bool(false) | ||
|
|
||
| Warning: file_get_contents(php://filter/string.toupper/resource=php://filter/string.toupper/resource=php://filter/string.toupper/resource=data:text/plain,three): 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.