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:
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:
even though ImageMagick reports:
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:
is detected by ImageMagick as:
and:
occ preview:generate "/admin/files/Photos/2020/01/IMG_7125.HEIC"
returns:
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
- Take a valid JPEG image.
- Rename it to
test.HEIC.
- Upload it to Nextcloud.
- Nextcloud identifies it as
image/heic.
- Confirm that ImageMagick identifies the actual data as JPEG.
- Run:
occ preview:generate "/path/to/test.HEIC"
- Preview generation fails.
- Rename the same file to
test.JPG using occ files:move.
- Run
occ preview:generate again.
- 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.
Bug: HEIC files containing JPEG data cannot generate previews
Bug description
Nextcloud cannot generate previews for a number of files whose filename extension is
.HEICand whose Nextcloud MIME type isimage/heic, but whose actual file content is JPEG.The files appear to be JPEG images that were saved or renamed with a
.HEICextension.For these files:
image/heicJPEGocc preview:generatefails withNo provider successfully handled the preview generation.HEICto.JPGusingocc files:moveimmediately allows preview generationThis 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
previewgenerator: 5.14.0memories: 8.1.0The HEIC preview provider is explicitly enabled:
ImageMagick supports both HEIC and JPEG.
Example affected file
Original filename:
Nextcloud:
Actual file detection:
The
filecommand also identifies it as JPEG image data.PHP Imagick can read it successfully:
However:
Control test
I renamed the same file using Nextcloud:
The same file then reports:
The file ID did not change.
After changing only the filename extension:
The preview files were then created successfully, including:
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:
The 1955 JPEG files all have
.HEICfilenames.For example:
Nextcloud still identifies these files as:
even though ImageMagick reports:
Expected behavior
If a file has a
.HEICextension 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/heicand attempts to use the HEIC preview provider.Preview generation fails:
Manually renaming the file to
.JPGimmediately fixes the problem.Additional observation
A real HEIC file works correctly on the same system.
For example:
is detected by ImageMagick as:
and:
returns:
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
.HEICfilename.Reproduction
test.HEIC.image/heic.test.JPGusingocc files:move.occ preview:generateagain.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
.HEICextension?I can provide additional logs, configuration, or test files if needed.