From 472b7789d58f65dd7122d1217bbf1501c39fbe7f Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 19 Oct 2025 23:28:01 +0200 Subject: [PATCH] Fix GH-20201: AVIF images misdetected as HEIF after introducing HEIF support in getimagesize() --- ext/standard/image.c | 9 +++++---- ext/standard/tests/image/gh20201.avif | Bin 0 -> 325 bytes ext/standard/tests/image/gh20201.phpt | 27 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/image/gh20201.avif create mode 100644 ext/standard/tests/image/gh20201.phpt diff --git a/ext/standard/image.c b/ext/standard/image.c index 97dcc437c833e..4eadace55ec8c 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1435,15 +1435,16 @@ PHPAPI int php_getimagetype(php_stream *stream, const char *input, char *filetyp return IMAGE_FILETYPE_JP2; } + if (!php_stream_rewind(stream) && php_is_image_avif(stream)) { + return IMAGE_FILETYPE_AVIF; + } + + /* See GH-20201: this needs to be after avif checks to avoid identifying avif as heif. */ if (twelve_bytes_read && !memcmp(filetype + 4, php_sig_ftyp, 4) && (!memcmp(filetype + 8, php_sig_mif1, 4) || !memcmp(filetype + 8, php_sig_heic, 4) || !memcmp(filetype + 8, php_sig_heix, 4))) { return IMAGE_FILETYPE_HEIF; } - if (!php_stream_rewind(stream) && php_is_image_avif(stream)) { - return IMAGE_FILETYPE_AVIF; - } - /* AFTER ALL ABOVE FAILED */ if (php_get_wbmp(stream, NULL, 1)) { return IMAGE_FILETYPE_WBMP; diff --git a/ext/standard/tests/image/gh20201.avif b/ext/standard/tests/image/gh20201.avif new file mode 100644 index 0000000000000000000000000000000000000000..3cf1ffdec18187ff280f2ac86a82e634cf0bcc64 GIT binary patch literal 325 zcmZQzU{FXasVvCNOfzHvg2b}SG!Q#CGcnEA(a;en^g1`SBoQPB1d16cIYkgA14BV( zatVwLqxlLlOLD;+Mj$DdnUkLk;<+#|FajZnWMC8q(ndh6k(rs72Bg8F3{pT&Dif5K zSY}}8oS%~qwks>Mpr`;S;hkBKoDZZ$GK&jRK?;F@1BwL-GAlAc0?Zs7ATgfAGDGJ^ z1t5!oK{z=-rzkHurvhj@F9TZxP)IzpAQ$E*pu<=gnVMOE!dAH{i6ue|T&xxx`x7P@ vsf#(VNhG!~FwNT;prF3}uY=mYzB|X5-_6lTe{!BLb;s?C<(neqc0K_BJY7JN literal 0 HcmV?d00001 diff --git a/ext/standard/tests/image/gh20201.phpt b/ext/standard/tests/image/gh20201.phpt new file mode 100644 index 0000000000000..272eb1d8dd162 --- /dev/null +++ b/ext/standard/tests/image/gh20201.phpt @@ -0,0 +1,27 @@ +--TEST-- +GH-20201 (AVIF images misdetected as HEIF after introducing HEIF support in getimagesize()) +--FILE-- + +--EXPECT-- +array(9) { + [0]=> + int(8) + [1]=> + int(8) + [2]=> + int(19) + [3]=> + string(20) "width="8" height="8"" + ["bits"]=> + int(8) + ["channels"]=> + int(3) + ["mime"]=> + string(10) "image/avif" + ["width_unit"]=> + string(2) "px" + ["height_unit"]=> + string(2) "px" +}