Repository navigation
Conversation
The new line/NUL check iterated over the size_t header length with a uint32_t index, which wraps around for header lines of 4 GiB or more, so the loop never ended. session_start() reaches this with a cookie path, domain or session id of that size. Use size_t for the index.
jorgsowa
reviewed
Oct 22, 2026
Use header() directly, as suggested in review, so the test does not depend on the session extension.
LamentXU123
approved these changes
Oct 22, 2026
LamentXU123
left a comment
Member
There was a problem hiding this comment.
LGTM. Can you add a NEWS entry?
Contributor
Author
|
Thanks, added a NEWS entry under Core. |
Member
|
AFAIK this is a SAPI fix so should be under SAPI? |
LamentXU123
added a commit
that referenced
this pull request
Oct 22, 2026
* PHP-8.6: Fix infinite loop in sapi_header_op() for headers of 4 GiB or more (#24540)
Member
|
Thanks! |
brainexe
pushed a commit
to brainexe/php-src
that referenced
this pull request
Oct 22, 2026
* PHP-8.4: Fix infinite loop in sapi_header_op() for headers of 4 GiB or more (php#24540)
brainexe
pushed a commit
to brainexe/php-src
that referenced
this pull request
Oct 22, 2026
* PHP-8.5: Fix infinite loop in sapi_header_op() for headers of 4 GiB or more (php#24540)
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.
The new line/NUL check in
sapi_header_op()walks the header line with auint32_tindex, butheader_line_lenis asize_t:For a header line of 4 GiB or more the index wraps around before it reaches the length, so the loop never ends and the request hangs, burning CPU until something kills it.
Any header of that size reaches the loop, for example
header('X-Foo: ' . str_repeat('a', 2**32) . "\nX-Bar: b"), and so doessession_start()with a cookie path, cookie domain or session id of 4 GiB or more (php_session_send_cookie()passes the fullsize_tlength tosapi_add_header_ex()). It can only be triggered by the script itself and needs a very large memory_limit, so this is a robustness fix, not a security one.Reproducer
Run with
php -n -d memory_limit=-1(needs about 17 GB of RAM).session_start()returns after about 9 s. With the 4 GiB + 16 byte path it is still spinning insapi_header_op()whentimeout 90kills it.session_start()returns after about 9 s in both cases.Fix
Use
size_tfor the index.Test
ext/standard/tests/general_functions/header_over_4gib.phptcallsheader()with a header line of 4 GiB followed by a new line and checks that the usual "new line detected" warning is raised. It needs more than 8 GB of RAM, so it follows the existing large-memory tests (e.g.ext/bz2/tests/gh20620.phpt): it only runs withRUN_RESOURCE_HEAVY_TESTSset, on 64-bit platforms, and not withSKIP_SLOW_TESTS.RUN_RESOURCE_HEAVY_TESTSit is skipped.ext/session/tests,tests/basicandsapi/cli/testspass (374 passed, 127 skipped, 1 expected fail, 0 failed).This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.
🤖 Generated with Claude Code