Make WordPress Core

Ticket #64767: 64767.patch

File 64767.patch, 6.6 KB (added by yasirkhalifa, 6 months ago)

patch file

  • wp-includes/l10n/class-wp-translation-file-mo.php

     
    1313 * @since 6.5.0
    1414 */
    1515class WP_Translation_File_MO extends WP_Translation_File {
     16
    1617        /**
    1718         * Endian value.
    1819         *
     
    3435        const MAGIC_MARKER = 0x950412de;
    3536
    3637        /**
     38         * Normalize unpacked uint32 values to integers.
     39         *
     40         * Prevents float-to-int cast warnings on PHP 8.5+.
     41         *
     42         * @param mixed $value Value from unpack().
     43         * @return int
     44         */
     45        private function normalize_uint32( $value ): int {
     46                return (int) ( $value & 0xFFFFFFFF );
     47        }
     48
     49        /**
    3750         * Detects endian and validates file.
    3851         *
    3952         * @since 6.5.0
     
    5467                        return false;
    5568                }
    5669
     70                $big = $this->normalize_uint32( $big );
     71
    5772                $little = unpack( 'V', $header );
    5873
    5974                if ( false === $little ) {
     
    6681                        return false;
    6782                }
    6883
     84                $little = $this->normalize_uint32( $little );
     85
    6986                // 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 ) {
     87                if ( self::MAGIC_MARKER === $big ) {
    7188                        return 'N';
    7289                }
    7390
    7491                // 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 ) {
     92                if ( self::MAGIC_MARKER === $little ) {
    7693                        return 'V';
    7794                }
    7895
     
    115132                        return false;
    116133                }
    117134
    118                 $offsets = unpack( "{$this->uint32}rev/{$this->uint32}total/{$this->uint32}originals_addr/{$this->uint32}translations_addr/{$this->uint32}hash_length/{$this->uint32}hash_addr", $offsets );
     135                $offsets = unpack(
     136                        "{$this->uint32}rev/{$this->uint32}total/{$this->uint32}originals_addr/{$this->uint32}translations_addr/{$this->uint32}hash_length/{$this->uint32}hash_addr",
     137                        $offsets
     138                );
    119139
    120140                if ( false === $offsets ) {
    121141                        return false;
    122142                }
    123143
     144                // Normalize all unpacked uint32 values to prevent PHP 8.5 float warnings.
     145                foreach ( $offsets as $key => $value ) {
     146                        $offsets[ $key ] = $this->normalize_uint32( $value );
     147                }
     148
    124149                $offsets['originals_length']    = $offsets['translations_addr'] - $offsets['originals_addr'];
    125150                $offsets['translations_length'] = $offsets['hash_addr'] - $offsets['translations_addr'];
    126151
     
    146171                                continue;
    147172                        }
    148173
     174                        // Normalize unpacked values.
     175                        $o['length'] = $this->normalize_uint32( $o['length'] );
     176                        $o['pos']    = $this->normalize_uint32( $o['pos'] );
     177                        $t['length'] = $this->normalize_uint32( $t['length'] );
     178                        $t['pos']    = $this->normalize_uint32( $t['pos'] );
     179
    149180                        $original    = substr( $file_contents, $o['pos'], $o['length'] );
    150181                        $translation = substr( $file_contents, $t['pos'], $t['length'] );
    151182                        // GlotPress bug.
     
    207238
    208239                $file_header = pack(
    209240                        $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.
    211241                        (int) self::MAGIC_MARKER,
    212242                        0, /* rev */
    213243                        $entry_count,
     
    236266
    237267                return $file_header . $o_addr . $t_addr . $o_entries . $t_entries;
    238268        }
    239 }
     269}
     270 No newline at end of file