php / php/php-src

Multi-Byte character breaks tempnam functionality

Abierto
#16,845 8 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Extension: standard Feature Status: Needs Triage
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.1k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el punto de entrada tempnam() y reproduce el comportamiento usando el script test.php y el prefijo multibyte proporcionado en macOS. Compara el tratamiento del límite de prefijo de 63 caracteres para ä y los caracteres de un solo byte; se considera terminado cuando tempnam() crea el archivo en la carpeta solicitada y devuelve su ruta sin un notice.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, php
Área
backend, operating-systems
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.