fileinfo: built-in magic database php_magic_database is not aligned, breaks on strict-alignment CPUs (ARMv5, 32-bit)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #25030 de @lazerg — cerrado sin fusionar
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 73/100
Línea de trabajo
Empieza con ext/fileinfo/create_data_file.php y la declaración generada ext/fileinfo/data_file.c para php_magic_database. Comprueba cómo se usa ZEND_SET_ALIGNED para otras declaraciones; luego vuelve a generar el archivo de datos y verifica su alineación. El trabajo estará terminado cuando la base de datos magic integrada esté alineada y finfo_open() y mime_content_type() funcionen en compilaciones de ARM con alineación estricta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
The following code:
<?php
var_dump(mime_content_type('/tmp/file.zip'));
Resulted in this output:
ValueError: Path must not be empty.
But I expected this output instead:
application/zip
Description:
On ARMv5 (32-bit cpu), built with GCC and -Os, finfo_open() and mime_content_type() fail in PHP 8.5.x with:
ValueError: Path must not be empty.
Cause:
php_magic_database (ext/fileinfo/data_file.c) is declared as const unsigned char[][], so the compiler only guarantees 1-byte alignment.
libmagic apprentice_map() casts the buffer to uint32_t * to check MAGICNO/VERSIONNO, then uses it as an array of struct magic (8-byte aligned).
On CPUs that don't support unaligned access, the header reads back wrong and the built-in database is rejected.
libmagic then falls back to apprentice_load(NULL), which calls the stream layer with an empty path and throws the ValueError.
Whether the bug appears depends on where the linker places the symbol (nm shows an address that isn't a multiple of 4 or 8). GCC on ARM normally word-aligns large arrays, but not with -Os.
Fix: declare the array with ZEND_SET_ALIGNED(8, ...) in create_data_file.php and regenerate data_file.c
Since ext/fileinfo/create_data_file.php is generated I will not provide a patch for it, but this is the AI generated proposal:
-echo 'const unsigned char php_magic_database[' . count($chunks) . '][' . CHUNK_SIZE . "] ZEND_NONSTRING = {\n";
+/* libmagic accesses the database as uint32_t and struct magic, which need 8-byte alignment */
+echo 'ZEND_SET_ALIGNED(8, const unsigned char php_magic_database[' . count($chunks) . '][' . CHUNK_SIZE . "]) ZEND_NONSTRING = {\n";
My own patch to solve my problem: directly in data_file.c
--- php-8.5.12/ext/fileinfo/data_file.c 2026-10-28 16:30:57.011450103 +0100
+++ php-8.5.12.modified/ext/fileinfo/data_file.c 2026-10-28 16:22:31.851759910 +0100
@@ -3 +3 @@
-const unsigned char php_magic_database[10113][1024] ZEND_NONSTRING = {
+const unsigned char php_magic_database[10113][1024] ZEND_NONSTRING attribute((aligned(8))) = {
PHP Version
PHP 8.5.12 (cli) (built: Oct 28 2026 16:52:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Operating System
No response
- Lenguaje dominante
- C
- Estrellas
- 41.7k
- Forks
- 8.5k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 144
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de php/php-src
-
Windows CLI: get_ps_title() passes bytes to GetConsoleTitleW() instead of characters, overflowing the 260-wchar_t bufferPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 1 día
-
master: part of the mbstring bailout fix got lost in a mergePosiblemente ocupada @lazerg la tomó hace 9 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
quoted_printable_encode() produces lines longer than 76 characters for bytes 0xF5 to 0xFFPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
php/php-src#24196 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de php/php-src
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
elf_loader: Xtensa ignores the addend of R_XTENSA_GLOB_DAT / R_XTENSA_JMP_SLOT (C++ vtables)Posiblemente ocupada @diplfranzhoepfinger la tomó hoy. Abiertoelf_loader
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
espressif/esp-iot-solution#813 ·
Los mantenedores suelen responder en 1 día
-
Status: Opened Type: Bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día