Commit f0e0286b authored by Tristan Matthews's avatar Tristan Matthews Committed by Felix Paul Kühne

twolame: avoid buffer overflow

Refs #12298

(cherry picked from commit 9ab9aa37080ed6e8d34717bdf416509c7e38bbf9)
Signed-off-by: default avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 40b1fa12
...@@ -251,12 +251,24 @@ static int OpenEncoder( vlc_object_t *p_this ) ...@@ -251,12 +251,24 @@ static int OpenEncoder( vlc_object_t *p_this )
****************************************************************************/ ****************************************************************************/
static void Bufferize( encoder_t *p_enc, int16_t *p_in, int i_nb_samples ) static void Bufferize( encoder_t *p_enc, int16_t *p_in, int i_nb_samples )
{ {
int16_t *p_buffer = p_enc->p_sys->p_buffer encoder_sys_t *p_sys = p_enc->p_sys;
+ (p_enc->p_sys->i_nb_samples const unsigned i_offset = p_sys->i_nb_samples * p_enc->fmt_in.audio.i_channels;
* p_enc->fmt_in.audio.i_channels); const unsigned i_len = ARRAY_SIZE(p_sys->p_buffer);
if( i_offset >= i_len )
{
msg_Err( p_enc, "buffer full" );
return;
}
unsigned i_copy = i_nb_samples * p_enc->fmt_in.audio.i_channels;
if( i_copy + i_offset > i_len)
{
msg_Err( p_enc, "dropping samples" );
i_copy = i_len - i_offset;
}
memcpy( p_buffer, p_in, i_nb_samples * p_enc->fmt_in.audio.i_channels memcpy( p_sys->p_buffer + i_offset, p_in, i_copy * sizeof(int16_t) );
* sizeof(int16_t) );
} }
static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf ) static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment