Skip to content

Add WebP support to ext/exif#22213

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:feature/webp-exif
Open

Add WebP support to ext/exif#22213
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:feature/webp-exif

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Jun 2, 2026

WebP keeps EXIF metadata in a RIFF EXIF chunk whose payload is a raw TIFF block, the same bytes a JPEG carries after its APP1/Exif\0\0 marker, so exif_read_data() can read it by handing the chunk to the existing exif_process_TIFF_in_JPEG() parser, with no new dependency. Chunk scanning is bounded by the declared RIFF size, the EXIF chunk is accepted whether or not the VP8X extended-format flag is set, and an optional leading Exif\0\0 marker is tolerated. The phpinfo supported-filetypes line now lists what exif actually parses (it was missing HEIF too).

Exif Spec: https://developers.google.com/speed/webp/docs/riff_container

Fixes #19904

Comment thread ext/exif/exif.c

static bool exif_scan_WEBP_header(image_info_type *ImageInfo, size_t riff_size)
{
static const uchar ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a commment explaining this? As looking from the spec it's not immediately obvious why this is the corresponding Exif header? Or is this just {'E', 'X', 'I', 'F', 0, 0}? In which chase writting it that way would be more obvious. Not everyone knows ASCII by heart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment. It's the Exif\0\0 identifier code, the same array as in exif_process_APP1, so I kept the hex form to match it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, I can update both places to admittedly more clear {'E', 'X', 'I', 'F', 0, 0}, just doesn't make sense to do the same thing in 2 different ways (imho)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to do so in a follow-up PR to update both places.

Comment thread ext/exif/exif.c
Comment thread ext/exif/exif.c
WebP stores EXIF metadata in a RIFF "EXIF" chunk whose payload is a raw
TIFF block, the same data JPEG carries after its APP1 marker. Walk the
RIFF chunks, locate the EXIF chunk, and hand its payload to the existing
exif_process_TIFF_in_JPEG() parser, so no third-party library is needed.

The chunk is accepted regardless of the VP8X extended-format flag, and an
optional leading "Exif\0\0" marker is skipped when an encoder emits one.

Closes phpGH-19904
@iliaal iliaal force-pushed the feature/webp-exif branch from ba889cb to f7ed2c3 Compare June 5, 2026 11:51
Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit but LGTM.

Other thing that might be good to refactor is renaming the motorale_intel stuff to isLittleEndian or something to make it a bit clearer.

Comment thread ext/exif/exif.c
Comment on lines +4470 to +4478
char *data;
size_t skip = 0;
bool ret = false;

if (chunk_size < 8) {
return false;
}

data = emalloc(chunk_size);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
char *data;
size_t skip = 0;
bool ret = false;
if (chunk_size < 8) {
return false;
}
data = emalloc(chunk_size);
size_t skip = 0;
bool ret = false;
if (chunk_size < 8) {
return false;
}
char *data = emalloc(chunk_size);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebP format is not supported by exif

2 participants