I18N: Cast magic MO marker number to integer.

In gettext, `0x950412de` is used to signal GNU MO files. In `WP_Translation_File_MO` this magic marker is used to detect whether a file uses little endian or big endian.

On 32 bit systems, this number will be interpreted by PHP as a float rather than an integer. This change adds extra casting to force an integer.

A similar change was done in the pomo library in the past, see #3780.

Props tmatsuur, swissspidy.
Fixes #60678.
Built from https://develop.svn.wordpress.org/trunk@57763


git-svn-id: http://core.svn.wordpress.org/trunk@57264 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-03-04 15:54:10 +00:00
parent f98a921c98
commit ce1eb78275
2 changed files with 16 additions and 4 deletions

View File

@ -66,11 +66,13 @@ class WP_Translation_File_MO extends WP_Translation_File {
return false;
}
if ( self::MAGIC_MARKER === $big ) {
// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
if ( (int) self::MAGIC_MARKER === $big ) {
return 'N';
}
if ( self::MAGIC_MARKER === $little ) {
// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
if ( (int) self::MAGIC_MARKER === $little ) {
return 'V';
}
@ -203,7 +205,17 @@ class WP_Translation_File_MO extends WP_Translation_File {
$hash_addr = $translations_addr + $bytes_for_entries;
$entry_offsets = $hash_addr;
$file_header = pack( $this->uint32 . '*', self::MAGIC_MARKER, 0 /* rev */, $entry_count, $originals_addr, $translations_addr, 0 /* hash_length */, $hash_addr );
$file_header = pack(
$this->uint32 . '*',
// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
(int) self::MAGIC_MARKER,
0, /* rev */
$entry_count,
$originals_addr,
$translations_addr,
0, /* hash_length */
$hash_addr
);
$o_entries = '';
$t_entries = '';

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-beta3-57762';
$wp_version = '6.5-beta3-57763';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.