Skip to content

Bug: HEIC files containing JPEG data cannot generate previews #2137

Description

@mrliuchang-crypto

Bug: HEIC files containing JPEG data cannot generate previews

Bug description

Nextcloud cannot generate previews for a number of files whose filename extension is .HEIC and whose Nextcloud MIME type is image/heic, but whose actual file content is JPEG.

The files appear to be JPEG images that were saved or renamed with a .HEIC extension.

For these files:

  • Nextcloud reports the MIME type as image/heic
  • ImageMagick detects the actual image format as JPEG
  • PHP Imagick can successfully read the file as JPEG
  • occ preview:generate fails with No provider successfully handled the preview generation
  • Renaming the file from .HEIC to .JPG using occ files:move immediately allows preview generation
  • The file ID remains unchanged after the rename

This suggests that the HEIC preview provider is selected based on the Nextcloud MIME type, but the actual image data is JPEG and therefore cannot be processed correctly by the HEIC provider.

Environment

  • Nextcloud Server: 34.x
  • PHP: 8.5
  • Web server: Apache
  • OS: Debian
  • MariaDB
  • Raspberry Pi 5
  • ImageMagick / Imagick installed
  • previewgenerator: 5.14.0
  • memories: 8.1.0

The HEIC preview provider is explicitly enabled:

OC\Preview\Movie
OC\Preview\MP4
OC\Preview\MKV
OC\Preview\AVI
OC\Preview\Image
OC\Preview\HEIC

ImageMagick supports both HEIC and JPEG.

Example affected file

Original filename:

IMG_6886.HEIC

Nextcloud:

fileid: 283288
mimetype: image/heic
size: 480 KB

Actual file detection:

$ identify IMG_6886.HEIC

JPEG 4032x3024

The file command also identifies it as JPEG image data.

PHP Imagick can read it successfully:

READ OK
Format: JPEG
Size: 4032x3024

However:

$ php8.5 occ preview:generate "/admin/files/Photos/2020/01/IMG_6886.HEIC"

In Generator.php line 413:

No provider successfully handled the preview generation

Control test

I renamed the same file using Nextcloud:

occ files:move \
"/admin/files/Photos/2020/01/IMG_6886.HEIC" \
"/admin/files/Photos/2020/01/IMG_6886.JPG"

The same file then reports:

fileid: 283288
mimetype: image/jpeg

The file ID did not change.

After changing only the filename extension:

$ php8.5 occ preview:generate \
"/admin/files/Photos/2020/01/IMG_6886.JPG"

preview generated

The preview files were then created successfully, including:

48-64.jpg
3024-4032-max.jpg

This demonstrates that the underlying image data itself is valid and that ImageMagick/Imagick can process it.

Scale of the problem

I scanned the HEIC files in my Photos directory using ImageMagick.

There are:

2807 files detected as actual HEIC
1955 files detected as JPEG

The 1955 JPEG files all have .HEIC filenames.

For example:

/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6886.HEIC
/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6898.HEIC
/mnt/pool/nextcloud_data/admin/files/Photos/2020/01/IMG_6885.HEIC
...

Nextcloud still identifies these files as:

mimetype: image/heic

even though ImageMagick reports:

JPEG 4032x3024

Expected behavior

If a file has a .HEIC extension but its actual image data is JPEG, Nextcloud should ideally detect the actual image format and use an appropriate preview provider.

At minimum, the HEIC preview provider should fail gracefully and allow another compatible image preview provider to handle the file when the underlying image is actually JPEG.

Actual behavior

Nextcloud treats these files as image/heic and attempts to use the HEIC preview provider.

Preview generation fails:

No provider successfully handled the preview generation

Manually renaming the file to .JPG immediately fixes the problem.

Additional observation

A real HEIC file works correctly on the same system.

For example:

IMG_7125.HEIC

is detected by ImageMagick as:

HEIC 3024x4032

and:

occ preview:generate "/admin/files/Photos/2020/01/IMG_7125.HEIC"

returns:

preview generated

Therefore this does not appear to be a general ImageMagick/HEIC installation problem.

The problematic files specifically appear to be JPEG data stored under a .HEIC filename.

Reproduction

  1. Take a valid JPEG image.
  2. Rename it to test.HEIC.
  3. Upload it to Nextcloud.
  4. Nextcloud identifies it as image/heic.
  5. Confirm that ImageMagick identifies the actual data as JPEG.
  6. Run:
occ preview:generate "/path/to/test.HEIC"
  1. Preview generation fails.
  2. Rename the same file to test.JPG using occ files:move.
  3. Run occ preview:generate again.
  4. Preview generation succeeds.

Question

Could the HEIC preview provider fall back to the normal image/JPEG preview provider when the underlying file is actually JPEG?

Alternatively, could Nextcloud detect the actual image format before selecting the preview provider for files with a .HEIC extension?

I can provide additional logs, configuration, or test files if needed.

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