Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Windows CLI: get_ps_title() passes bytes to GetConsoleTitleW() instead of characters, overflowing the 260-wchar_t buffer

オープン 初心者向け
#25,009 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@lazerg がすでに取り組んでいます。

2026年10月28日 から。

  • #25011 @lazerg による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
79/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c

調査の方向性

sapi/cli/ps_title.cの407~436行付近にあるGetConsoleTitleW()の呼び出しを読み、バッファ長がどのように渡されているかを確認してください。まず、現在は短いタイトルを対象としているcli_get_process_title_basic.phptとcli_process_title_windows.phptを確認してください。APIにバッファ容量が文字数で渡され、長いコンソールタイトルがWindowsでクラッシュせずに切り詰められれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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):

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

主要言語
C
スター
41.7k
フォーク
8.5k
平均マージ
2日 10時間
マージ済み PR(30日)
158

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。