Multi-Byte character breaks tempnam functionality
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 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
- Create a new folder
- Create script
test.phpin 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));
- Run
php test.phpin 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 tempnam() 入口点开始,使用 test.php 脚本和提供的多字节前缀在 macOS 上复现该行为。比较 ä 和单字节字符在 63 个字符前缀边界上的处理方式;当 tempnam() 在请求的文件夹中创建文件并在不产生 notice 的情况下返回其路径时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend, operating-systems
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100