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 <[email protected]>


>From 90269d74b9632c0d3b6b6d7a6d8ea8137806c31a Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
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 <[email protected]>
---
 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 -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to