Skip to content

Clamp negative CONTENT_LENGTH to 0 in CGI and FPM SAPIs - #25799

Open
hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-cgi-fpm-negative-content-length
Open

hohphu8 wants to merge 1 commit into
php:PHP-8.4from
hohphu8:fix-cgi-fpm-negative-content-length

Conversation

@hohphu8

@hohphu8 hohphu8 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

In init_request_info() (sapi/cgi/cgi_main.c and sapi/fpm/fpm/fpm_main.c), SG(request_info).content_length is set directly from atol(content_length) without rejecting negative values. When CONTENT_LENGTH is negative (e.g. -1), debug builds abort on a ZEND_ASSERT in main/SAPI.c, while release builds skip the post_max_size check and convert -1 to size_t, reading stdin into php://input and $_POST.

This parses CONTENT_LENGTH with ZEND_ATOL() and clamps values <= 0 to 0 in both CGI and FPM.

Adds sapi/cgi/tests/negative_content_length.phpt checking that CONTENT_LENGTH=-1 exits cleanly with empty php://input and $_POST. Verified FAIL/CRASH -> PASS on PHP-8.4 (Debug + ZTS, building both php-cgi and php-fpm) and release builds, with sapi/cgi/tests/ passing.

I identified this via LLM-assisted source inspection and manually verified it

Sign up for free to 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.

1 participant