From ce1eb78275825a0c5151c9c155ffbd5762b2b062 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 4 Mar 2024 15:54:10 +0000 Subject: [PATCH] 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 --- .../l10n/class-wp-translation-file-mo.php | 18 +++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/wp-includes/l10n/class-wp-translation-file-mo.php b/wp-includes/l10n/class-wp-translation-file-mo.php index bf39cc70ec..3f5e72597c 100644 --- a/wp-includes/l10n/class-wp-translation-file-mo.php +++ b/wp-includes/l10n/class-wp-translation-file-mo.php @@ -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 = ''; diff --git a/wp-includes/version.php b/wp-includes/version.php index a3fb020c15..5a3307ef98 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.