Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2013-11-11 22:06:54 +0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2013-11-11 22:06:54 +0400
commitf6066df2b9f8231ba3d5df27962e05cb658aac1f (patch)
tree64dca23e2b199171e0486f0d5e051a5ec6fecbe8
parentca6fac041bc6ffe4a8b21eb6ee429dd32d803764 (diff)
More size-zero VLA fixes and making opus_decode* return BAD_ARG on framesize<0
-rw-r--r--celt/quant_bands.c4
-rw-r--r--silk/fixed/pitch_analysis_core_FIX.c2
-rw-r--r--src/opus_decoder.c21
3 files changed, 22 insertions, 5 deletions
diff --git a/celt/quant_bands.c b/celt/quant_bands.c
index 79685e17..52d6e0bb 100644
--- a/celt/quant_bands.c
+++ b/celt/quant_bands.c
@@ -312,6 +312,7 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
opus_int32 tell_intra;
opus_uint32 nstart_bytes;
opus_uint32 nintra_bytes;
+ opus_uint32 save_bytes;
int badness2;
VARDECL(unsigned char, intra_bits);
@@ -322,7 +323,8 @@ void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
nstart_bytes = ec_range_bytes(&enc_start_state);
nintra_bytes = ec_range_bytes(&enc_intra_state);
intra_buf = ec_get_buffer(&enc_intra_state) + nstart_bytes;
- ALLOC(intra_bits, nintra_bytes-nstart_bytes, unsigned char);
+ save_bytes = IMAX(ALLOC_NONE, nintra_bytes-nstart_bytes);
+ ALLOC(intra_bits, save_bytes, unsigned char);
/* Copy bits from intra bit-stream */
OPUS_COPY(intra_bits, intra_buf, nintra_bytes - nstart_bytes);
diff --git a/silk/fixed/pitch_analysis_core_FIX.c b/silk/fixed/pitch_analysis_core_FIX.c
index b6bc0bbf..b2c6cbb4 100644
--- a/silk/fixed/pitch_analysis_core_FIX.c
+++ b/silk/fixed/pitch_analysis_core_FIX.c
@@ -465,7 +465,7 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0
/***************************************************************************/
/* find scaling as max scaling for each subframe */
silk_sum_sqr_shift( &energy, &shift, frame, frame_length );
- ALLOC( scratch_mem, shift > 0 ? frame_length : 0, opus_int16 );
+ ALLOC( scratch_mem, shift > 0 ? frame_length : ALLOC_NONE, opus_int16 );
if( shift > 0 ) {
/* Move signal to scratch mem because the input signal should be unchanged */
shift = silk_RSHIFT( shift, 1 );
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index e7964e3d..2a7b78bc 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -444,7 +444,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (redundancy)
{
transition = 0;
- pcm_transition_silk_size=0;
+ pcm_transition_silk_size=ALLOC_NONE;
}
ALLOC(pcm_transition_silk, pcm_transition_silk_size, opus_val16);
@@ -456,7 +456,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
}
/* Only allocation memory for redundancy if/when needed */
- redundant_audio_size = redundancy ? F5*st->channels : 0;
+ redundant_audio_size = redundancy ? F5*st->channels : ALLOC_NONE;
ALLOC(redundant_audio, redundant_audio_size, opus_val16);
/* 5 ms redundant frame for CELT->SILK*/
@@ -701,6 +701,11 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int opus_decode(OpusDecoder *st, const unsigned char *data,
opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec)
{
+ if(frame_size<=0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0);
}
@@ -712,6 +717,11 @@ int opus_decode_float(OpusDecoder *st, const unsigned char *data,
int ret, i;
ALLOC_STACK;
+ if(frame_size<=0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
ALLOC(out, frame_size*st->channels, opus_int16);
ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0);
@@ -734,7 +744,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
int ret, i;
ALLOC_STACK;
- if(frame_size<0)
+ if(frame_size<=0)
{
RESTORE_STACK;
return OPUS_BAD_ARG;
@@ -755,6 +765,11 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
int opus_decode_float(OpusDecoder *st, const unsigned char *data,
opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec)
{
+ if(frame_size<=0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0);
}