Skip to content

Commit 6cf45c4

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix phpGH-20201: AVIF images misdetected as HEIF after introducing HEIF support in getimagesize()
2 parents 0df31e5 + 0b974dd commit 6cf45c4

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

ext/standard/image.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,15 +1435,16 @@ PHPAPI int php_getimagetype(php_stream *stream, const char *input, char *filetyp
14351435
return IMAGE_FILETYPE_JP2;
14361436
}
14371437

1438+
if (!php_stream_rewind(stream) && php_is_image_avif(stream)) {
1439+
return IMAGE_FILETYPE_AVIF;
1440+
}
1441+
1442+
/* See GH-20201: this needs to be after avif checks to avoid identifying avif as heif. */
14381443
if (twelve_bytes_read && !memcmp(filetype + 4, php_sig_ftyp, 4) &&
14391444
(!memcmp(filetype + 8, php_sig_mif1, 4) || !memcmp(filetype + 8, php_sig_heic, 4) || !memcmp(filetype + 8, php_sig_heix, 4))) {
14401445
return IMAGE_FILETYPE_HEIF;
14411446
}
14421447

1443-
if (!php_stream_rewind(stream) && php_is_image_avif(stream)) {
1444-
return IMAGE_FILETYPE_AVIF;
1445-
}
1446-
14471448
/* AFTER ALL ABOVE FAILED */
14481449
if (php_get_wbmp(stream, NULL, 1)) {
14491450
return IMAGE_FILETYPE_WBMP;
325 Bytes
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-20201 (AVIF images misdetected as HEIF after introducing HEIF support in getimagesize())
3+
--FILE--
4+
<?php
5+
var_dump(getimagesize(__DIR__ . '/gh20201.avif'));
6+
?>
7+
--EXPECT--
8+
array(9) {
9+
[0]=>
10+
int(8)
11+
[1]=>
12+
int(8)
13+
[2]=>
14+
int(19)
15+
[3]=>
16+
string(20) "width="8" height="8""
17+
["bits"]=>
18+
int(8)
19+
["channels"]=>
20+
int(3)
21+
["mime"]=>
22+
string(10) "image/avif"
23+
["width_unit"]=>
24+
string(2) "px"
25+
["height_unit"]=>
26+
string(2) "px"
27+
}

0 commit comments

Comments
 (0)