Fix $kAlphaStr in PHP libavifinfo implementation PHP strings do not behave exactly like C string literals. Fix for https://github.com/WordPress/wordpress-develop/pull/4612 Add more test cases in avifinfo_test.php. Change-Id: I00194cb141a860ac5547cc2238907e591cc24156
diff --git a/avifinfo.php b/avifinfo.php index 84a2e93..f4e9429 100644 --- a/avifinfo.php +++ b/avifinfo.php
@@ -444,7 +444,7 @@ } else if ( $box->type == 'auxC' ) { // See AV1 Image File Format (AVIF) 4 // at https://aomediacodec.github.io/av1-avif/#auxiliary-images - $kAlphaStr = "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; + $kAlphaStr = "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha\0"; $kAlphaStrLength = 44; // Includes terminating character. if ( $box->content_size >= $kAlphaStrLength ) { if ( !( $data = read( $this->handle, $kAlphaStrLength ) ) ) {
diff --git a/tests/avifinfo_test.php b/tests/avifinfo_test.php index 4b03f9c..cbdf49e 100644 --- a/tests/avifinfo_test.php +++ b/tests/avifinfo_test.php
@@ -15,21 +15,31 @@ require_once('../avifinfo.php'); -$features = array( 'width' => false, 'height' => false, - 'bit_depth' => false, 'num_channels' => false ); -$handle = fopen( 'avifinfo_test_1x1.avif', 'rb' ); -if ( $handle ) { - $parser = new Avifinfo\Parser( $handle ); - $success = $parser->parse_ftyp() && $parser->parse_file(); - fclose( $handle ); - if ( $success ) { - $features = $parser->features->primary_item_features; +function test_avifinfo_parser( $file_name, $expected_width, $expected_height, + $expected_bit_depth, $expected_num_channels ) { + $features = array( 'width' => false, 'height' => false, + 'bit_depth' => false, 'num_channels' => false ); + $handle = fopen( $file_name, 'rb' ); + if ( $handle ) { + $parser = new Avifinfo\Parser( $handle ); + $success = $parser->parse_ftyp() && $parser->parse_file(); + fclose( $handle ); + if ( $success ) { + $features = $parser->features->primary_item_features; + } + } + + if ( $features['width'] != $expected_width || + $features['height'] != $expected_height || + $features['bit_depth'] != $expected_bit_depth || + $features['num_channels'] != $expected_num_channels ) { + echo 'Failure: '.$file_name.PHP_EOL; + } else { + echo 'Success: '.$file_name.PHP_EOL; } } -if ( !$features['width'] || !$features['height'] || - !$features['bit_depth'] || !$features['num_channels'] ) { - echo 'Failure'.PHP_EOL; -} else { - echo 'Success'.PHP_EOL; -} +test_avifinfo_parser('avifinfo_test_1x1.avif', 1, 1, 8, 3); +test_avifinfo_parser('avifinfo_test_2x2_alpha.avif', 2, 2, 8, 4); +test_avifinfo_parser('avifinfo_test_1x1_10b_nopixi_metasize64b_mdatsize0.avif', + 1, 1, 10, 3);