Skip to content

Fix GH-24536: Built-in server crashes on a huge chunk size or Content-Length - #24543

Open
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix-gh-24536
Open

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix-gh-24536

Conversation

@lazerg

@lazerg lazerg commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The first on_body call pre-allocated parser->content_length bytes, which is whatever size the client declared. A chunk size of FFFFFFFFFFFFFFFF wraps to -1 and becomes a SIZE_MAX allocation, but a valid huge size like 7FFFFFFFFFFFFFFF or Content-Length: 9000000000000000000 kills the server the same way. The buffer was shrunk by the perealloc() right after anyway, so I dropped the pre-allocation and let perealloc() grow the buffer from NULL.

The parser now also rejects chunk sizes and Content-Length values that would overflow ssize_t, so they get a malformed request error instead of wrapping.

Fixes GH-24536

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