PR #25917 opened by onurctirtir
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25917
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25917.patch
# Summary of changes
A photo taken with an iPhone 16 on iOS 18.3.1 couldn't be opened, although
its primary image was fine. Five of the 48 tiles of its Apple "styledeltamap"
auxiliary image grid had no iloc entry and no hvcC property, and
mov_parse_heif_items() rejected the whole file because of the following:
stream 95, missing mandatory atoms, broken header
Error opening input: Invalid data found when processing input
So the first commit ignores such an item with a warning, as mov_read_trak()
ignores a track missing mandatory atoms. The existing checks in
mov_parse_tiles() and mov_parse_heif_layered_video() then drop any stream
group that uses the item. If no stream or group is left for the primary item,
the demuxer fails as before. With -err_detect compliant or explode, it also
fails as before.
The second commit adds a FATE test. Its "sample"(*) is attached to this PR
and needs to be added to the fate-suite.
(Note (*): I avoided sharing the original photo that caused the failure as it
was a personal one, but please let me know if it won't work that way)
The sample is gain_map_tmap.heic with one item's
iloc entry removed, as the commit message describes.
```fate-samples
heif/gain_map_tmap_gain_map_no_data.heic
```
User-visible changes:
- A file with such an item now opens, and the demuxer logs
"Ignoring HEIF item id N" for each one.
- The ignored item's stream stays in the stream list, as a track ignored by
mov_read_trak() does.
Testing:
- `make fate` passes with and without `--disable-x86asm`.
- Without the first commit, the new sample fails to open.
- Fuzzed the HEIF and AVIF samples with tools/trasher and with a script
that removes iloc entries and ipma associations, on an ASan build. Each
crash found is in send_eof() in fftools/ffmpeg_filter.c on
gain_map_alpha_grid.avif, in a build without an AV1 decoder, and unpatched
master crashes the same way on those inputs.
>From c1a6a8b2e3a3c2f55b988f8d05817c9224ac2633 Mon Sep 17 00:00:00 2001
From: Onur Tirtir <[email protected]>
Date: Tue, 10 Nov 2026 01:22:55 +0300
Subject: [PATCH 1/2] avformat/mov: ignore HEIF items with no data instead of
failing
A photo taken with an iPhone 16 on iOS 18.3.1 has an intact primary
image, a grid of 45 tiles. But five of the 48 tiles of its Apple
"styledeltamap" auxiliary image grid have no iloc entry and no hvcC
property. sanity_checks() fails for such an item, because its sample
size is 0, so mov_parse_heif_items() rejected the whole file:
stream 95, missing mandatory atoms, broken header
Error opening input: Invalid data found when processing input
Ignore such an item with a warning instead, as mov_read_trak() ignores
a track missing mandatory atoms. The existing checks in mov_parse_tiles()
and mov_parse_heif_layered_video() then drop any stream group that uses
it. If no stream or group is left for the primary item, fail as before.
With -err_detect compliant or explode, also fail as before.
Signed-off-by: Onur Tirtir <[email protected]>
---
libavformat/mov.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0c2f592e7f3..2019cb50030 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -12027,6 +12027,7 @@ static int mov_parse_heif_layered_video(AVFormatContext
*s)
static int mov_parse_heif_items(AVFormatContext *s)
{
MOVContext *mov = s->priv_data;
+ int nb_ignored = 0;
int err;
for (int i = 0; i < mov->nb_heif_item; i++) {
@@ -12057,8 +12058,17 @@ static int mov_parse_heif_items(AVFormatContext *s)
sc->sample_count = 1;
err = sanity_checks(s, sc, st->index);
- if (err)
- return AVERROR_INVALIDDATA;
+ if (err) {
+ if (s->error_recognition & (AV_EF_COMPLIANT | AV_EF_EXPLODE))
+ return AVERROR_INVALIDDATA;
+ /* Ignore the item, as mov_read_trak() ignores a track missing
+ * mandatory atoms. Stream groups that use it are then dropped
+ * below, and we fail if that leaves no primary image. */
+ av_log(s, AV_LOG_WARNING, "Ignoring HEIF item id %d\n",
item->item_id);
+ item->st = NULL;
+ nb_ignored++;
+ continue;
+ }
if (offset > INT64_MAX - item->extent_offset)
return AVERROR_INVALIDDATA;
@@ -12086,6 +12096,16 @@ static int mov_parse_heif_items(AVFormatContext *s)
if (err < 0)
return err;
+ if (nb_ignored) {
+ const HEIFItem *primary = get_heif_item(mov, mov->primary_item_id);
+
+ if (!primary || (!primary->st && !primary->stg)) {
+ av_log(s, AV_LOG_ERROR, "HEIF primary item id %d doesn't reference
a "
+ "stream or group\n", mov->primary_item_id);
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
return 0;
}
--
2.54.0
>From 1f8f59efa37c95418192bd703a4c430ecbcb7cbf Mon Sep 17 00:00:00 2001
From: Onur Tirtir <[email protected]>
Date: Tue, 10 Nov 2026 02:07:50 +0300
Subject: [PATCH 2/2] tests/fate/mov: add a test for a HEIF item with no data
gain_map_tmap_gain_map_no_data.heic is gain_map_tmap.heic with the iloc
entry of item 6, the gain map, removed. A free box of the same size
follows the iloc box, so the size of the meta box and the offsets of the
other items don't change. The demuxer ignores the gain map and drops the
tmap group, and keeps the primary grid.
Signed-off-by: Onur Tirtir <[email protected]>
---
tests/fate/mov.mak | 6 ++++
...mov-heic-demux-still-image-gainmap-no-data | 33 +++++++++++++++++++
2 files changed, 39 insertions(+)
create mode 100644 tests/ref/fate/mov-heic-demux-still-image-gainmap-no-data
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 7aabe980d3d..ddf445b7175 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -329,6 +329,12 @@ FATE_MOV_FFMPEG_FFPROBE_SAMPLES-$(call FRAMECRC, MOV,
HEVC, HEVC_PARSER) \
fate-mov-heic-demux-still-image-gainmap-tmap: CMD = stream_demux mov
$(TARGET_SAMPLES)/heif/gain_map_tmap.heic "" "-c:v copy -map 0:g:0 -map 0:4" \
"-of compact -show_entries
stream_group=index,id,nb_streams,type:stream_group_components:stream_group_disposition:stream_group_tags:stream_group_side_data:stream_group_stream=index,id:stream_group_stream_disposition:stream_group_stream_side_data_list"
+# heic demuxing - still image where the Gain Map item has no data, so only the
base image grid is exported
+FATE_MOV_FFMPEG_FFPROBE_SAMPLES-$(call FRAMECRC, MOV, HEVC, HEVC_PARSER) \
+ += fate-mov-heic-demux-still-image-gainmap-no-data
+fate-mov-heic-demux-still-image-gainmap-no-data: CMD = stream_demux mov
$(TARGET_SAMPLES)/heif/gain_map_tmap_gain_map_no_data.heic "" "-c:v copy -map
0:g:0" \
+ "-of compact -show_entries
stream_group=index,id,nb_streams,type:stream_group_components:stream_group_disposition:stream_group_tags:stream_group_side_data:stream_group_stream=index,id:stream_group_stream_disposition:stream_group_stream_side_data_list"
+
# Resulting remux should have:
# 1. first audio stream with AV_DISPOSITION_HEARING_IMPAIRED
# 2. second audio stream with AV_DISPOSITION_VISUAL_IMPAIRED | DESCRIPTIONS
diff --git a/tests/ref/fate/mov-heic-demux-still-image-gainmap-no-data
b/tests/ref/fate/mov-heic-demux-still-image-gainmap-no-data
new file mode 100644
index 00000000000..16c5ca19724
--- /dev/null
+++ b/tests/ref/fate/mov-heic-demux-still-image-gainmap-no-data
@@ -0,0 +1,33 @@
+#extradata 0: 105, 0x607d1563
+#extradata 1: 105, 0x607d1563
+#extradata 2: 105, 0x607d1563
+#extradata 3: 105, 0x607d1563
+#tb 0: 1/1
+#media_type 0: video
+#codec_id 0: hevc
+#dimensions 0: 512x512
+#sar 0: 0/1
+#tb 1: 1/1
+#media_type 1: video
+#codec_id 1: hevc
+#dimensions 1: 512x512
+#sar 1: 0/1
+#tb 2: 1/1
+#media_type 2: video
+#codec_id 2: hevc
+#dimensions 2: 512x512
+#sar 2: 0/1
+#tb 3: 1/1
+#media_type 3: video
+#codec_id 3: hevc
+#dimensions 3: 512x512
+#sar 3: 0/1
+0, 0, 0, 1, 1900, 0xdc4fa164
+1, 0, 0, 1, 716, 0x9eb062d8
+2, 0, 0, 1, 1344, 0x60ee8d67
+3, 0, 0, 1, 730, 0x7dfa6c3d
+stream_group|index=0|id=0x5|nb_streams=4|type=Tile
Grid|component_entry/tile_grid:nb_tiles=4|component_entry/tile_grid:coded_width=1024|component_entry/tile_grid:coded_height=1024|component_entry/tile_grid:horizontal_offset=0|component_entry/tile_grid:vertical_offset=0|component_entry/tile_grid:width=600|component_entry/tile_grid:height=800|subcomponent_entry/tile_offset:stream_index=0|subcomponent_entry/tile_offset:tile_horizontal_offset=0|subcomponent_entry/tile_offset:tile_vertical_offset=0|subcomponent_entry/tile_offset:stream_index=1|subcomponent_entry/tile_offset:tile_horizontal_offset=512|subcomponent_entry/tile_offset:tile_vertical_offset=0|subcomponent_entry/tile_offset:stream_index=2|subcomponent_entry/tile_offset:tile_horizontal_offset=0|subcomponent_entry/tile_offset:tile_vertical_offset=512|subcomponent_entry/tile_offset:stream_index=3|subcomponent_entry/tile_offset:tile_horizontal_offset=512|subcomponent_entry/tile_offset:tile_vertical_offset=512|disposition:default=1|
disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0|disposition:multilayer=0|side_datum/exif_metadata:side_data_type=EXIF
metadata|side_datum/exif_metadata:size=796|side_datum/icc_profile:side_data_type=ICC
Profile
+stream|index=0|id=0x1|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=1|disposition:still_image=0|disposition:multilayer=0|side_datum/icc_profile:side_data_type=ICC
Profile
+stream|index=1|id=0x2|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=1|disposition:still_image=0|disposition:multilayer=0|side_datum/icc_profile:side_data_type=ICC
Profile
+stream|index=2|id=0x3|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=1|disposition:still_image=0|disposition:multilayer=0|side_datum/icc_profile:side_data_type=ICC
Profile
+stream|index=3|id=0x4|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=1|disposition:still_image=0|disposition:multilayer=0|side_datum/icc_profile:side_data_type=ICC
Profile
--
2.54.0
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]