This is an automated email from the git hooks/post-receive script.
Git pushed a commit to branch release/9.0
in repository ffmpeg.
The following commit(s) were added to refs/heads/release/9.0 by this push:
new 8c7ef49002 avformat/mov_chan: grow custom channel maps incrementally
8c7ef49002 is described below
commit 8c7ef49002fffdd0554481b36c849e89bdb72887
Author: Marvin Scholz <[email protected]>
AuthorDate: Tue Nov 17 01:40:15 2026 +0000
Commit: ffmpeg-devel <[email protected]>
CommitDate: Thu Nov 19 00:16:54 2026 +0000
avformat/mov_chan: grow custom channel maps incrementally
ff_mov_read_chan() and ff_mov_read_chnl() previously allocated the full
custom channel map upfront from st->codecpar->ch_layout.nb_channels
before reading any channel entries from the stream. On containers with a
32-bit channel count and 64-bit chunk size (such as CAF or MOV stsd v2),
a truncated header can specify up to INT32_MAX channels and trigger
multi-gigabyte allocations before hitting EOF.
Grow tmp.u.map incrementally with av_dynarray2_add() as channel entries
are read from AVIOContext, and check pb->eof_reached in
ff_mov_read_chnl().
Signed-off-by: Marvin Scholz <[email protected]>
(cherry picked from commit aa7c09781dd698d6cd775631198eefcc34a21fcd)
---
libavformat/mov_chan.c | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index 8274e62f3d..88bab2e879 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -569,7 +569,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb,
AVStream *st,
return 0;
if (layout_tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS) {
- AVChannelLayout tmp = { 0 };
+ AVChannelLayout tmp = { .order = AV_CHANNEL_ORDER_CUSTOM };
int nb_channels = ch_layout->nb_channels;
if (!num_descr || num_descr < nb_channels) {
@@ -589,11 +589,13 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb,
AVStream *st,
num_descr = nb_channels;
}
- ret = av_channel_layout_custom_init(&tmp, nb_channels);
- if (ret < 0)
+ if (nb_channels <= 0) {
+ ret = AVERROR(EINVAL);
goto out;
+ }
for (int i = 0; i < num_descr; i++) {
+ AVChannelCustom ch = { 0 };
uint32_t label;
if (pb->eof_reached) {
av_log(s, AV_LOG_ERROR,
@@ -607,7 +609,13 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb,
AVStream *st,
avio_rl32(pb); // mCoordinates[1]
avio_rl32(pb); // mCoordinates[2]
size -= 20;
- tmp.u.map[i].id = mov_get_channel_id(label);
+ ch.id = mov_get_channel_id(label);
+ if (!av_dynarray2_add((void **)&tmp.u.map, &tmp.nb_channels,
+ sizeof(*tmp.u.map), (const uint8_t *)&ch)) {
+ av_channel_layout_uninit(&tmp);
+ ret = AVERROR(ENOMEM);
+ goto out;
+ }
}
ret = av_channel_layout_retype(&tmp, 0,
AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL);
@@ -783,7 +791,7 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb,
AVStream *st, int vers
av_log(s, AV_LOG_TRACE, "'chnl' layout %d\n", layout);
if (!layout) {
- AVChannelLayout tmp = { 0 }, *ch_layout = &st->codecpar->ch_layout;
+ AVChannelLayout tmp = { .order = AV_CHANNEL_ORDER_CUSTOM },
*ch_layout = &st->codecpar->ch_layout;
int nb_channels = ch_layout->nb_channels;
if (version == 1) {
@@ -793,14 +801,22 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb,
AVStream *st, int vers
return AVERROR_INVALIDDATA;
}
- ret = av_channel_layout_custom_init(&tmp, nb_channels);
- if (ret < 0)
- return ret;
+ if (nb_channels <= 0)
+ return AVERROR(EINVAL);
for (int i = 0; i < nb_channels; i++) {
- int speaker_pos = avio_r8(pb);
+ AVChannelCustom ch = { 0 };
+ int speaker_pos;
enum AVChannel channel;
+ if (pb->eof_reached) {
+ av_log(s, AV_LOG_ERROR,
+ "reached EOF while reading channel layout\n");
+ av_channel_layout_uninit(&tmp);
+ return AVERROR_INVALIDDATA;
+ }
+
+ speaker_pos = avio_r8(pb);
if (speaker_pos == 126) // explicit position
avio_skip(pb, 3); // azimuth, elevation
@@ -814,7 +830,12 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb,
AVStream *st, int vers
channel = AV_CHAN_UNKNOWN;
}
- tmp.u.map[i].id = channel;
+ ch.id = channel;
+ if (!av_dynarray2_add((void **)&tmp.u.map, &tmp.nb_channels,
+ sizeof(*tmp.u.map), (const uint8_t
*)&ch)) {
+ av_channel_layout_uninit(&tmp);
+ return AVERROR(ENOMEM);
+ }
}
ret = av_channel_layout_retype(&tmp, 0,
AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL);
--
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]