Skip to content

Fix GH-25029: fileinfo built-in magic database is not aligned - #25030

Closed
lazerg wants to merge 3 commits into
php:PHP-8.4from
lazerg:fix/gh-25029-fileinfo-db-align
Closed

lazerg wants to merge 3 commits into
php:PHP-8.4from
lazerg:fix/gh-25029-fileinfo-db-align

Conversation

@lazerg

@lazerg lazerg commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

php_magic_database is a plain unsigned char array, so it only gets 1-byte alignment, but apprentice_map() reads it as uint32_t and then as an array of struct magic. On strict-alignment CPUs like ARMv5 the header check reads garbage, the built-in database is rejected and every finfo call fails. Cross-compiling for armv5te with -Os puts the array in a .rodata section with alignment 1 (at offset 3 in a small test object). This declares it with ZEND_SET_ALIGNED(8, ...) in create_data_file.php and in the generated data_file.c.

Fixes #25029

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

adapik pushed a commit to adapik/php-src that referenced this pull request Oct 30, 2026
* PHP-8.4:
  Fix phpGH-25029: Align the fileinfo built-in magic database (php#25030)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fileinfo: built-in magic database php_magic_database is not aligned, breaks on strict-alignment CPUs (ARMv5, 32-bit)

3 participants