diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 0daff31b37..2c818596c7 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -5235,47 +5235,47 @@ function wp_get_webp_info( $filename ) { return compact( 'width', 'height', 'type' ); } - try { - $handle = fopen( $filename, 'rb' ); - if ( $handle ) { - $magic = fread( $handle, 40 ); - fclose( $handle ); + $handle = fopen( $filename, 'rb' ); - // Make sure we got enough bytes. - if ( strlen( $magic ) < 40 ) { - return compact( 'width', 'height', 'type' ); - } + if ( false === $handle ) { + return compact( 'width', 'height', 'type' ); + } - // The headers are a little different for each of the three formats. - // Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container. - switch ( substr( $magic, 12, 4 ) ) { - // Lossy WebP. - case 'VP8 ': - $parts = unpack( 'v2', substr( $magic, 26, 4 ) ); - $width = (int) ( $parts[1] & 0x3FFF ); - $height = (int) ( $parts[2] & 0x3FFF ); - $type = 'lossy'; - break; - // Lossless WebP. - case 'VP8L': - $parts = unpack( 'C4', substr( $magic, 21, 4 ) ); - $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; - $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; - $type = 'lossless'; - break; - // Animated/alpha WebP. - case 'VP8X': - // Pad 24-bit int. - $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); - $width = (int) ( $width[1] & 0xFFFFFF ) + 1; - // Pad 24-bit int. - $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); - $height = (int) ( $height[1] & 0xFFFFFF ) + 1; - $type = 'animated-alpha'; - break; - } - } - } catch ( Exception $e ) { + $magic = fread( $handle, 40 ); + fclose( $handle ); + + // Make sure we got enough bytes. + if ( strlen( $magic ) < 40 ) { + return compact( 'width', 'height', 'type' ); + } + + // The headers are a little different for each of the three formats. + // Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container. + switch ( substr( $magic, 12, 4 ) ) { + // Lossy WebP. + case 'VP8 ': + $parts = unpack( 'v2', substr( $magic, 26, 4 ) ); + $width = (int) ( $parts[1] & 0x3FFF ); + $height = (int) ( $parts[2] & 0x3FFF ); + $type = 'lossy'; + break; + // Lossless WebP. + case 'VP8L': + $parts = unpack( 'C4', substr( $magic, 21, 4 ) ); + $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; + $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; + $type = 'lossless'; + break; + // Animated/alpha WebP. + case 'VP8X': + // Pad 24-bit int. + $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); + $width = (int) ( $width[1] & 0xFFFFFF ) + 1; + // Pad 24-bit int. + $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); + $height = (int) ( $height[1] & 0xFFFFFF ) + 1; + $type = 'animated-alpha'; + break; } return compact( 'width', 'height', 'type' );