From: oliverchang via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: oliverchang <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avformat/iamf_parse: Fix heap-buffer-overflow (PR #21107)
Date: Fri, 05 Dec 2025 05:33:50 -0000
Message-ID: <176491283104.39.1723969197932564100@2cb04c0e5124> (raw)
PR #21107 opened by oliverchang
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21107
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21107.patch
The ASAN heap-buffer-overflow in `scalable_channel_layout_config` at
`libavformat/iamf_parse.c:435` was caused by an unchecked assumption
that the channel layout of a scalable audio layer is a superset of the
previous layer's channel layout.
`scalable_channel_layout_config` constructs a channel layout map by
copying channels from the previous layer and adding new ones. The memory
allocation is based on the target `loudspeaker_layout`. However, if the
target layout doesn't encompass all previous channels (e.g., Mono to
Stereo), copying previous channels followed by adding current ones could
exceed the allocated size, causing a heap buffer overflow.
This commit adds a check to ensure the previous layer's channel layout
is a subset of the current layer's layout by comparing their masks. If
the condition isn't met, `AVERROR_INVALIDDATA` is returned.
Fixes: https://issues.oss-fuzz.com/issues/464965414
>From 6b353995bea2f39dbb751ba868e156b4dd94e8a8 Mon Sep 17 00:00:00 2001
From: Oliver Chang <ochang@google.com>
Date: Fri, 5 Dec 2025 05:30:29 +0000
Subject: [PATCH] avformat/iamf_parse: Fix heap-buffer-overflow
The ASAN heap-buffer-overflow in `scalable_channel_layout_config` at
`libavformat/iamf_parse.c:435` was caused by an unchecked assumption
that the channel layout of a scalable audio layer is a superset of the
previous layer's channel layout.
`scalable_channel_layout_config` constructs a channel layout map by
copying channels from the previous layer and adding new ones. The memory
allocation is based on the target `loudspeaker_layout`. However, if the
target layout doesn't encompass all previous channels (e.g., Mono to
Stereo), copying previous channels followed by adding current ones could
exceed the allocated size, causing a heap buffer overflow.
This commit adds a check to ensure the previous layer's channel layout
is a subset of the current layer's layout by comparing their masks. If
the condition isn't met, `AVERROR_INVALIDDATA` is returned.
Fixes: https://issues.oss-fuzz.com/issues/464965414
---
libavformat/iamf_parse.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 597d800be0..3bb55eb0e9 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -399,8 +399,12 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
av_channel_layout_copy(&ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_loudspeaker_layout]);
} else if (loudspeaker_layout < 10) {
av_channel_layout_copy(&ch_layout, &ff_iamf_scalable_ch_layouts[loudspeaker_layout]);
- if (i)
- ch_layout.u.mask &= ~av_channel_layout_subset(&audio_element->element->layers[i-1]->ch_layout, UINT64_MAX);
+ if (i) {
+ uint64_t mask = av_channel_layout_subset(&audio_element->element->layers[i-1]->ch_layout, UINT64_MAX);
+ if ((ch_layout.u.mask & mask) != mask)
+ return AVERROR_INVALIDDATA;
+ ch_layout.u.mask &= ~mask;
+ }
} else
ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
.nb_channels = substream_count +
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next reply other threads:[~2025-12-05 5:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 5:33 oliverchang via ffmpeg-devel [this message]
2025-12-05 13:24 ` [FFmpeg-devel] " James Almer via ffmpeg-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176491283104.39.1723969197932564100@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git