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

These three decoders read the sample rate from their extradata in init() but 
never reject a non-positive value. alac and alsdec declare 
AV_CODEC_CAP_CHANNEL_CONF, so avcodec_open2() does not reject a zero sample 
rate; wavarc overwrites the sample rate avcodec_open2() had already validated. 
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).

Following the same approach as #25808, the sample rate is checked in init() 
with the same message and error code avcodec_open2() uses for decoders without 
AV_CODEC_CAP_CHANNEL_CONF.

Found with the OSS decoder fuzzers for ALAC, WAVARC and ALS.


>From 83590562c7c412838452d69e3b351c62cbb31606 Mon Sep 17 00:00:00 2001
From: Trevor Hansen <[email protected]>
Date: Thu, 12 Nov 2026 10:03:55 +1100
Subject: [PATCH] avcodec/alac, wavarc, alsdec: reject a non-positive sample
 rate

These three decoders read the sample rate from the extradata in their
init() function but never reject a non-positive value. alac and alsdec
declare AV_CODEC_CAP_CHANNEL_CONF, so avcodec_open2() does not reject a
zero sample rate; wavarc overwrites the sample rate avcodec_open2() had
already validated. 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).

Check the sample rate in init() after reading it, with the same message
and error code avcodec_open2() uses for decoders without
AV_CODEC_CAP_CHANNEL_CONF.

Signed-off-by: Trevor Hansen <[email protected]>
---
 libavcodec/alac.c   | 5 +++++
 libavcodec/alsdec.c | 4 ++++
 libavcodec/wavarc.c | 4 ++++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index f91288e97c8..b67279575c2 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -579,6 +579,11 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
     avctx->bits_per_raw_sample = alac->sample_size;
     avctx->sample_rate         = alac->sample_rate;
 
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
+
     if (alac->channels < 1) {
         av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
         if (avctx->ch_layout.nb_channels < 1)
diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 5378d01d43d..4ac5310da15 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -322,6 +322,10 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
     // read the fixed items
     als_id                      = get_bits_long(&gb, 32);
     avctx->sample_rate          = m4ac.sample_rate;
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
     skip_bits_long(&gb, 32); // sample rate already known
     sconf->samples              = get_bits_long(&gb, 32);
 
diff --git a/libavcodec/wavarc.c b/libavcodec/wavarc.c
index 3169a5f0d65..8de2a45bd6b 100644
--- a/libavcodec/wavarc.c
+++ b/libavcodec/wavarc.c
@@ -79,6 +79,10 @@ static av_cold int wavarc_init(AVCodecContext *avctx)
     av_channel_layout_uninit(&avctx->ch_layout);
     av_channel_layout_default(&avctx->ch_layout, AV_RL16(avctx->extradata + 
38));
     avctx->sample_rate = AV_RL32(avctx->extradata + 40);
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", 
avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
 
     s->align = avctx->ch_layout.nb_channels;
 
-- 
2.54.0

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

Reply via email to