Skip to content

ext/session: reject non-numeric session.upload_progress.freq - #22579

Open
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:fix/session-upload-progress-freq-parsing
Open

ext/session: reject non-numeric session.upload_progress.freq#22579
jorgsowa wants to merge 3 commits into
php:masterfrom
jorgsowa:fix/session-upload-progress-freq-parsing

Conversation

@jorgsowa

@jorgsowajorgsowa commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

OnUpdateRfc1867Freq silently truncates trailing characters (e.g. "5 apples" becomes 5), the same parsing bug recently fixed for session.cookie_lifetime. Switch to is_numeric_string_ex() to validate the numeric portion strictly, still allowing the optional trailing "%" for percentage mode.

InputOld binary outputNew binary output
5"5""5"
5%"5%""5%"
5%" 5%" (raw, kept spaces)"5%" (normalized)
5% "5% " (raw)"5%" (normalized)
5 %"5 %" accepted silentlyRejected, warning shown
5 apples"5 apples" accepted silentlyRejected, warning shown
5 apples%"5 apples%" accepted silentlyRejected, warning shown
" " accepted silentlyRejected, warning shown
200%Rejected (same warning)Rejected (same warning)
-1Rejected (same warning)Rejected (same warning)

Comment threadext/session/session.c
int new_freq = ZEND_ATOL(ZSTR_VAL(new_value));
const char *str = ZSTR_VAL(new_value);
size_t len = ZSTR_LEN(new_value);
bool is_percentage = len > 0 && str[len - 1] == '%';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with trailing spaces? Not sure how our INI parser deals with those.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good input. Is there any ini helper for such values? I added a comparison table to the PR description and test cases to the branch for my suggested solution for trailing whitespaces.

OnUpdateRfc1867Freq used ZEND_ATOL(), which silently truncates
trailing garbage (e.g. "5 apples" becomes 5), the same parsing bug
recently fixed for session.cookie_lifetime. Switch to
is_numeric_string_ex() to validate the numeric portion strictly,
still allowing the optional trailing "%" for percentage mode.
Covers the "%"-suffixed form of session.upload_progress.freq, alongside
the plain-integer case added in rfc1867_invalid_settings_3.phpt.
….freq
Whitespace surrounding the whole value (leading, or trailing after an
optional "%") is tolerated, but whitespace between the number and the
"%" suffix (e.g. "5 %") is rejected rather than silently accepted.
The stored ini value is also normalized to a whitespace-free canonical
form so ini_get() no longer echoes back stray whitespace.
@jorgsowa
jorgsowaforce-pushed the fix/session-upload-progress-freq-parsing branch from 3e7229e to 3f78a89CompareJuly 4, 2026 22:02
@Girgias

Copy link
Copy Markdown
Member

I wonder if it doesn't make more sense to normalize all INI settings so they don't have trailing/leading whitespace. @arnaud-lb do you know if this would cause any issues?

@arnaud-lb

arnaud-lb commented Jul 6, 2026

Copy link
Copy Markdown
Member

@Girgias I think that it may corrupt some deliberate values.

It makes sense to strip leading/trailing whitespaces in ini files such as

foo = bar 

because the whitespaces are invisible and may be introduced by error.

But not in -d session.upload_progress.freq=' 5%' as it looks deliberate due to the quotes.

Edit: However, OnUpdateLong does it (via zend_ini_parse_quantity), so why not for numeric values at least.

Comment threadext/session/session.c
Comment on lines +888 to +898
if (is_percentage && numeric_len > 0 && php_session_is_ini_whitespace(str[numeric_len - 1])) {
php_error_docref(NULL, E_WARNING, "session.upload_progress.freq must be of type int");
return FAILURE;
}

zend_long new_freq = 0;
uint8_t type = is_numeric_string_ex(str, numeric_len, &new_freq, NULL, false, NULL, NULL);
if (type != IS_LONG) {
php_error_docref(NULL, E_WARNING, "session.upload_progress.freq must be of type int");
return FAILURE;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error messages are wrong, as the INI is not an int, it's an int followed by a % sign.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jorgsowa@Girgias@arnaud-lb