avformat/mov: reject dimg references with zero entries
Reject dimg entries with a zero reference count in mov_read_iref_dimg(). This is the earliest point where the parser learns how many input images a derived HEIF item references, so it is the right place to enforce the invariant. If entries == 0 is accepted here, the value is stored in HEIFGrid.nb_tiles, later propagated by read_image_iovl() into AVStreamGroupTileGrid.nb_tiles, and finally consumed in istg_parse_tile_grid(), which assumes at least one tile and reads tg->offsets[tg->nb_tiles - 1]. With zero tiles, that assumption breaks and leads to the out-of-bounds access seen in ASan. Fixing the problem at the parser boundary is preferable to adding a later workaround because it prevents creation of an invalid derived-image state and stops that malformed state from reaching downstream consumers. This is also consistent with the HEIF specification. Both iovl and grid derived images are formed from one or more input images, and for grid the dimg reference count must equal rows * columns; since rows and columns are encoded as *_minus_one + 1, that count cannot be zero. A zero dimg entry count is therefore invalid input and should be rejected when parsed.
This commit is contained in:
committed by
michaelni
parent
0f6ba39122
commit
68ea660d83
+7
-1
@@ -9217,6 +9217,13 @@ static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version)
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
entries = avio_rb16(pb);
|
||||
if (!entries) {
|
||||
av_log(c->fc, AV_LOG_ERROR,
|
||||
"Derived image item references no input images\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
|
||||
grid = av_realloc_array(c->heif_grid, c->nb_heif_grid + 1U,
|
||||
sizeof(*c->heif_grid));
|
||||
if (!grid)
|
||||
@@ -9224,7 +9231,6 @@ static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version)
|
||||
c->heif_grid = grid;
|
||||
grid = &grid[c->nb_heif_grid];
|
||||
|
||||
entries = avio_rb16(pb);
|
||||
grid->tile_id_list = av_malloc_array(entries, sizeof(*grid->tile_id_list));
|
||||
grid->tile_idx_list = av_calloc(entries, sizeof(*grid->tile_idx_list));
|
||||
grid->tile_item_list = av_calloc(entries, sizeof(*grid->tile_item_list));
|
||||
|
||||
Reference in New Issue
Block a user