Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: michaelni via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: michaelni <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avcodec/libvorbisdec: output AV_SAMPLE_FMT_FLTP (PR #21717)
Date: Tue, 10 Feb 2026 23:41:38 -0000
Message-ID: <177076738160.25.3761966764312119924@009cbcb3d8cd> (raw)

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

This removes the internal sample format convert

Fixes: nan is outside the range of representable values of type 'int'
Fixes: 471946097/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBVORBIS_DEC_fuzzer-4843605174059008

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>


>From 90269d74b9632c0d3b6b6d7a6d8ea8137806c31a Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael@niedermayer.cc>
Date: Tue, 10 Feb 2026 16:08:41 +0100
Subject: [PATCH] avcodec/libvorbisdec: output AV_SAMPLE_FMT_FLTP

This removes the internal sample format convert

Fixes: nan is outside the range of representable values of type 'int'
Fixes: 471946097/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBVORBIS_DEC_fuzzer-4843605174059008

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/libvorbisdec.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/libavcodec/libvorbisdec.c b/libavcodec/libvorbisdec.c
index 326ed4b4fe..b081c42820 100644
--- a/libavcodec/libvorbisdec.c
+++ b/libavcodec/libvorbisdec.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <string.h>
 #include <vorbis/vorbisenc.h>
 
 #include "avcodec.h"
@@ -124,7 +125,7 @@ static av_cold int oggvorbis_decode_init(AVCodecContext *avccontext)
     avccontext->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
     avccontext->ch_layout.nb_channels = context->vi.channels;
     avccontext->sample_rate = context->vi.rate;
-    avccontext->sample_fmt = AV_SAMPLE_FMT_S16;
+    avccontext->sample_fmt = AV_SAMPLE_FMT_FLTP;
     avccontext->time_base= (AVRational){1, avccontext->sample_rate};
 
     vorbis_synthesis_init(&context->vd, &context->vi);
@@ -138,33 +139,14 @@ static av_cold int oggvorbis_decode_init(AVCodecContext *avccontext)
 }
 
 
-static inline int conv(int samples, float **pcm, char *buf, int channels) {
-    int i, j;
-    ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ;
-    float *mono ;
-
-    for(i = 0 ; i < channels ; i++){
-        ptr = &data[i];
-        mono = pcm[i] ;
-
-        for(j = 0 ; j < samples ; j++) {
-            *ptr = av_clip_int16(mono[j] * 32767.f);
-            ptr += channels;
-        }
-    }
-
-    return 0 ;
-}
-
 static int oggvorbis_decode_frame(AVCodecContext *avccontext, AVFrame *frame,
                                   int *got_frame_ptr, AVPacket *avpkt)
 {
     OggVorbisDecContext *context = avccontext->priv_data ;
     float **pcm ;
     ogg_packet *op= &context->op;
-    int samples, total_samples, total_bytes;
+    int samples, total_samples;
     int ret;
-    int16_t *output;
 
     if(!avpkt->size){
     //FIXME flush
@@ -174,8 +156,6 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, AVFrame *frame,
     frame->nb_samples = 8192*4;
     if ((ret = ff_get_buffer(avccontext, frame, 0)) < 0)
         return ret;
-    output = (int16_t *)frame->data[0];
-
 
     op->packet = avpkt->data;
     op->bytes  = avpkt->size;
@@ -190,11 +170,10 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, AVFrame *frame,
         vorbis_synthesis_blockin(&context->vd, &context->vb) ;
 
     total_samples = 0 ;
-    total_bytes = 0 ;
 
     while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) {
-        conv(samples, pcm, (char*)output + total_bytes, context->vi.channels) ;
-        total_bytes += samples * 2 * context->vi.channels ;
+        for (int ch = 0; ch < context->vi.channels; ch++)
+            memcpy((float *)frame->extended_data[ch] + total_samples, pcm[ch], samples * sizeof(float));
         total_samples += samples ;
         vorbis_synthesis_read(&context->vd, samples) ;
     }
@@ -229,4 +208,5 @@ const FFCodec ff_libvorbis_decoder = {
     .init           = oggvorbis_decode_init,
     FF_CODEC_DECODE_CB(oggvorbis_decode_frame),
     .close          = oggvorbis_decode_close,
+    CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP),
 };
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-02-10 23:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=177076738160.25.3761966764312119924@009cbcb3d8cd \
    --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