php / php/php-src

Multi-Byte character breaks tempnam functionality

オープン
#16,845 コメント 8 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: standard Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

Hi all,

first of all thanks for all the development on PHP. Love the language more than ever. In a recent project I encountered this bug (?):

tempnam() shortens the given prefix after character 63. When passing a multi-byte character in this position, the shortened prefix contains a malformed character. MacOS does not seem to be able to handle that, hence no file is created and a notice is triggered. The PHP docs do not state, that multi-byte strings are not allowed with tempnam().

To reproduce
  1. Create a new folder
  2. Create script test.php in this folder and paste the following code into it:
<?php
// String concatenation only for highlighting the malicious character
$prefix = 'this_string_pushes_the_multi_byte_character_in_position_______' . 'ä' . 'foobar';
var_dump(tempnam(__DIR__, $prefix));
  1. Run php test.php in that directory.
Desired behaviour

It should create a temporary file in this folder and tempnam() should return the path to the file:

string(108) "/Users/benedict/dev/multibyte/this_string_pushes_the_multi_byte_character_in_position_______atWEta7"
Actual behaviour

On MacOS (tested with Sonoma 14.6.1 and Sequoia 15.1) no temporary file is created, a notice is triggered and tempnam() returns false:

PHP Notice:  tempnam(): file created in the system's temporary directory in /Users/benedict/dev/multibyte/test.php on line 16

Notice: tempnam(): file created in the system's temporary directory in /Users/benedict/dev/multibyte/test.php on line 16
bool(false)

When you change the ä in position 63 for anything but a multi-byte character, everything works as expected

If I can provide any further information, please let me know.

PHP Version

PHP 8.3.13

Operating System

MacOS Sonoma 14.6.1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

tempnam() のエントリーポイントから始め、macOS 上で test.php スクリプトと提供されたマルチバイトプレフィックスを使って動作を再現します。ä とシングルバイト文字について、63 文字のプレフィックス境界の扱いを比較します。tempnam() が要求されたフォルダーにファイルを作成し、notice なしでそのパスを返せば完了です。

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

評価

技術スタック
c, php
領域
backend, operating-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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