iLBC: Handle a case of bad input data

We detect an unreasonable state (caused by a bad encoded stream)
before it can lead to problems, and handle it by resetting the
decoder.

NOPRESUBMIT=true
BUG=chromium:617124

Review-Url: https://codereview.webrtc.org/2255203002
Cr-Commit-Position: refs/heads/master@{#13888}
This commit is contained in:
kwiberg
2016-08-24 02:46:44 -07:00
committed by Commit bot
parent 0aa9d1808b
commit 619a211562
16 changed files with 211 additions and 99 deletions

View File

@ -16,6 +16,8 @@
******************************************************************/
#include "decode_residual.h"
#include <string.h>
#include "defines.h"
@ -32,7 +34,7 @@
* frame residual decoder function (subrutine to iLBC_decode)
*---------------------------------------------------------------*/
void WebRtcIlbcfix_DecodeResidual(
bool WebRtcIlbcfix_DecodeResidual(
IlbcDecoder *iLBCdec_inst,
/* (i/o) the decoder state structure */
iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits, which are used
@ -72,11 +74,11 @@ void WebRtcIlbcfix_DecodeResidual(
/* construct decoded vector */
WebRtcIlbcfix_CbConstruct(
&decresidual[start_pos+iLBCdec_inst->state_short_len],
iLBC_encbits->cb_index, iLBC_encbits->gain_index,
mem+CB_MEML-ST_MEM_L_TBL,
ST_MEM_L_TBL, diff);
if (!WebRtcIlbcfix_CbConstruct(
&decresidual[start_pos + iLBCdec_inst->state_short_len],
iLBC_encbits->cb_index, iLBC_encbits->gain_index,
mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL, diff))
return false; // Error.
}
else {/* put adaptive part in the beginning */
@ -90,12 +92,11 @@ void WebRtcIlbcfix_DecodeResidual(
/* construct decoded vector */
WebRtcIlbcfix_CbConstruct(
reverseDecresidual,
iLBC_encbits->cb_index, iLBC_encbits->gain_index,
mem+CB_MEML-ST_MEM_L_TBL,
ST_MEM_L_TBL, diff
);
if (!WebRtcIlbcfix_CbConstruct(reverseDecresidual, iLBC_encbits->cb_index,
iLBC_encbits->gain_index,
mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL,
diff))
return false; // Error.
/* get decoded residual from reversed vector */
@ -122,12 +123,12 @@ void WebRtcIlbcfix_DecodeResidual(
for (subframe=0; subframe<Nfor; subframe++) {
/* construct decoded vector */
WebRtcIlbcfix_CbConstruct(
&decresidual[(iLBC_encbits->startIdx+1+subframe)*SUBL],
iLBC_encbits->cb_index+subcount*CB_NSTAGES,
iLBC_encbits->gain_index+subcount*CB_NSTAGES,
mem, MEM_LF_TBL, SUBL
);
if (!WebRtcIlbcfix_CbConstruct(
&decresidual[(iLBC_encbits->startIdx + 1 + subframe) * SUBL],
iLBC_encbits->cb_index + subcount * CB_NSTAGES,
iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL,
SUBL))
return false; // Error;
/* update memory */
memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem));
@ -160,12 +161,12 @@ void WebRtcIlbcfix_DecodeResidual(
for (subframe=0; subframe<Nback; subframe++) {
/* construct decoded vector */
WebRtcIlbcfix_CbConstruct(
&reverseDecresidual[subframe*SUBL],
iLBC_encbits->cb_index+subcount*CB_NSTAGES,
iLBC_encbits->gain_index+subcount*CB_NSTAGES,
mem, MEM_LF_TBL, SUBL
);
if (!WebRtcIlbcfix_CbConstruct(
&reverseDecresidual[subframe * SUBL],
iLBC_encbits->cb_index + subcount * CB_NSTAGES,
iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL,
SUBL))
return false; // Error.
/* update memory */
memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem));
@ -179,4 +180,6 @@ void WebRtcIlbcfix_DecodeResidual(
WebRtcSpl_MemCpyReversedOrder(decresidual+SUBL*Nback-1,
reverseDecresidual, SUBL*Nback);
}
return true; // Success.
}