Repository navigation
Conversation
add_post_vars() checked the max_input_vars limit only after add_post_var() had already registered the variable, so an application/x-www-form-urlencoded body with more than max_input_vars variables produced max_input_vars + 1 entries in $_POST (1001 with the default setting). The GET, cookie and multipart/form-data paths stop at exactly max_input_vars. Skip registering the variable once the limit has been reached; the warning is emitted at the same point as before.
Contributor
|
I checked this with and without the patch. Without it, 6 vars at max_input_vars=5 land 6 entries in $_POST. With the patch it caps at 5, same as GET and multipart. The loop still terminates at the limit. LGTM. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An
application/x-www-form-urlencodedPOST body with more thanmax_input_varsvariables putsmax_input_vars + 1entries into$_POST. GET, cookies andmultipart/form-datastop at exactlymax_input_vars.Reproducer
php-cgi,
max_input_vars=1000, with 1001 variables each in the query string, theCookieheader and the urlencoded body:The same count shows up in #20456 ("Total test values: 1001").
Cause
add_post_vars()checks the limit only afteradd_post_var()has already registered the variable:php_default_treat_data()(GET/cookies) andrfc1867.ccheck the count before registering.Fix
add_post_vars()passesvars->cnt < max_varstoadd_post_var(). Once the limit has been reached,add_post_var()still reports that a variable is present but does not register it. The warning text and the point where parsing stops do not change. With the fix the output above becomesGET=1000 POST=1000 COOKIE=1000. A body of exactly 1000 variables still gives 1000 entries and no warning, andmax_input_vars=0now gives 0 entries for POST, as it already did for GET.Tests
tests/basic/max_input_vars_post_urlencoded.phpt(max_input_vars=5, 6 POST variables): before the fix$_POSThas 6 entries and the test fails; with the fix it has 5 and the test passes.tests/basic,ext/standard/tests/http(includingrequest_parse_body),sapi/cgi/tests,sapi/cli/tests: 277 passed, 68 skipped, 0 failed.Zend/tests/oom_request_parsing.phptalso passes. (Non-debug--disable-all --enable-cli --enable-cgibuild.)This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.