[php-src] PR #25799: Clamp negative CONTENT_LENGTH to 0 in CGI and FPM SAPIs
| From: | hohphu8 | Date: | Thu, 26 Nov 2026 19:22:20 +0000 |
| Subject: | [php-src] PR #25799: Clamp negative CONTENT_LENGTH to 0 in CGI and FPM SAPIs | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41074@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25799
Author: hohphu8
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