Make WordPress Core


Ignore:
Timestamp:
03/04/2024 03:52:04 PM (9 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n/class-wp-translation-file-mo.php

    r57513 r57763  
    6767        }
    6868
    69         if ( self::MAGIC_MARKER === $big ) {
     69        // Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
     70        if ( (int) self::MAGIC_MARKER === $big ) {
    7071            return 'N';
    7172        }
    7273
    73         if ( self::MAGIC_MARKER === $little ) {
     74        // Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
     75        if ( (int) self::MAGIC_MARKER === $little ) {
    7476            return 'V';
    7577        }
     
    204206        $entry_offsets     = $hash_addr;
    205207
    206         $file_header = pack( $this->uint32 . '*', self::MAGIC_MARKER, 0 /* rev */, $entry_count, $originals_addr, $translations_addr, 0 /* hash_length */, $hash_addr );
     208        $file_header = pack(
     209            $this->uint32 . '*',
     210            // Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
     211            (int) self::MAGIC_MARKER,
     212            0, /* rev */
     213            $entry_count,
     214            $originals_addr,
     215            $translations_addr,
     216            0, /* hash_length */
     217            $hash_addr
     218        );
    207219
    208220        $o_entries = '';
Note: See TracChangeset for help on using the changeset viewer.