Skip to content

exif_read_data() reports "Invalid WebP file" for a valid WebP without an EXIF chunk #25678

Open

Description

@AceMedia

Description

exif_read_data() on a well formed WebP file that has no EXIF chunk emits a warning and returns false. A JPEG without EXIF returns the FILE and COMPUTED sections and no warning.

<?php
function chunk(string $id, string $data): string {
    return $id . pack('V', strlen($data)) . $data . (strlen($data) & 1 ? "\0" : '');
}
$image = chunk('VP8L', "/\0\0\0\0\0\0\0\0\0");
$body = 'WEBP' . $image;
file_put_contents('/tmp/no-exif.webp', 'RIFF' . pack('V', strlen($body)) . $body);

var_dump(exif_read_data('/tmp/no-exif.webp', null, true));
var_dump(array_keys(exif_read_data('ext/standard/tests/image/test1pix.jpg', null, true)));

Resulting output for the WebP:

Warning: exif_read_data(): Invalid WebP file in ... on line ...
bool(false)

Expected: FILE and COMPUTED sections with MimeType image/webp, as for the JPEG (["FILE", "COMPUTED"]). Truncated or oversized chunks should keep returning false.

exif_scan_WEBP_header() returns false when it reaches the end of the chunk list without finding an EXIF chunk. I found it on PHP-8.6 at 1be37f6 while checking WebP metadata handling for WordPress uploads. WordPress suppresses the warning, but other callers will log it.

PHP Version: PHP-8.6 branch (also master)

Operating System: Ubuntu 24.04 (WSL2), x86-64

Disclosure: I used an LLM to help investigate this and to draft this report. I reviewed the reproduction and results myself.

Activity

  1. desrosj commented on Nov 23, 2026

    @desrosj

    Just noting that the same is true for HEIF files as well.

    If a warning is desired, then JPEG and TIFF should also be changed for consistency. However, I think it makes more sense for invalid file warnings to only be triggered when a file is actually malformed/invalid.

  2. AceMedia commented on Nov 23, 2026

    @AceMedia
    Author

    Thanks @desrosj, I checked HEIF and you are right, it behaves the same way. On the PHP-8.6 branch tip (1be37f6, NTS, Linux x86-64 under WSL2) I took ext/exif/tests/image029.heic, which parses normally (53 keys), and changed the infe entry for its Exif item to a different four-character item type. That leaves a well-formed HEIC with no Exif item. exif_read_data() then emits Warning: exif_read_data(): Invalid HEIF file and returns false.

    The cause looks like the WebP one. exif_scan_HEIF_header() returns true only after an Exif item has been found and read, so a file with no Exif item falls through to return false and the caller reports "Invalid HEIF file". For comparison, a JPEG with a scan header and no EXIF data, and a TIFF with an empty IFD, both return an array of 7 keys with no warning on the same build.

    I agree that the warning should be kept for files that are actually malformed. For HEIF, exif_isobmff_parse_meta() returns nothing and stops silently on truncated data, so the scanner cannot currently tell "no Exif item" from "damaged meta box". A fix would need that function to report which case it hit. I have not written one, and PR #25679 only changes WebP.

    Caveat: the test file is a real HEIC with one item retyped, not an untouched file from a camera or phone. I have not tested AVIF or any other ISO base media file.

    Disclosure: I used an LLM to help run these checks and to draft this comment. I reviewed the results before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions