[vlc-commits] codec: adpcm: check computing of samples per block
Francois Cartegnie
git at videolan.org
Thu Sep 29 11:53:35 CEST 2016
vlc/vlc-2.2 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Sep 29 11:32:07 2016 +0200| [606431b7ce1bf006b094fd91160625bf9230f6fe] | committer: Jean-Baptiste Kempf
codec: adpcm: check computing of samples per block
we should not trust block size
(cherry picked from commit 7f2eeddd05ec8d889ad9bda67c440db408055834)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=606431b7ce1bf006b094fd91160625bf9230f6fe
---
modules/codec/adpcm.c | 48 +++++++++++++++++++++++++++++++++++-------------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c
index cc28a59..7838fc7 100644
--- a/modules/codec/adpcm.c
+++ b/modules/codec/adpcm.c
@@ -162,6 +162,7 @@ static int OpenDecoder( vlc_object_t *p_this )
return VLC_ENOMEM;
p_sys->prev = NULL;
+ p_sys->i_samplesperblock = 0;
uint8_t i_max_channels = 5;
switch( p_dec->fmt_in.i_codec )
@@ -224,28 +225,41 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->i_samplesperblock = 64;
break;
case ADPCM_IMA_WAV:
- p_sys->i_samplesperblock =
- 2 * ( p_sys->i_block - 4 * p_dec->fmt_in.audio.i_channels ) /
- p_dec->fmt_in.audio.i_channels;
+ if( p_sys->i_block >= 4 * p_dec->fmt_in.audio.i_channels )
+ {
+ p_sys->i_samplesperblock =
+ 2 * ( p_sys->i_block - 4 * p_dec->fmt_in.audio.i_channels ) /
+ p_dec->fmt_in.audio.i_channels;
+ }
break;
case ADPCM_MS:
- p_sys->i_samplesperblock =
- 2 * (p_sys->i_block - 7 * p_dec->fmt_in.audio.i_channels) /
- p_dec->fmt_in.audio.i_channels + 2;
+ if( p_sys->i_block >= 7 * p_dec->fmt_in.audio.i_channels )
+ {
+ p_sys->i_samplesperblock =
+ 2 * (p_sys->i_block - 7 * p_dec->fmt_in.audio.i_channels) /
+ p_dec->fmt_in.audio.i_channels + 2;
+ }
break;
case ADPCM_DK4:
- p_sys->i_samplesperblock =
- 2 * (p_sys->i_block - 4 * p_dec->fmt_in.audio.i_channels) /
- p_dec->fmt_in.audio.i_channels + 1;
+ if( p_sys->i_block >= 4 * p_dec->fmt_in.audio.i_channels )
+ {
+ p_sys->i_samplesperblock =
+ 2 * (p_sys->i_block - 4 * p_dec->fmt_in.audio.i_channels) /
+ p_dec->fmt_in.audio.i_channels + 1;
+ }
break;
case ADPCM_DK3:
p_dec->fmt_in.audio.i_channels = 2;
- p_sys->i_samplesperblock = ( 4 * ( p_sys->i_block - 16 ) + 2 )/ 3;
+ if( p_sys->i_block >= 16 )
+ p_sys->i_samplesperblock = ( 4 * ( p_sys->i_block - 16 ) + 2 )/ 3;
break;
case ADPCM_EA:
- p_sys->i_samplesperblock =
- 2 * (p_sys->i_block - p_dec->fmt_in.audio.i_channels) /
- p_dec->fmt_in.audio.i_channels;
+ if( p_sys->i_block >= p_dec->fmt_in.audio.i_channels )
+ {
+ p_sys->i_samplesperblock =
+ 2 * (p_sys->i_block - p_dec->fmt_in.audio.i_channels) /
+ p_dec->fmt_in.audio.i_channels;
+ }
}
msg_Dbg( p_dec, "format: samplerate:%d Hz channels:%d bits/sample:%d "
@@ -254,6 +268,14 @@ static int OpenDecoder( vlc_object_t *p_this )
p_dec->fmt_in.audio.i_bitspersample, p_sys->i_block,
p_sys->i_samplesperblock );
+ if (p_sys->i_samplesperblock == 0)
+ {
+ free(p_sys->prev);
+ free(p_sys);
+ msg_Err( p_dec, "Error computing number of samples per block");
+ return VLC_EGENERIC;
+ }
+
p_dec->p_sys = p_sys;
p_dec->fmt_out.i_cat = AUDIO_ES;
p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
More information about the vlc-commits
mailing list