diff --git a/NEWS b/NEWS index f2dc4c3302b9..1906663dd895 100644 --- a/NEWS +++ b/NEWS @@ -66,6 +66,10 @@ PHP NEWS . Fixed a crash and a use-after-free in key() of an attribute or DTD named node map iterator that has no current item. (Ilia Alshanetsky) +- Exif: + . Fixed bug GH-25678 (exif_read_data() reports "Invalid WebP file" for a + valid WebP without an EXIF chunk). (Shane Rounce) + - Fileinfo: . Fixed bug GH-25051 (TrueType fonts detected as application/octet-stream since libmagic 5.48). (Weilin Du) diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 7ae86d869b49..f3443dbd3d53 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -4563,7 +4563,8 @@ static bool exif_scan_WEBP_header(image_info_type *ImageInfo, size_t riff_size) offset = payload_offset + chunk_size + (chunk_size & 1); } - return false; + /* Every chunk was well formed and none of them is EXIF: a valid WebP file without metadata. */ + return true; } /* {{{ exif_scan_FILE_header diff --git a/ext/exif/tests/webp_chunk_layouts.phpt b/ext/exif/tests/webp_chunk_layouts.phpt new file mode 100755 index 000000000000..c7f59fb3b177 --- /dev/null +++ b/ext/exif/tests/webp_chunk_layouts.phpt @@ -0,0 +1,73 @@ +--TEST-- +exif_read_data() on WebP files: no EXIF chunk, chunk padding and malformed layouts +--EXTENSIONS-- +exif +--INI-- +output_handler= +zlib.output_compression=0 +--FILE-- + webp([$image]), + 'no EXIF chunk, VP8X' => webp([$vp8x, $image]), + 'EXIF after image' => webp([$vp8x, $image, chunk('EXIF', $tiff)]), + 'EXIF with Exif header' => webp([$vp8x, $image, chunk('EXIF', "Exif\0\0" . $tiff)]), + 'EXIF after odd sized chunk' => webp([$vp8x, chunk('XMP ', 'abc'), $image, chunk('EXIF', $tiff)]), + 'RIFF size larger than file' => webp([$vp8x, $image, chunk('EXIF', $tiff)], 0x7fffffff), + 'truncated chunk' => substr(webp([$vp8x, $image, chunk('EXIF', $tiff)]), 0, -10), + 'RIFF size too small for EXIF' => webp([$vp8x, $image, chunk('EXIF', $tiff)], 40), + 'EXIF chunk too small' => webp([$vp8x, $image, chunk('EXIF', 'Exif')]), +]; + +$file = __DIR__ . '/exif_webp_layouts.webp'; +foreach ($cases as $name => $bytes) { + file_put_contents($file, $bytes); + echo $name, ":\n"; + $result = exif_read_data($file, null, true); + if ($result === false) { + echo " false\n"; + continue; + } + echo ' ', $result['FILE']['MimeType'], ' ', implode(',', array_keys($result)), + ' Orientation=', $result['IFD0']['Orientation'] ?? 'none', "\n"; +} +?> +--CLEAN-- + +--EXPECTF-- +no EXIF chunk: + image/webp FILE,COMPUTED Orientation=none +no EXIF chunk, VP8X: + image/webp FILE,COMPUTED Orientation=none +EXIF after image: + image/webp FILE,COMPUTED,IFD0 Orientation=6 +EXIF with Exif header: + image/webp FILE,COMPUTED,IFD0 Orientation=6 +EXIF after odd sized chunk: + image/webp FILE,COMPUTED,IFD0 Orientation=6 +RIFF size larger than file: + image/webp FILE,COMPUTED,IFD0 Orientation=6 +truncated chunk: + +Warning: exif_read_data(): Invalid WebP file in %s on line %d + false +RIFF size too small for EXIF: + image/webp FILE,COMPUTED Orientation=none +EXIF chunk too small: + +Warning: exif_read_data(): Invalid WebP file in %s on line %d + false \ No newline at end of file