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

@ -22,6 +22,7 @@
#include "encode.h"
#include "init_decode.h"
#include "decode.h"
#include "webrtc/base/checks.h"
#include <stdlib.h>
int16_t WebRtcIlbcfix_EncoderAssign(IlbcEncoderInstance** iLBC_encinst,
@ -180,11 +181,12 @@ int WebRtcIlbcfix_Decode(IlbcDecoderInstance* iLBCdec_inst,
}
while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) {
WebRtcIlbcfix_DecodeImpl(
&decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl],
(const uint16_t*)&encoded
[2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words],
(IlbcDecoder*)iLBCdec_inst, 1);
if (WebRtcIlbcfix_DecodeImpl(
&decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl],
(const uint16_t*)&encoded
[2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words],
(IlbcDecoder*)iLBCdec_inst, 1) == -1)
return -1;
i++;
}
/* iLBC does not support VAD/CNG yet */
@ -208,11 +210,12 @@ int WebRtcIlbcfix_Decode20Ms(IlbcDecoderInstance* iLBCdec_inst,
}
while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) {
WebRtcIlbcfix_DecodeImpl(
if (!WebRtcIlbcfix_DecodeImpl(
&decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl],
(const uint16_t*)&encoded
[2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words],
(IlbcDecoder*)iLBCdec_inst, 1);
(IlbcDecoder*)iLBCdec_inst, 1))
return -1;
i++;
}
/* iLBC does not support VAD/CNG yet */
@ -236,11 +239,12 @@ int WebRtcIlbcfix_Decode30Ms(IlbcDecoderInstance* iLBCdec_inst,
}
while ((i*((IlbcDecoder*)iLBCdec_inst)->no_of_bytes)<len) {
WebRtcIlbcfix_DecodeImpl(
if (!WebRtcIlbcfix_DecodeImpl(
&decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl],
(const uint16_t*)&encoded
[2 * i * ((IlbcDecoder*)iLBCdec_inst)->no_of_words],
(IlbcDecoder*)iLBCdec_inst, 1);
(IlbcDecoder*)iLBCdec_inst, 1))
return -1;
i++;
}
/* iLBC does not support VAD/CNG yet */
@ -255,10 +259,11 @@ size_t WebRtcIlbcfix_DecodePlc(IlbcDecoderInstance* iLBCdec_inst,
uint16_t dummy;
for (i=0;i<noOfLostFrames;i++) {
/* call decoder */
WebRtcIlbcfix_DecodeImpl(
// PLC decoding shouldn't fail, because there is no external input data
// that can be bad.
RTC_CHECK(WebRtcIlbcfix_DecodeImpl(
&decoded[i * ((IlbcDecoder*)iLBCdec_inst)->blockl], &dummy,
(IlbcDecoder*)iLBCdec_inst, 0);
(IlbcDecoder*)iLBCdec_inst, 0));
}
return (noOfLostFrames*((IlbcDecoder*)iLBCdec_inst)->blockl);
}