-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add WebP support to ext/exif #22213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iliaal
wants to merge
1
commit into
php:master
Choose a base branch
from
iliaal:feature/webp-exif
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−1
Open
Add WebP support to ext/exif #22213
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -69,7 +69,7 @@ PHP_MINFO_FUNCTION(exif) | |||||||||||||||||||||||||||||||||||
| php_info_print_table_start(); | ||||||||||||||||||||||||||||||||||||
| php_info_print_table_row(2, "EXIF Support", "enabled"); | ||||||||||||||||||||||||||||||||||||
| php_info_print_table_row(2, "Supported EXIF Version", "0220"); | ||||||||||||||||||||||||||||||||||||
| php_info_print_table_row(2, "Supported filetypes", "JPEG, TIFF"); | ||||||||||||||||||||||||||||||||||||
| php_info_print_table_row(2, "Supported filetypes", "JPEG, TIFF, HEIF, WebP"); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (USE_MBSTRING) { | ||||||||||||||||||||||||||||||||||||
| php_info_print_table_row(2, "Multibyte decoding support using mbstring", "enabled"); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -4445,6 +4445,55 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf | |||||||||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| static bool exif_scan_WEBP_header(image_info_type *ImageInfo, size_t riff_size) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| /* "Exif\0\0" identifier code */ | ||||||||||||||||||||||||||||||||||||
| static const uchar ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; | ||||||||||||||||||||||||||||||||||||
| unsigned char chunk_header[8]; | ||||||||||||||||||||||||||||||||||||
| size_t offset = 12; | ||||||||||||||||||||||||||||||||||||
| size_t riff_end = riff_size <= ImageInfo->FileSize - 8 ? riff_size + 8 : ImageInfo->FileSize; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| while (offset + 8 <= riff_end) { | ||||||||||||||||||||||||||||||||||||
| if ((php_stream_seek(ImageInfo->infile, offset, SEEK_SET) < 0) || | ||||||||||||||||||||||||||||||||||||
| (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)chunk_header, 8) != 8)) { | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| size_t chunk_size = php_ifd_get32u(chunk_header + 4, 0); | ||||||||||||||||||||||||||||||||||||
| size_t payload_offset = offset + 8; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (chunk_size > riff_end - payload_offset) { | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!memcmp(chunk_header, "EXIF", 4)) { | ||||||||||||||||||||||||||||||||||||
| char *data; | ||||||||||||||||||||||||||||||||||||
| size_t skip = 0; | ||||||||||||||||||||||||||||||||||||
| bool ret = false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (chunk_size < 8) { | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| data = emalloc(chunk_size); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4470
to
+4478
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| if (exif_read_from_stream_file_looped(ImageInfo->infile, data, chunk_size) == chunk_size) { | ||||||||||||||||||||||||||||||||||||
| if (chunk_size >= sizeof(ExifHeader) + 8 && !memcmp(data, ExifHeader, sizeof(ExifHeader))) { | ||||||||||||||||||||||||||||||||||||
| skip = sizeof(ExifHeader); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| exif_process_TIFF_in_JPEG(ImageInfo, data + skip, chunk_size - skip, payload_offset + skip); | ||||||||||||||||||||||||||||||||||||
| ret = true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| efree(data); | ||||||||||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /* RIFF chunks are word-aligned: an odd payload is followed by a pad byte. */ | ||||||||||||||||||||||||||||||||||||
| offset = payload_offset + chunk_size + (chunk_size & 1); | ||||||||||||||||||||||||||||||||||||
|
Girgias marked this conversation as resolved.
Girgias marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /* {{{ exif_scan_FILE_header | ||||||||||||||||||||||||||||||||||||
| * Parse the marker stream until SOS or EOI is seen; */ | ||||||||||||||||||||||||||||||||||||
| static bool exif_scan_FILE_header(image_info_type *ImageInfo) | ||||||||||||||||||||||||||||||||||||
|
|
@@ -4521,6 +4570,17 @@ static bool exif_scan_FILE_header(image_info_type *ImageInfo) | |||||||||||||||||||||||||||||||||||
| exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid HEIF file"); | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } else if ((ImageInfo->FileSize >= 16) && | ||||||||||||||||||||||||||||||||||||
| (!memcmp(file_header, "RIFF", 4)) && | ||||||||||||||||||||||||||||||||||||
| (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)(file_header + 8), 4) == 4) && | ||||||||||||||||||||||||||||||||||||
| (!memcmp(file_header + 8, "WEBP", 4))) { | ||||||||||||||||||||||||||||||||||||
| if (exif_scan_WEBP_header(ImageInfo, php_ifd_get32u(file_header + 4, 0))) { | ||||||||||||||||||||||||||||||||||||
| ImageInfo->FileType = IMAGE_FILETYPE_WEBP; | ||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid WebP file"); | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File not supported"); | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --TEST-- | ||
| GH-19904 (exif_read_data() reads EXIF metadata from WebP images) | ||
| --EXTENSIONS-- | ||
| exif | ||
| --INI-- | ||
| output_handler= | ||
| zlib.output_compression=0 | ||
| --FILE-- | ||
| <?php | ||
| var_dump(exif_read_data(__DIR__.'/gh19904.webp')); | ||
| ?> | ||
| --EXPECTF-- | ||
| array(26) { | ||
| ["FileName"]=> | ||
| string(12) "gh19904.webp" | ||
| ["FileDateTime"]=> | ||
| int(%d) | ||
| ["FileSize"]=> | ||
| int(526) | ||
| ["FileType"]=> | ||
| int(18) | ||
| ["MimeType"]=> | ||
| string(10) "image/webp" | ||
| ["SectionsFound"]=> | ||
| string(24) "ANY_TAG, IFD0, EXIF, GPS" | ||
| ["COMPUTED"]=> | ||
| array(4) { | ||
| ["IsColor"]=> | ||
| int(0) | ||
| ["ByteOrderMotorola"]=> | ||
| int(0) | ||
| ["UserComment"]=> | ||
| string(17) "Created with GIMP" | ||
| ["UserCommentEncoding"]=> | ||
| string(9) "UNDEFINED" | ||
| } | ||
| ["ImageWidth"]=> | ||
| int(100) | ||
| ["ImageLength"]=> | ||
| int(100) | ||
| ["BitsPerSample"]=> | ||
| array(3) { | ||
| [0]=> | ||
| int(8) | ||
| [1]=> | ||
| int(8) | ||
| [2]=> | ||
| int(8) | ||
| } | ||
| ["ImageDescription"]=> | ||
| string(17) "Created with GIMP" | ||
| ["XResolution"]=> | ||
| string(5) "300/1" | ||
| ["YResolution"]=> | ||
| string(5) "300/1" | ||
| ["ResolutionUnit"]=> | ||
| int(2) | ||
| ["Software"]=> | ||
| string(10) "GIMP 3.0.4" | ||
| ["DateTime"]=> | ||
| string(19) "2025:09:21 15:30:30" | ||
| ["Exif_IFD_Pointer"]=> | ||
| int(250) | ||
| ["GPS_IFD_Pointer"]=> | ||
| int(430) | ||
| ["DateTimeOriginal"]=> | ||
| string(19) "2025:09:21 15:29:27" | ||
| ["DateTimeDigitized"]=> | ||
| string(19) "2025:09:21 15:29:27" | ||
| ["OffsetTime"]=> | ||
| string(6) "+02:00" | ||
| ["OffsetTimeOriginal"]=> | ||
| string(6) "+02:00" | ||
| ["OffsetTimeDigitized"]=> | ||
| string(6) "+02:00" | ||
| ["UserComment"]=> | ||
| string(25) "%sCreated with GIMP" | ||
| ["ColorSpace"]=> | ||
| int(1) | ||
| ["GPSAltitude"]=> | ||
| string(5) "0/100" | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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\0identifier code, the same array as inexif_process_APP1, so I kept the hex form to match it.There was a problem hiding this comment.
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)There was a problem hiding this comment.
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.