Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 0/4] Check sample rate generically
@ 2025-06-23  5:28 ffmpegagent
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 1/4] avcodec/avcodec: Check sample_rate generically Andreas Rheinhardt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ffmpegagent @ 2025-06-23  5:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: mkver

This is an alternative to
https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/345575.html.

Andreas Rheinhardt (4):
  avcodec/avcodec: Check sample_rate generically
  avcodec/wma,wmaprodec: Remove always-false checks
  avcodec/wma: Remove redundant nb_channels check
  avcodec/wmaprodec: Avoid branch for setting block_align

 libavcodec/avcodec.c   |  6 +++++-
 libavcodec/encode.c    |  5 -----
 libavcodec/wma.c       |  4 ++--
 libavcodec/wmaprodec.c | 20 +++++++-------------
 4 files changed, 14 insertions(+), 21 deletions(-)


base-commit: 34953e195fe108224abdfe25d147f1a7ba5477c8
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-101%2Fmkver%2Fsample_rate_check-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-101/mkver/sample_rate_check-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/101
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 1/4] avcodec/avcodec: Check sample_rate generically
  2025-06-23  5:28 [FFmpeg-devel] [PATCH 0/4] Check sample rate generically ffmpegagent
@ 2025-06-23  5:28 ` Andreas Rheinhardt
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 2/4] avcodec/wma, wmaprodec: Remove always-false checks Andreas Rheinhardt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23  5:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

Check that all audio codecs except decoders with the
AV_CODEC_CAP_CHANNEL_CONF flag have a positive sample rate set.

Fixes: AVERROR_BUG return
Fixes: 413997604/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HCA_fuzzer-5188382613635072

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/avcodec.c | 6 +++++-
 libavcodec/encode.c  | 5 -----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 7bcb0295e5..0ad39b4d91 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -254,7 +254,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         }
     }
 
-    if (avctx->sample_rate < 0) {
+    /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
+     * in particular checks that sample_rate is set for all audio encoders. */
+    if (avctx->sample_rate < 0 ||
+        avctx->sample_rate == 0 && avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
+        !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
         av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
         ret = AVERROR(EINVAL);
         goto free_and_end;
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 72dfa8867a..38833c566c 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -633,11 +633,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
                avctx->sample_fmt);
         return AVERROR(EINVAL);
     }
-    if (avctx->sample_rate <= 0) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid audio sample rate: %d\n",
-               avctx->sample_rate);
-        return AVERROR(EINVAL);
-    }
 
     ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT,
                                        0, (const void **) &sample_fmts,
-- 
ffmpeg-codebot

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] avcodec/wma, wmaprodec: Remove always-false checks
  2025-06-23  5:28 [FFmpeg-devel] [PATCH 0/4] Check sample rate generically ffmpegagent
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 1/4] avcodec/avcodec: Check sample_rate generically Andreas Rheinhardt
@ 2025-06-23  5:28 ` Andreas Rheinhardt
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 3/4] avcodec/wma: Remove redundant nb_channels check Andreas Rheinhardt
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 4/4] avcodec/wmaprodec: Avoid branch for setting block_align Andreas Rheinhardt
  3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23  5:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

None of the codecs used here has the AV_CODEC_CAP_CHANNEL_CONF
cap set, so the sample rate is checked generically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/wma.c       | 2 +-
 libavcodec/wmaprodec.c | 5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 257184c0d8..31a422ee27 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -86,7 +86,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     int sample_rate1;
     int coef_vlc_table;
 
-    if (avctx->sample_rate <= 0 || avctx->sample_rate > 50000 ||
+    if (avctx->sample_rate > 50000 ||
         channels           <= 0 || channels    > 2            ||
         avctx->bit_rate    <= 0)
         return -1;
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 44e5da08ab..7f3dc7fd8b 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -471,11 +471,6 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
         return AVERROR_INVALIDDATA;
     }
 
-    if (s->avctx->sample_rate <= 0) {
-        av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     if (s->nb_channels <= 0) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n",
                s->nb_channels);
-- 
ffmpeg-codebot

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 3/4] avcodec/wma: Remove redundant nb_channels check
  2025-06-23  5:28 [FFmpeg-devel] [PATCH 0/4] Check sample rate generically ffmpegagent
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 1/4] avcodec/avcodec: Check sample_rate generically Andreas Rheinhardt
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 2/4] avcodec/wma, wmaprodec: Remove always-false checks Andreas Rheinhardt
@ 2025-06-23  5:28 ` Andreas Rheinhardt
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 4/4] avcodec/wmaprodec: Avoid branch for setting block_align Andreas Rheinhardt
  3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23  5:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

Already checked generically as none of the codecs here
have the AV_CODEC_CAP_CHANNEL_CONF set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/wma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 31a422ee27..0a34c1b00e 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -87,7 +87,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     int coef_vlc_table;
 
     if (avctx->sample_rate > 50000 ||
-        channels           <= 0 || channels    > 2            ||
+        channels    > 2            ||
         avctx->bit_rate    <= 0)
         return -1;
 
-- 
ffmpeg-codebot

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] avcodec/wmaprodec: Avoid branch for setting block_align
  2025-06-23  5:28 [FFmpeg-devel] [PATCH 0/4] Check sample rate generically ffmpegagent
                   ` (2 preceding siblings ...)
  2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 3/4] avcodec/wma: Remove redundant nb_channels check Andreas Rheinhardt
@ 2025-06-23  5:28 ` Andreas Rheinhardt
  3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23  5:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/wmaprodec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 7f3dc7fd8b..d87ed0433e 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -370,14 +370,6 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
     int log2_max_num_subframes;
     int num_possible_block_sizes;
 
-    if (avctx->codec_id == AV_CODEC_ID_XMA1 || avctx->codec_id == AV_CODEC_ID_XMA2)
-        avctx->block_align = 2048;
-
-    if (!avctx->block_align) {
-        av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
-        return AVERROR(EINVAL);
-    }
-
     s->avctx = avctx;
 
     init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
@@ -603,6 +595,11 @@ static av_cold int wmapro_decode_init(AVCodecContext *avctx)
 {
     WMAProDecodeCtx *s = avctx->priv_data;
 
+    if (!avctx->block_align) {
+        av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
+        return AVERROR(EINVAL);
+    }
+
     return decode_init(s, avctx, 0);
 }
 
@@ -1957,6 +1954,8 @@ static av_cold int xma_decode_init(AVCodecContext *avctx)
     XMADecodeCtx *s = avctx->priv_data;
     int i, ret, start_channels = 0;
 
+    avctx->block_align = 2048;
+
     if (avctx->ch_layout.nb_channels <= 0 || avctx->extradata_size == 0)
         return AVERROR_INVALIDDATA;
 
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-23  5:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23  5:28 [FFmpeg-devel] [PATCH 0/4] Check sample rate generically ffmpegagent
2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 1/4] avcodec/avcodec: Check sample_rate generically Andreas Rheinhardt
2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 2/4] avcodec/wma, wmaprodec: Remove always-false checks Andreas Rheinhardt
2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 3/4] avcodec/wma: Remove redundant nb_channels check Andreas Rheinhardt
2025-06-23  5:28 ` [FFmpeg-devel] [PATCH 4/4] avcodec/wmaprodec: Avoid branch for setting block_align Andreas Rheinhardt

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