Skip to content

Commit

Permalink
Issue #2209: more accurate magic for HEIF files.
Browse files Browse the repository at this point in the history
Just looking for "ftyp" would also match other ISOBMFF files (.mov or
.mp4 files for instance). These are the possible 4-byte "brand" code
which can follow "ftyp", as listed by Dirk Farin from libheif.

I add the "mif1" brand, as I encountered some files using this magic
(even though this should normally not be valid apparently, yet the file
loaded fine in GIMP).

This is not perfect as the standard allows potentially very big box
headers, in which case 8 bytes (the "largesize" slot) may be inserted
between "ftyp" and the brand, as I understand it. But this is actually
unlikely enough to probably never happen (the compatible brands list
would have to be huuuge, as it looks like this is the only extendable
part in a ftyp box). So let's assume this just never happens.

See also: strukturag/libheif#83

(cherry picked from commit 4ad3993)
  • Loading branch information
Jehan committed Sep 16, 2018
1 parent eb227b1 commit e4bff4c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plug-ins/common/file-heif.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,19 @@ query (void)
gimp_register_load_handler (LOAD_PROC, "heic,heif", "");
gimp_register_file_handler_mime (LOAD_PROC, "image/heif");
gimp_register_file_handler_uri (LOAD_PROC);
/* HEIF is an ISOBMFF format whose "brand" (the value after "ftyp")
* can be of various values. I added the "mif1" brand as I saw some
* HEIF files with this value, and it loaded fine (though it may not
* be valid theoretically, according to libheif developers).
* See also: https://gitlab.gnome.org/GNOME/gimp/issues/2209
*/
gimp_register_magic_load_handler (LOAD_PROC,
"heif,heic",
"",
"4,string,ftyp");
"4,string,ftypheic,4,string,ftypheix,"
"4,string,ftyphevc,4,string,ftypheim,"
"4,string,ftypheis,4,string,ftyphevm,"
"4,string,ftyphevs,4,string,ftypmif1");

gimp_install_procedure (SAVE_PROC,
_("Exports HEIF images"),
Expand Down

0 comments on commit e4bff4c

Please sign in to comment.