Make WordPress Core

Opened 7 weeks ago

Closed 4 weeks ago

#62272 closed defect (bug) (fixed)

Error when uploading .heic image

Reported by: azaozz's profile azaozz Owned by: azaozz's profile azaozz
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.7
Component: Media Keywords: has-patch dev-reviewed
Focuses: Cc:

Description

When trying to upload a .heic image (both in the media library and the editor) the upload may fail with a "Sorry, you are not allowed to upload this file type." error message.

Seems caused by an image with .heic file extension that is reported as having mime type of image/heif by finfo_file().

Attachments (3)

test2.heic (872.8 KB) - added by adamsilverstein 6 weeks ago.
reports mime type of image/heif-sequence
sample1.heic (286.7 KB) - added by debarghyabanerjee 6 weeks ago.
returns mime-type of image/heif
starfield_animation.heic (372.4 KB) - added by ironprogrammer 6 weeks ago.
$ file --mime-type starfield_animation.heic --> image/heif-sequence

Download all attachments as: .zip

Change History (38)

#1 follow-up: @azaozz
7 weeks ago

The error seems to be in wp_check_filetype_and_ext(). It uses finfo_file() to get the $real_mime which is returned as image/heif. However that mime type is treated as unsupported, only image/heic is supported.

Seems the fix can be as easy as mapping image/heif to image/heic in wp_check_filetype_and_ext(). However wondering if adding image/heif to the supported image mime types may be a better idea?

Version 0, edited 7 weeks ago by azaozz (next)

#3 @picard102
7 weeks ago

HEIF/HEIC image format support from browsers is spotty right now, so it would need to be converted to a jpg or webp format before the user could use it.

#4 @swissspidy
6 weeks ago

  • Keywords needs-patch added

If you‘re not aware, WordPress is doing such conversion already, see https://make.wordpress.org/core/2024/08/15/automatic-conversion-of-heic-images-to-jpeg-in-wordpress-6-7/. This ticket is about a small big in that implementation

Checking for image/heif makes. I thought I had previously flagged this, so probably an oversight. cc @adamsilverstein

#5 in reply to: ↑ 1 @adamsilverstein
6 weeks ago

Replying to azaozz:

Seems the fix can be as easy as mapping image/heif to image/heic in wp_check_filetype_and_ext():

That works

However wondering if adding image/heif to the supported image mime types may be a better idea?

Yes, lets go ahead and add it.

I can work on a patch.

#6 @adamsilverstein
6 weeks ago

Seems caused by an image with .heic file extension that is reported as having mime type of image/heif by finfo_file().

Do we have a sample image of this type? Would be useful for testing.

@adamsilverstein
6 weeks ago

reports mime type of image/heif-sequence

#7 follow-up: @adamsilverstein
6 weeks ago

I haven't been able to find any image files with a mime type of image/heif to test with. Any chance you can share what you were testing with @azaozz?

Part of the reason we decided not to add the complexity of heif support was that this file type seems rare or largely unused.

@debarghyabanerjee
6 weeks ago

returns mime-type of image/heif

#8 in reply to: ↑ 7 @azaozz
6 weeks ago

Replying to adamsilverstein:

I haven't been able to find any image files with a mime type of image/heif to test with.

I don't have an iPhone so downloaded few free test images some time ago. Thanks @debarghyabanerjee for uploading that image, seems it's the same as one of the images I tested with.

Part of the reason we decided not to add the complexity of heif support was that this file type seems rare or largely unused.
...
reports mime type of image/heif-sequence

Yea I was surprised to see it too, but seems better to "cover all the bases" just in case. Seems WP should probably support image/heic, image/heic-sequence, image/heif, image/heif-sequence: https://www.iana.org/assignments/media-types/media-types.xhtml#image.

#9 follow-up: @swissspidy
6 weeks ago

The *-sequence ones are for "live photos" with multiple frames, those would need extra testing for the JPEG conversion. I might have some test images somewhere.

#10 in reply to: ↑ 9 @azaozz
6 weeks ago

Replying to swissspidy:

The *-sequence ones are for "live photos" with multiple frames

Yea, these seem really rare, and I'm unsure how ImageMagick would handle them. But the mime types exist and seems there's no reason to block uploading even if they cannot be converted.

@ironprogrammer
6 weeks ago

$ file --mime-type starfield_animation.heic --> image/heif-sequence

#11 @ironprogrammer
6 weeks ago

Other sample HEIF images of various flavors can be pulled from https://nokiatech.github.io/heif/examples.html.

Regarding iOS Live Photos, after syncing and exporting as "unmodified" out of the Photos app, it yielded separate .heic (image/heic) and .mov files, rather than a HEIC sequence. If they are, in fact, stored on-device as sequences, I'm unsure what "photo to web" workflow to use (I had set the iOS Photos transfer setting to keep original format). Happy to test if anybody has an alternate suggestion.

Additionally, in my iOS image burst test, once exported, they are individual JPEGs, not a sequence file. Same as above, I'm unsure what workflow would yield a single sequence file.

#12 @azaozz
6 weeks ago

Started on a patch. Seems there are few irregularities here :)
There may be four file extensions corresponding to the four mime types: .heic, .heif, .heics, and .heifs. However wasn't able to find any samples with .heics and .heifs extensions. On the opposite, the samples of animated images were all with .heic extensions.

Also was able to find a lot of .heic images, and a few .heif. However some of the .heic images have mime type of image/heif, both as returned by finfo_file() and looking at Mac's Preview app.

Seems images with all four mime types can have a .heic file extension and (seemingly) that may be preferred and/or is not considered an error. Wondering how to handle this in WordPress. Couple options:

  1. When uploading rename images with the image/heic, image/heif, image/heic-sequence, image/heif-sequence mime types to have .heic file extension. As far as I see most already have it. This seems somewhat more compatible with similar images that are available on the internet at this time.
  1. Rename .heic and .heif images according to their mime type. Seems that will change many .heic images to .heif. Also rename images with image/heic-sequence and image/heif-sequence mime types to .heic and .heif regardless of the existing extension.

This ticket was mentioned in Slack in #core by stoyangeorgiev. View the logs.


6 weeks ago

#14 follow-up: @ironprogrammer
6 weeks ago

For HEIC images I've tested from my iPhone (going back to 2017), they're all .HEIC (capitalized) and mime image/heic. Because the presumptive use case of HEIC support in WordPress is to help iOS users, perhaps supporting the other "questionable" mime variations can be shelved until they become more widely adopted?

But I agree it would help to at least add support for image/heif, as originally reported for this ticket, since that seems to be a common mime for sample spec images. A .heic file returning image/heif should be considered valid.

In response to @azaozz:

  1. Rename .heic and .heif images according to their mime type...

I don't think original uploads should be renamed to match the mime. The HEIC designation hints that the file has a HEVC encoded image (like attachment:sample1.heic), which is valid as image/heif. Let's leave the original files alone.

Also rename images with image/heic-sequence and image/heif-sequence mime types to .heic and .heif regardless of the existing extension.

As a side note, while chatting with @azaozz about sequence/burst images, we found that ImageMagick (magick CLI) grabs the first frame when converting to JPEG, so seems to work okay at a glance. However, for lack of finding a real-world use case for this, I think supporting sequences should wait until there's a defined need.

This ticket was mentioned in PR #7650 on WordPress/wordpress-develop by @azaozz.


6 weeks ago
#15

  • Keywords has-patch added; needs-patch removed

Add support for all HEIC images mime types.

Trac ticket: https://core.trac.wordpress.org/ticket/62272

#16 in reply to: ↑ 14 @azaozz
6 weeks ago

Replying to ironprogrammer:

it would help to at least add support for image/heif, as originally reported for this ticket, since that seems to be a common mime for sample spec images. A .heic file returning image/heif should be considered valid.

Right, my thinking too. The other two mime types can be "partially supported" for now, i.e. don't prevent uploading, but the results of converting them to JPEGs may vary.

I don't think original uploads should be renamed to match the mime. The HEIC designation hints that the file has a HEVC encoded image (like attachment:sample1.heic), which is valid as image/heif.

Yep, this seems most compatible. Went with 1 above: all HEIC images have .heic file extension.

found that ImageMagick (magick CLI) grabs the first frame when converting to JPEG, so seems to work okay at a glance. However, for lack of finding a real-world use case for this, I think supporting sequences should wait until there's a defined need.

This is somewhat similar to the support for animated GIFs: when resized the sub-sizes are of the first frame only. I too thinking this can be left as-is for now and revisited if the need arises. These images seem extremely rare for now.

Last edited 6 weeks ago by azaozz (previous) (diff)

This ticket was mentioned in Slack in #core by chaion07. View the logs.


6 weeks ago

This ticket was mentioned in Slack in #core by azaozz. View the logs.


6 weeks ago

#19 @azaozz
6 weeks ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 59315:

Media: Fix uploading of .heic images.

  • Adds support for all HEIC/HEIF mime types: image/heic, image/heif, image/heic-sequence, and image/heif-sequence.
  • Introduces wp_is_heic_image_mime_type().

Props swissspidy, adamsilverstein, debarghyabanerjee, ironprogrammer, peterwilsoncc, apermo, azaozz.
Fixes #62272.

#20 @azaozz
6 weeks ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopen for 6.7.

This ticket was mentioned in Slack in #core by azaozz. View the logs.


6 weeks ago

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.


5 weeks ago

#23 follow-up: @ironprogrammer
5 weeks ago

Here are some confidence checks for this update to support a wider variety of HEIC formats.

Test Report

Patch tested: [59315]

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 14.6.1
  • Browser: Safari 17.6, Google Chrome 130.0.6723.91
  • Server: nginx/1.27.2
  • PHP: 8.3.13, w/ ImageMagick (supports HEIC->JPEG conversion)
  • MySQL: 8.0.27
  • WordPress: 6.8-alpha-59274-src

Actual Results

  • ✅ Upload supported for image/heif and image/heif-sequence (could not locate an image/heic-sequence file for this test).
    • anim-heif-sequence.heic - image/heif-sequence
    • burst-heif-sequence.heic - image/heif-sequence
    • static-heif.heic - image/heif
    • static-ios-heic.HEIC - image/heic(regression test)

Supplemental Artifacts

Videos:

This ticket was mentioned in Slack in #core by azaozz. View the logs.


5 weeks ago

#25 in reply to: ↑ 23 @azaozz
5 weeks ago

Replying to ironprogrammer:

Great test report, thanks! Think it confirms both this ticket and #62305 as some of the test images were smaller than the big image threshold. Looking at the videos the image is a JPEG and the uploaded .heic file can be seen as "Original image" in the sidebar.

#26 @mosne
5 weeks ago

Hello, I've tested the patch, and I have a small issue in the editor en some problem with the front.

Test Report

Patch tested: [59315]

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/7650.diff

Environment

  • WordPress: 6.8-alpha-59274-src
  • PHP: 8.2.25
  • Server: nginx/1.27.2
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.2.25)
  • Browser: Chrome 130.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Upload supported for image/heif
  2. ❌ No preview images for image/heif / image/heic during upload.
  3. ❌ All images in front are looking small.

Additional Notes

  • It seems related to the new attribute sizes auto introduced (rightfully) by the performance team in the last release.

example:

  • Before

<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="683" src="http://localhost:10049/wp-content/uploads/2024/10/image-1024x683.jpg" alt="" class="wp-image-2239" srcset="http://localhost:10049/wp-content/uploads/2024/10/image-1024x683.jpg 1024w, http://localhost:10049/wp-content/uploads/2024/10/image-300x200.jpg 300w, http://localhost:10049/wp-content/uploads/2024/10/image-768x512.jpg 768w, http://localhost:10049/wp-content/uploads/2024/10/image-1536x1024.jpg 1536w, http://localhost:10049/wp-content/uploads/2024/10/image.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px"></figure>

  • After

{{{<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="683" src="http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3-1024x683.jpg" alt="" class="wp-image-23" srcset="http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3-1024x683.jpg 1024w, http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3-300x200.jpg 300w, http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3-768x512.jpg 768w, http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3-1536x1024.jpg 1536w, http://localhost:8889/wp-content/uploads/2024/11/2186606b72b426379.48966035-2048x1365-3.jpg 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px"></figure>

}}}

Supplemental Artifacts

  • video on chrome

https://kdrive.infomaniak.com/app/share/565596/5078577d-176e-4877-aa1c-edc96fe041f0

#27 @swissspidy
5 weeks ago

No preview images for image/heif / image/heic during upload.

@mosne That's expected. Chrome does not support HEIF images, which is why there is no preview. That's the whole point why WordPress now converts those images to JPEGs.

All images in front are looking small.

Not sure I follow what's going on when looking at your video. But if you think there's an issues with sizes=auto then that's an issue with sizes=auto, and not HEIF/HEIC and warrants its own issue.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


5 weeks ago

#29 @ironprogrammer
5 weeks ago

Thank you for sharing your test report and video, @mosne! Your report validates the fix for this ticket, in that HEIC images of various mimes can be uploaded. 🙌🏻

I wasn't able to reproduce the issue you shared with selecting full size for the converted images, and agree with @swissspidy that a separate Trac ticket with reproduction details would be helpful for tracking that down, including what happens with non-converted images inserted into posts.

#30 @mosne
5 weeks ago

@swissspidy ok for the preview part, sorry I thought that there was a better browser support :)
@ironprogrammer I agree with you: I've created a new ticket for the other issue. #62345
since I'm a newbie here I'm not sure of the severity of the bug, so please take a look
Thank you

#31 follow-up: @peterwilsoncc
4 weeks ago

@azaozz Another naming things for this ticket, sorry. I think the variable name $heic_images_etx was a typo and ought to been $heic_images_ext (or extensions for extra clarity).

Otherwise I think [59315] is good for backport after reviewing the changes and some manual testing but will await your feedback on the above.

#32 in reply to: ↑ 31 @azaozz
4 weeks ago

Replying to peterwilsoncc:

Ugh, right, it is a typo. Fixing.

#33 @azaozz
4 weeks ago

In 59358:

Media: Fix variable name in wp_check_filetype_and_ext().

Props peterwilsoncc.
See #62272.

#34 @peterwilsoncc
4 weeks ago

  • Keywords dev-reviewed added; fixed-major removed

[59315], [59358] approved for backport. I'll do this now.

#35 @peterwilsoncc
4 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 59360:

Media: Fix uploading of .heic images.

  • Adds support for all HEIC/HEIF mime types: image/heic, image/heif, image/heic-sequence, and image/heif-sequence.
  • Introduces wp_is_heic_image_mime_type().

This backport includes a subsequent fix of a typo.

Reviewed by peterwilsoncc.
Merges [59315,59358] to the 6.7 branch.

Props swissspidy, adamsilverstein, debarghyabanerjee, ironprogrammer, peterwilsoncc, apermo, azaozz, mosne.
Fixes #62272.

Note: See TracTickets for help on using tickets.