[php-src] PHP-8.5: Fix GH-23764: Built-in server leaks fd on HEAD request for static file

From: Date: Tue, 22 Sep 2026 15:42:10 +0000
Subject: [php-src] PHP-8.5: Fix GH-23764: Built-in server leaks fd on HEAD request for static file
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141443@lists.php.net to get a copy of this message
Author: Jakub Skopal (jakubskopal) Committer: ndossche (ndossche) Date: 2026-09-22T17:40:33+02:00 Commit: https://github.com/php/php-src/commit/abdcfc38b4a0faa96399fa0e53ff270d1f2e5fd3 Raw diff: https://github.com/php/php-src/commit/abdcfc38b4a0faa96399fa0e53ff270d1f2e5fd3.diff Fix GH-23764: Built-in server leaks fd on HEAD request for static file php_cli_server_begin_send_static() opens the file, but for HEAD requests never stores the descriptor in client->file_fd, so nothing closes it. Close it right away; Content-Length comes from the stat and the body is never sent, so the descriptor is not needed. Closes GH-23765. Changed paths: M NEWS M sapi/cli/php_cli_server.c Diff: diff --git a/NEWS b/NEWS index e7f45c810b23..4450776530c4 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - CLI . Fix GH-22567 (Windows ZTS CLI SAPI should refresh its TSRMLS cache during request activation). (matyhtf) + . Fixed bug GH-23764 (Built-in server leaks a file descriptor on every HEAD + request for a static file). (jakubskopal) - Core . Fix GH-21999: GC inconsistency with lazy object, var_dump(), and object diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 36187aaeb035..dcd3d4a7e04e 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -2185,6 +2185,11 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_ client->content_sender_initialized = true; if (client->request.request_method != PHP_HTTP_HEAD) { client->file_fd = fd; + } else { + /* Content-Length comes from the stat and no body is sent, so the fd is + not needed; it is still opened so HEAD gets the same 404 as GET on + an unreadable file. */ + close(fd); } {

« previous php.cvs (#141443) next »