PR #25962 opened by fuzzyrichie
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25962
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25962.patch

Extends the fix in #25954 (alac/wavarc/alsdec) to three more decoders with the 
identical issue: qdmc, qdm2 and shorten take the sample rate from 
attacker-controlled data (extradata / in-band VERBATIM header) without 
validating it and can end up with a non-positive value; the decoder then 
outputs a frame whose sample rate is 0, which frame_validate() rejects with 
AVERROR_BUG (and which trips the av_assert0() in the decode fuzzer). Affected 
code paths: libavcodec/qdmc.c:261 (raw be32 from the QDCA extradata blob, 
reachable via AIFF 'wave' chunk and MOV; overwrites the rate avcodec_open2() 
had validated; AV_CODEC_CAP_CHANNEL_CONF bypasses the open-time rejection), 
libavcodec/qdm2.c:1768 (same pattern), libavcodec/shorten.c 
decode_wave_header()/decode_aiff_header() (rate from the embedded WAVE/AIFF 
VERBATIM header during the first frame, no check). Impact as stated in #25954: 
invalid frame output (AVERROR_BUG, 'An invalid frame was output by a decoder. 
This is a bug, please report it.'),
  fuzzer assert; for qdmc/qdm2 the stream is additionally reported with an 
unspecified sample rate, breaking filter graph init ('Sample rate not set'). 
Reproduced with crafted AIFF/SHN files (< 2 KB, available on request; 
generators can be attached): before the patch the decoders emit the invalid 
frame, after: 'Invalid sample rate: 0'; positive controls with rates 
11025/44100 decode normally. make fate: 3126 tests pass on the patched tree 
(sample-dependent qdm2/shorten FATE tests need fate-suite access); targeted 
ASAN decode verification of all three codecs done with crafted and valid inputs.


>From ca961a5a1084be7469516df3fa5f73a10b9b2eee Mon Sep 17 00:00:00 2001
From: Richard Desmarais <[email protected]>
Date: Wed, 11 Nov 2026 21:34:17 -0500
Subject: [PATCH] avcodec/qdmc, qdm2, shorten: reject a non-positive sample
 rate

These three decoders take the sample rate from attacker-controlled data:
qdmc and qdm2 read it from the extradata in their init() function (the
'QDCA' blob, reachable i.a. via the AIFF 'wave' chunk and MOV), overwriting
the value avcodec_open2() had already validated; all three declare
AV_CODEC_CAP_CHANNEL_CONF, so avcodec_open2() does not re-check it.
shorten reads the rate from the in-band WAVE/AIFF VERBATIM header when
the first frame is decoded. None of them validates the value.

The decoder then outputs a frame whose sample rate is 0, which
frame_validate() rejects with AVERROR_BUG (and which trips the av_assert0()
in the decode fuzzer). For qdmc and qdm2 the stream also ends up reported
with an unspecified sample rate ("Could not find codec parameters ... "
/ "Sample rate not set"), which breaks filter graph initialization.

Check the sample rate where it is read, with the same message and error
code avcodec_open2() uses for decoders without AV_CODEC_CAP_CHANNEL_CONF,
mirroring what 25954 does for alac, wavarc and alsdec.

Signed-off-by: Richard Desmarais <[email protected]>
---
 libavcodec/qdm2.c    | 4 ++++
 libavcodec/qdmc.c    | 4 ++++
 libavcodec/shorten.c | 8 ++++++++
 3 files changed, 16 insertions(+)

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 796321f9d8e..da650353684 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1766,6 +1766,10 @@ static av_cold int qdm2_decode_init(AVCodecContext 
*avctx)
     av_channel_layout_default(&avctx->ch_layout, s->channels);
 
     avctx->sample_rate = bytestream2_get_be32u(&gb);
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
     avctx->bit_rate    = bytestream2_get_be32u(&gb);
     s->group_size      = bytestream2_get_be32u(&gb);
     s->fft_size        = bytestream2_get_be32u(&gb);
diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index 474e5ef8faa..a30319d0a08 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -259,6 +259,10 @@ static av_cold int qdmc_decode_init(AVCodecContext *avctx)
                                              
(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     avctx->sample_rate = bytestream2_get_be32u(&b);
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
     avctx->bit_rate = bytestream2_get_be32u(&b);
     bytestream2_skipu(&b, 4);
     fft_size = bytestream2_get_be32u(&b);
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index c0325a81f8b..39ffd68ef49 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -270,6 +270,10 @@ static int decode_aiff_header(AVCodecContext *avctx, const 
uint8_t *header,
         avctx->sample_rate = val << exp;
     else
         avctx->sample_rate = (val + (1ULL<<(-exp-1))) >> -exp;
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
     len -= 18;
     if (len > 0)
         av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
@@ -325,6 +329,10 @@ static int decode_wave_header(AVCodecContext *avctx, const 
uint8_t *header,
 
     bytestream2_skip(&gb, 2); // skip channels    (already got from shorten 
header)
     avctx->sample_rate = bytestream2_get_le32(&gb);
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
     bytestream2_skip(&gb, 4); // skip bit rate    (represents original 
uncompressed bit rate)
     bytestream2_skip(&gb, 2); // skip block align (not needed)
     bps = bytestream2_get_le16(&gb);
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to