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>
This commit is contained in:
Michael Niedermayer
2026-02-10 16:08:41 +01:00
committed by michaelni
parent 0e89d993c5
commit d138169966
+5 -26
View File
@@ -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) ;
}