Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file added ext/standard/tests/image/gh20201.avif
Binary file not shown.
27 changes: 27 additions & 0 deletions ext/standard/tests/image/gh20201.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-20201 (AVIF images misdetected as HEIF after introducing HEIF support in getimagesize())
--FILE--
<?php
var_dump(getimagesize(__DIR__ . '/gh20201.avif'));
?>
--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"
}