diff --git a/includes/media/WebPHandler.php b/includes/media/WebPHandler.php index 1e6e0cbd22a..f0993996df5 100644 --- a/includes/media/WebPHandler.php +++ b/includes/media/WebPHandler.php @@ -277,13 +277,13 @@ class WebPHandler extends BitmapHandler { return []; } // Bytes 9-12 contain the image size - // Bits 0-13 are width-1; bits 15-27 are height-1 + // Bits 0-13 are width-1; bits 14-27 are height-1 $imageSize = unpack( 'C4', substr( $header, 9, 4 ) ); return [ 'compression' => 'lossless', 'width' => ( $imageSize[1] | ( ( $imageSize[2] & 0x3F ) << 8 ) ) + 1, 'height' => ( ( ( $imageSize[2] & 0xC0 ) >> 6 ) | - ( $imageSize[3] << 2 ) | ( ( $imageSize[4] & 0x03 ) << 10 ) ) + 1 + ( $imageSize[3] << 2 ) | ( ( $imageSize[4] & 0x0F ) << 10 ) ) + 1 ]; } diff --git a/tests/phpunit/data/media/webp_ll_large.webp b/tests/phpunit/data/media/webp_ll_large.webp new file mode 100644 index 00000000000..4fcfa534623 Binary files /dev/null and b/tests/phpunit/data/media/webp_ll_large.webp differ diff --git a/tests/phpunit/includes/media/WebPHandlerTest.php b/tests/phpunit/includes/media/WebPHandlerTest.php index a75d8904239..10f5e387167 100644 --- a/tests/phpunit/includes/media/WebPHandlerTest.php +++ b/tests/phpunit/includes/media/WebPHandlerTest.php @@ -284,6 +284,22 @@ class WebPHandlerTest extends MediaWikiIntegrationTestCase { ] ] ], + // Lossless red square at max resolution to confirm height decoding + [ + __DIR__ . '/../../data/media/webp_ll_large.webp', + [ + 'width' => 16383, + 'height' => 16383, + 'metadata' => [ + 'compression' => 'lossless', + 'width' => 16383, + 'height' => 16383, + 'metadata' => [ + '_MW_WEBP_VERSION' => 2, + ], + ], + ] + ], // Error cases [