Skip to content

Commit 22720cf

Browse files
Wei Jiaandi34
authored andcommitted
SoftAMR: check input buffer size to avoid overflow.
Bug: 27662364 Change-Id: I47380545ea7d85845e141e722b0d84f498d27145
1 parent c11c8d0 commit 22720cf

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

media/libstagefright/codecs/amrnb/dec/SoftAMR.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ void SoftAMR::onQueueFilled(OMX_U32 portIndex) {
286286
BufferInfo *inInfo = *inQueue.begin();
287287
OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
288288

289+
if (inHeader->nFilledLen == 0) {
290+
inInfo->mOwnedByUs = false;
291+
inQueue.erase(inQueue.begin());
292+
notifyEmptyBufferDone(inHeader);
293+
continue;
294+
}
295+
289296
BufferInfo *outInfo = *outQueue.begin();
290297
OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
291298

@@ -321,6 +328,17 @@ void SoftAMR::onQueueFilled(OMX_U32 portIndex) {
321328
return;
322329
}
323330

331+
int16 mode = ((inputPtr[0] >> 3) & 0x0f);
332+
// for WMF since MIME_IETF is used when calling AMRDecode.
333+
size_t frameSize = WmfDecBytesPerFrame[mode] + 1;
334+
335+
if (inHeader->nFilledLen < frameSize) {
336+
ALOGE("b/27662364: expected %zu bytes vs %u", frameSize, inHeader->nFilledLen);
337+
notify(OMX_EventError, OMX_ErrorStreamCorrupt, 0, NULL);
338+
mSignalledError = true;
339+
return;
340+
}
341+
324342
numBytesRead =
325343
AMRDecode(mState,
326344
(Frame_Type_3GPP)((inputPtr[0] >> 3) & 0x0f),
@@ -371,10 +389,8 @@ void SoftAMR::onQueueFilled(OMX_U32 portIndex) {
371389

372390
size_t frameSize = getFrameSize(mode);
373391
if (inHeader->nFilledLen < frameSize) {
374-
ALOGE("Filled length vs frameSize %d vs %d. Corrupt clip?",
375-
inHeader->nFilledLen, frameSize);
376-
377-
notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
392+
ALOGE("b/27662364: expected %zu bytes vs %u", frameSize, inHeader->nFilledLen);
393+
notify(OMX_EventError, OMX_ErrorStreamCorrupt, 0, NULL);
378394
mSignalledError = true;
379395
return;
380396
}

media/libstagefright/codecs/amrnb/dec/src/amrdecode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ terms listed above has been obtained from the copyright holder.
104104
; INCLUDES
105105
----------------------------------------------------------------------------*/
106106
#include "typedef.h"
107-
#include "mode.h"
108107
#include "frame_type_3gpp.h"
109108

110109
/*--------------------------------------------------------------------------*/

media/libstagefright/codecs/amrnb/dec/src/gsmamr_dec.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ terms listed above has been obtained from the copyright holder.
8787

8888
#include "gsm_amr_typedefs.h"
8989
#include "frame_type_3gpp.h"
90+
#include "amrdecode.h"
9091

9192
/*--------------------------------------------------------------------------*/
9293
#ifdef __cplusplus
@@ -135,19 +136,6 @@ extern "C"
135136
Word16 GSMInitDecode(void **state_data,
136137
Word8 *id);
137138

138-
/*
139-
* AMRDecode steps into the part of the library that decodes the raw data
140-
* speech bits for the decoding process. It returns the address offset of
141-
* the next frame to be decoded.
142-
*/
143-
Word16 AMRDecode(
144-
void *state_data,
145-
enum Frame_Type_3GPP frame_type,
146-
UWord8 *speech_bits_ptr,
147-
Word16 *raw_pcm_buffer,
148-
Word16 input_format
149-
);
150-
151139
/*
152140
* This function resets the state memory used by the GSM AMR decoder. This
153141
* function returns zero. It will return negative one if there is an error.

0 commit comments

Comments
 (0)