[php-src] Issue #25009: Windows CLI: get_ps_title() passes bytes to GetConsoleTitleW() instead of characters, overflowing the 260-wchar_t buffer

From: Date: Wed, 28 Oct 2026 16:21:13 +0000
Subject: [php-src] Issue #25009: Windows CLI: get_ps_title() passes bytes to GetConsoleTitleW() instead of characters, overflowing the 260-wchar_t buffer
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253900@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25009 Author: apoc ### Description In sapi/cli/ps_title.c (~L407-436), wchar_t ps_buffer_w[MAX_PATH] is filled by GetConsoleTitleW(ps_buffer_w, (DWORD)sizeof(ps_buffer_w)). nSize is a count of characters, so 520 is passed for a buffer of 260 wchar_t; the API may write up to 1040 bytes. The clamp after the call acts on a different buffer. PHP itself rejects titles of 260+ characters in set_ps_title(), so the console title has to be set by another process on the same console. The following code (run from a console): ```python import ctypes, subprocess ctypes.windll.kernel32.SetConsoleTitleW("A" * 500) r = subprocess.run([r"C:\php\php.exe", "-r", "echo strlen(cli_get_process_title());"]) print(hex(r.returncode & 0xFFFFFFFF)) ``` Resulted in this output: ``` 0xC0000409 (STATUS_STACK_BUFFER_OVERRUN) ``` Title length 10 and 259 work; 260 prints 259; 500 aborts. But I expected this output instead: 259 (truncated title), no crash. Fix: GetConsoleTitleW(ps_buffer_w, (DWORD)_countof(ps_buffer_w)). Existing tests (cli_get_process_title_basic.phpt, cli_process_title_windows.phpt) only use short titles. ### PHP Version ``` PHP 8.7.0-dev (cli) (built: Oct 27 2026 17:51:17) (ZTS Visual C++ 2026 x64) Zend Engine v4.7.0-dev (master @ 0af8a091eec28513a6a0b758bcb10b430ba6c6de) ``` Affects PHP-8.4/8.5 by source inspection (not run there). ### Operating System Windows 11 x64

« previous php.bugs (#253900) next »