Skip to content

Commit

Permalink
mp3dec: Update input buffer validation checks to handle EOS case
Browse files Browse the repository at this point in the history
In case of EOS, application may call pvmp3_framedecoder() with a zero
length buffer and in such cases pvmp3_framedecoder() is expected return
NO_ENOUGH_MAIN_DATA_ERROR.
Earlier CL that added checks to validate the input buffer, was wrongly
returning SYNCH_LOST_ERROR for zero length cases. This is now addressed
by updating the error code appropriately.

Bug: 315387969
Test: atest VtsHalMediaOmxV1_0TargetAudioDecTest
(cherry picked from https://partner-android-review.googlesource.com/q/commit:3aba4cda18971c011b3ce27778e4d056688c42ad)
Merged-In: I48038143dd7c797d7a95a8e90ce56c8e659fb51d
Change-Id: I48038143dd7c797d7a95a8e90ce56c8e659fb51d
  • Loading branch information
harishdm authored and NurKeinNeid committed Jun 13, 2024
1 parent c2d51ae commit e30837b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions media/module/codecs/mp3dec/src/pvmp3_framedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,31 @@ static uint32_t U32_AT(const uint8_t *ptr) {
}

// Check if the input is valid by checking if it contains a sync word
static bool isInputValid(uint8 *buf, uint32 inSize)
static ERROR_CODE validate_input(uint8 *buf, uint32 inSize)
{
// Buffer needs to contain at least 4 bytes which is the size of
// the header
if (inSize < 4) return false;
/*
* Verify that at least the header is complete
* Note that SYNC_WORD_LNGTH is in unit of bits, but inSize is in unit of bytes.
*/
if (inSize < ((SYNC_WORD_LNGTH + 21) >> 3))
{
return NO_ENOUGH_MAIN_DATA_ERROR;
}

size_t totalInSize = 0;
size_t frameSize = 0;
while (totalInSize <= (inSize - 4)) {
if (!parseHeader(U32_AT(buf + totalInSize), &frameSize)) {
return false;
return SYNCH_LOST_ERROR;
}
// Buffer needs to be large enough to include complete frame
if ((frameSize > inSize) || (totalInSize > (inSize - frameSize))) {
return false;
return SYNCH_LOST_ERROR;
}
totalInSize += frameSize;
}

return true;
return NO_DECODING_ERROR;
}

ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
Expand All @@ -348,10 +353,11 @@ ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
mp3Header info_data;
mp3Header *info = &info_data;

if (!isInputValid(pExt->pInputBuffer, pExt->inputBufferCurrentLength))
errorCode = validate_input(pExt->pInputBuffer, pExt->inputBufferCurrentLength);
if (errorCode != NO_DECODING_ERROR)
{
pExt->outputFrameSize = 0;
return SYNCH_LOST_ERROR;
return errorCode;
}

pVars->inputStream.pBuffer = pExt->pInputBuffer;
Expand Down

0 comments on commit e30837b

Please sign in to comment.