Skip to content
Open
450 changes: 229 additions & 221 deletions src/wp-admin/includes/export.php

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/wp-includes/class-wp-token-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ static function ( array $a, array $b ): int {
foreach ( $groups[ $group ] as $group_word ) {
list( $word, $mapping ) = $group_word;

$word_length = pack( 'C', strlen( $word ) );
$mapping_length = pack( 'C', strlen( $mapping ) );
$word_length = chr( strlen( $word ) );
$mapping_length = chr( strlen( $mapping ) );
$group_string .= "{$word_length}{$word}{$mapping_length}{$mapping}";
}

Expand Down Expand Up @@ -472,10 +472,10 @@ public function contains( string $word, string $case_sensitivity = 'case-sensiti
$at = 0;

while ( $at < $group_length ) {
$token_length = unpack( 'C', $group[ $at++ ] )[1];
$token_length = ord( $group[ $at++ ] );
$token_at = $at;
$at += $token_length;
$mapping_length = unpack( 'C', $group[ $at++ ] )[1];
$mapping_length = ord( $group[ $at++ ] );
$mapping_at = $at;

if ( $token_length === $length && 0 === substr_compare( $group, $slug, $token_at, $token_length, $ignore_case ) ) {
Expand Down Expand Up @@ -559,10 +559,10 @@ public function read_token( string $text, int $offset = 0, &$matched_token_byte_
$group_length = strlen( $group );
$at = 0;
while ( $at < $group_length ) {
$token_length = unpack( 'C', $group[ $at++ ] )[1];
$token_length = ord( $group[ $at++ ] );
$token = substr( $group, $at, $token_length );
$at += $token_length;
$mapping_length = unpack( 'C', $group[ $at++ ] )[1];
$mapping_length = ord( $group[ $at++ ] );
$mapping_at = $at;

if ( 0 === substr_compare( $text, $token, $offset + $this->key_length, $token_length, $ignore_case ) ) {
Expand Down Expand Up @@ -666,11 +666,11 @@ public function to_array(): array {
$group_length = strlen( $group );
$at = 0;
while ( $at < $group_length ) {
$length = unpack( 'C', $group[ $at++ ] )[1];
$length = ord( $group[ $at++ ] );
$key = $prefix . substr( $group, $at, $length );

$at += $length;
$length = unpack( 'C', $group[ $at++ ] )[1];
$length = ord( $group[ $at++ ] );
$value = substr( $group, $at, $length );

$tokens[ $key ] = $value;
Expand Down Expand Up @@ -737,10 +737,10 @@ public function precomputed_php_source_table( string $indent = "\t" ): string {
$data_line = "{$i3}\"";
$at = 0;
while ( $at < $group_length ) {
$token_length = unpack( 'C', $group[ $at++ ] )[1];
$token_length = ord( $group[ $at++ ] );
$token = substr( $group, $at, $token_length );
$at += $token_length;
$mapping_length = unpack( 'C', $group[ $at++ ] )[1];
$mapping_length = ord( $group[ $at++ ] );
$mapping = substr( $group, $at, $mapping_length );
$at += $mapping_length;

Expand Down
76 changes: 51 additions & 25 deletions src/wp-includes/compat-utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,37 +506,63 @@ function _wp_utf8_decode_fallback( $utf8_text ) {
continue;
}

$next_at = $at;
$invalid_length = 0;
$found = _wp_scan_utf8( $utf8_text, $next_at, $invalid_length, null, 1 );
$span_length = $next_at - $at;
$span_length = 0;
$next_byte = '?';
$byte1 = ord( $utf8_text[ $at ] );
$byte2 = ord( $utf8_text[ $at + 1 ] ?? "\xC0" );
$byte3 = ord( $utf8_text[ $at + 2 ] ?? "\xC0" );
$byte4 = ord( $utf8_text[ $at + 3 ] ?? "\xC0" );

if ( $byte1 >= 0xC2 && $byte1 <= 0xDF && $byte2 >= 0x80 && $byte2 <= 0xBF ) {
$span_length = 2;
$code_point = ( ( $byte1 & 0x1F ) << 6 ) | ( $byte2 & 0x3F );
$next_byte = $code_point <= 0xFF ? chr( $code_point ) : '?';
} elseif (
$byte3 >= 0x80 && $byte3 <= 0xBF &&
(
( 0xE0 === $byte1 && $byte2 >= 0xA0 && $byte2 <= 0xBF ) ||
( $byte1 >= 0xE1 && $byte1 <= 0xEC && $byte2 >= 0x80 && $byte2 <= 0xBF ) ||
( 0xED === $byte1 && $byte2 >= 0x80 && $byte2 <= 0x9F ) ||
( $byte1 >= 0xEE && $byte1 <= 0xEF && $byte2 >= 0x80 && $byte2 <= 0xBF )
)
) {
$span_length = 3;
} elseif (
$byte3 >= 0x80 && $byte3 <= 0xBF &&
$byte4 >= 0x80 && $byte4 <= 0xBF &&
(
( 0xF0 === $byte1 && $byte2 >= 0x90 && $byte2 <= 0xBF ) ||
( $byte1 >= 0xF1 && $byte1 <= 0xF3 && $byte2 >= 0x80 && $byte2 <= 0xBF ) ||
( 0xF4 === $byte1 && $byte2 >= 0x80 && $byte2 <= 0x8F )
)
) {
$span_length = 4;
} else {
$next_byte = '';
$invalid_length = 1;

if ( 0xE0 === ( $byte1 & 0xF0 ) ) {
$byte2_valid = (
( 0xE0 === $byte1 && $byte2 >= 0xA0 && $byte2 <= 0xBF ) ||
( $byte1 >= 0xE1 && $byte1 <= 0xEC && $byte2 >= 0x80 && $byte2 <= 0xBF ) ||
( 0xED === $byte1 && $byte2 >= 0x80 && $byte2 <= 0x9F ) ||
( $byte1 >= 0xEE && $byte1 <= 0xEF && $byte2 >= 0x80 && $byte2 <= 0xBF )
);

if ( 1 !== $found ) {
if ( $invalid_length > 0 ) {
$next_byte = '';
goto flush_sub_part;
}

break;
}

// All convertible code points are two-bytes long.
$byte1 = ord( $utf8_text[ $at ] );
if ( 0xC0 !== ( $byte1 & 0xE0 ) ) {
goto flush_sub_part;
}
$invalid_length = min( $end - $at, $byte2_valid ? 2 : 1 );
} elseif ( 0xF0 === ( $byte1 & 0xF8 ) ) {
$byte2_valid = (
( 0xF0 === $byte1 && $byte2 >= 0x90 && $byte2 <= 0xBF ) ||
( $byte1 >= 0xF1 && $byte1 <= 0xF3 && $byte2 >= 0x80 && $byte2 <= 0xBF ) ||
( 0xF4 === $byte1 && $byte2 >= 0x80 && $byte2 <= 0x8F )
);
$byte3_valid = $byte3 >= 0x80 && $byte3 <= 0xBF;

// All convertible code points are not greater than U+FF.
$byte2 = ord( $utf8_text[ $at + 1 ] );
$code_point = ( ( $byte1 & 0x1F ) << 6 ) | ( ( $byte2 & 0x3F ) );
if ( $code_point > 0xFF ) {
goto flush_sub_part;
$invalid_length = min( $end - $at, $byte2_valid ? ( $byte3_valid ? 3 : 2 ) : 1 );
}
}

$next_byte = chr( $code_point );

flush_sub_part:
$iso_8859_1_text .= substr( $utf8_text, $was_at, $at - $was_at );
$iso_8859_1_text .= $next_byte;
$at += $span_length;
Expand Down
77 changes: 46 additions & 31 deletions src/wp-includes/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,56 @@ function _mb_ord( $string, $encoding = null ) {
return false;
}

$byte_length = 0;
$invalid_length = 0;
$found_count = _wp_scan_utf8( $string, $byte_length, $invalid_length, null, 1 );
$b0 = ord( $string[0] );

if ( 1 !== $found_count ) {
return false;
if ( $b0 <= 0x7F ) {
return $b0;
}

// These are valid code points, so no further validation is required.
$b0 = ord( $string[0] );
$b1 = ord( $string[1] ?? "\x00" );

switch ( $byte_length ) {
case 1:
return $b0;

case 2:
return (
( ( $b0 & 0x1F ) << 6 ) |
( ( ord( $string[1] ) & 0x3F ) )
);

case 3:
return (
( ( $b0 & 0x0F ) << 12 ) |
( ( ord( $string[1] ) & 0x3F ) << 6 ) |
( ( ord( $string[2] ) & 0x3F ) )
);

case 4:
return (
( ( $b0 & 0x07 ) << 18 ) |
( ( ord( $string[1] ) & 0x3F ) << 12 ) |
( ( ord( $string[2] ) & 0x3F ) << 6 ) |
( ( ord( $string[3] ) & 0x3F ) )
);
if ( $b0 >= 0xC2 && $b0 <= 0xDF && $b1 >= 0x80 && $b1 <= 0xBF ) {
return (
( ( $b0 & 0x1F ) << 6 ) |
( $b1 & 0x3F )
);
}

$b2 = ord( $string[2] ?? "\x00" );

if (
$b2 >= 0x80 && $b2 <= 0xBF &&
(
( 0xE0 === $b0 && $b1 >= 0xA0 && $b1 <= 0xBF ) ||
( $b0 >= 0xE1 && $b0 <= 0xEC && $b1 >= 0x80 && $b1 <= 0xBF ) ||
( 0xED === $b0 && $b1 >= 0x80 && $b1 <= 0x9F ) ||
( $b0 >= 0xEE && $b0 <= 0xEF && $b1 >= 0x80 && $b1 <= 0xBF )
)
) {
return (
( ( $b0 & 0x0F ) << 12 ) |
( ( $b1 & 0x3F ) << 6 ) |
( $b2 & 0x3F )
);
}

$b3 = ord( $string[3] ?? "\x00" );

if (
$b2 >= 0x80 && $b2 <= 0xBF &&
$b3 >= 0x80 && $b3 <= 0xBF &&
(
( 0xF0 === $b0 && $b1 >= 0x90 && $b1 <= 0xBF ) ||
( $b0 >= 0xF1 && $b0 <= 0xF3 && $b1 >= 0x80 && $b1 <= 0xBF ) ||
( 0xF4 === $b0 && $b1 >= 0x80 && $b1 <= 0x8F )
)
) {
return (
( ( $b0 & 0x07 ) << 18 ) |
( ( $b1 & 0x3F ) << 12 ) |
( ( $b2 & 0x3F ) << 6 ) |
( $b3 & 0x3F )
);
}

return false;
Expand Down
5 changes: 3 additions & 2 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -6593,7 +6593,9 @@ function wp_start_cross_origin_isolation_output_buffer(): void {

ob_start(
static function ( string $output ): string {
header( 'Document-Isolation-Policy: isolate-and-credentialless' );
if ( ! headers_sent() ) {
header( 'Document-Isolation-Policy: isolate-and-credentialless' );
}

return wp_add_crossorigin_attributes( $output );
}
Expand Down Expand Up @@ -6674,4 +6676,3 @@ function wp_add_crossorigin_attributes( string $html ): string {

return $processor->get_updated_html();
}

Loading
Loading