[vlc-commits] [Git][videolan/vlc][master] 4 commits: packetizer: speex: only use frame_size from decoder
François Cartegnie (@fcartegnie)
gitlab at videolan.org
Thu Sep 10 12:30:08 UTC 2026
François Cartegnie pushed to branch master at VideoLAN / VLC
Commits:
919963e6 by François Cartegnie at 2026-09-10T13:46:52+02:00
packetizer: speex: only use frame_size from decoder
- - - - -
aaa782b8 by François Cartegnie at 2026-09-10T13:46:52+02:00
codec: speex: only use frame_size from decoder
fix #30103
- - - - -
fbe70dd6 by François Cartegnie at 2026-09-10T13:46:52+02:00
resampler: speex: check new rate assignment
- - - - -
d6a50c1a by François Cartegnie at 2026-09-10T13:46:52+02:00
resampler: speex: check for overflow
- - - - -
2 changed files:
- modules/audio_filter/resampler/speex.c
- modules/codec/speex.c
Changes:
=====================================
modules/audio_filter/resampler/speex.c
=====================================
@@ -23,6 +23,8 @@
#endif
#include <inttypes.h>
+#include <stdckdint.h>
+#include <limits.h>
#include <vlc_common.h>
#include <vlc_aout.h>
@@ -120,20 +122,36 @@ static void Close (filter_t *filter)
static block_t *Resample (filter_t *filter, block_t *in)
{
SpeexResamplerState *st = filter->p_sys;
+ block_t *out = NULL;
const size_t framesize = filter->fmt_out.audio.i_bytes_per_frame;
const unsigned irate = filter->fmt_in.audio.i_rate;
const unsigned orate = filter->fmt_out.audio.i_rate;
- spx_uint32_t ilen = in->i_nb_samples;
- spx_uint32_t olen = ((ilen + 2) * orate * UINT64_C(11))
- / (irate * UINT64_C(10));
+ if( speex_resampler_set_rate (st, irate, orate) != RESAMPLER_ERR_SUCCESS )
+ goto error;
- block_t *out = block_Alloc (olen * framesize);
- if (unlikely(out == NULL))
+ unsigned ilen = in->i_nb_samples;
+ unsigned olen;
+
+ // spx_uint32_t olen = ((ilen + 2) * orate * UINT64_C(11))
+ // / (irate * UINT64_C(10));
+ uint64_t num, den;
+ if( ckd_add(&olen, ilen, 2U) ||
+ ckd_mul(&num, (uint64_t)orate, UINT64_C(11)) ||
+ ckd_mul(&den, (uint64_t)irate, UINT64_C(10)) ||
+ ckd_mul(&num, (uint64_t)olen, num) ||
+ num / UINT_MAX >= den )
goto error;
- speex_resampler_set_rate (st, irate, orate);
+ olen = num / den;
+
+ if(SIZE_MAX / framesize < olen)
+ goto error;
+
+ out = block_Alloc (olen * framesize);
+ if (unlikely(out == NULL))
+ goto error;
int err;
if (filter->fmt_in.audio.i_format == VLC_CODEC_FL32)
=====================================
modules/codec/speex.c
=====================================
@@ -647,7 +647,17 @@ static block_t *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
i_pcm_output_size = 0, i_bits_in_speex_frame = 0;
block_t *p_new_block = NULL;
- i_pcm_output_size = p_sys->p_header->frame_size * sizeof(short);
+ spx_int32_t frame_size = 0;
+ if( speex_decoder_ctl( p_sys->p_state, SPEEX_GET_FRAME_SIZE, &frame_size ) != 0 ||
+ frame_size <= 0 || (size_t)frame_size > INT_MAX / sizeof(short) )
+ {
+ msg_Warn( p_dec, "Invalid or unknown frame size %d", frame_size );
+ if( p_block )
+ block_Release( p_block );
+ return NULL;
+ }
+
+ i_pcm_output_size = frame_size * sizeof(short);
/* Alloc/Update our temp buffer if needed */
void *p_realloc = realloc( p_sys->p_tempbuffer, i_pcm_output_size );
@@ -903,13 +913,17 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
if( p_sys->i_frame_in_packet < p_sys->p_header->frames_per_packet )
{
block_t *p_aout_buffer;
- if( p_sys->p_header->frame_size == 0 )
+ spx_int32_t frame_size = 0;
+ if( speex_decoder_ctl( p_sys->p_state, SPEEX_GET_FRAME_SIZE, &frame_size ) != 0 ||
+ frame_size <= 0 || (size_t)frame_size > INT_MAX )
+ {
+ msg_Warn( p_dec, "Invalid or unknown frame size %d", frame_size );
return NULL;
+ }
if( decoder_UpdateAudioFormat( p_dec ) )
return NULL;
- p_aout_buffer =
- decoder_NewAudioBuffer( p_dec, p_sys->p_header->frame_size );
+ p_aout_buffer = decoder_NewAudioBuffer( p_dec, frame_size );
if( !p_aout_buffer )
{
return NULL;
@@ -933,13 +947,13 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
if( p_sys->p_header->nb_channels == 2 )
speex_decode_stereo_int( (int16_t *)p_aout_buffer->p_buffer,
- p_sys->p_header->frame_size,
+ frame_size,
&p_sys->stereo );
/* Date management */
p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
p_aout_buffer->i_length =
- date_Increment( &p_sys->end_date, p_sys->p_header->frame_size )
+ date_Increment( &p_sys->end_date, frame_size )
- p_aout_buffer->i_pts;
p_sys->i_frame_in_packet++;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/97336913b8c2ab445c6f860081b335855ffd9402...d6a50c1a61acea4d943e7272ccdf27bfa4c4306b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/97336913b8c2ab445c6f860081b335855ffd9402...d6a50c1a61acea4d943e7272ccdf27bfa4c4306b
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list