Skip to content

AVIF images misdetected as HEIF after introducing HEIF support in getimagesize() #20201

@andypost

Description

@andypost

Description

After commit dfac2da PHP incorrectly detects certain AVIF files as HEIF.

The issue arises because both formats use the same ISOBMFF (.heif) container and share the mif1 major brand.
Current PHP logic checks only the major_brand and stops, even when the compatible_brands list includes avif.

Example test file header:

size: 0x0000001C
boxtype: 'ftyp'
major_brand: 'mif1'
minor_version: 0
compatible_brands: ['mif1', 'avif', 'miaf']

PHP currently classifies this as IMAGE_FILETYPE_HEIF, though it is an AVIF image.

Expected result:
Files that include 'avif' in compatible_brands should be recognized as IMAGE_FILETYPE_AVIF.

Actual result:
They are recognized as IMAGE_FILETYPE_HEIF.

Environment:

- PHP 8.3.x / 8.4.x
- GD enabled (bundled)
- libavif < 1.2.0 (no experimental HEIF support)
- Ubuntu Noble / Debian Testing
$file = 'test.avif';
$info = getimagesize($file);
var_dump($info[2]); // Expected IMAGETYPE_AVIF, got IMAGETYPE_HEIF

before 8.5 it returns int(19) but on 8.5 int(20)

Possible fix:
When parsing ftyp, prefer avif if it appears in compatible_brands, or parse all compatible brands before deciding on type.

Related references:

PHP Version

PHP 8.5.0RC2 (cli) (built: Oct  8 2025 09:46:31) (NTS)
Copyright (c) The PHP Group
Built by Alpine Linux aports
Zend Engine v4.5.0RC2, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.0RC2, Copyright (c), by Zend Technologies

Operating System

Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions