Skip to content

Keep valid HEIF images when embedded thumbnail decoding fails - #206

Merged
danoli3 merged 1 commit into
masterfrom
fix/heif-thumbnail-errors
Oct 25, 2026
Merged

danoli3 merged 1 commit into
masterfrom
fix/heif-thumbnail-errors

Conversation

@danoli3

@danoli3 danoli3 commented Oct 25, 2026

Copy link
Copy Markdown
Owner

A HEIF image with a damaged or unsupported embedded thumbnail currently loses its successfully decoded primary image: the thumbnail exception reaches the outer load handler, which returns NULL.

Catch thumbnail errors within the thumbnail-loading block, report the error through FreeImage's message callback, and return the primary image. Existing valid-thumbnail loading and header-only behavior are preserved.

Add two small synthetic HEIF fixtures for a corrupt thumbnail bitstream and the coded-size mismatch seen in the reported HEIX file. The tests verify that primary pixels and Exif remain intact, valid thumbnails still load, bad bitstreams produce no thumbnail, and header-only loading succeeds. Older libheif versions that accept the inconsistent thumbnail dimensions are also supported.

Validation:

  • Original code rejects the reported 8192 x 5464 sample with Decoded image does not have the size signaled in the file; the fix loads the complete primary image and reports/omits the rejected thumbnail.
  • All 12 tests pass with system libheif 1.23.2 and with bundled libheif 1.23.6, including both new fixtures. The supplied sample loads successfully with both builds and produces identical primary pixel hashes.
  • The reported photograph is kept out of the repository; regression assets total about 2 KB.

Fixes #204.

@danoli3
danoli3 merged commit 85b7994 into master Oct 25, 2026
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HEIF thumbnail decode error discards a valid primary image

1 participant