Description
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.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));
- 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