Skip to content

Commit

Permalink
codecs: check OMX buffer size before use in (h263|h264)dec
Browse files Browse the repository at this point in the history
Bug: 27833616
Ticket: CYNGNOS-2707

Change-Id: I0fd599b3da431425d89236ffdd9df423c11947c0
(cherry picked from commit 3a3c3f7)
  • Loading branch information
Wonsik Kim authored and Jessica Wagantall committed Jun 13, 2016
1 parent 47f4eea commit 73d0aa2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
10 changes: 9 additions & 1 deletion media/libstagefright/codecs/m4v_h263/dec/SoftMPEG4.cpp
Expand Up @@ -222,6 +222,14 @@ void SoftMPEG4::onQueueFilled(OMX_U32 /* portIndex */) {
int32_t bufferSize = inHeader->nFilledLen;
int32_t tmp = bufferSize;

OMX_U32 frameSize = (mWidth * mHeight * 3) / 2;
if (outHeader->nAllocLen < frameSize) {
android_errorWriteLog(0x534e4554, "27833616");
ALOGE("Insufficient output buffer size");
notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
mSignalledError = true;
return;
}
// The PV decoder is lying to us, sometimes it'll claim to only have
// consumed a subset of the buffer when it clearly consumed all of it.
// ignore whatever it says...
Expand Down Expand Up @@ -265,7 +273,7 @@ void SoftMPEG4::onQueueFilled(OMX_U32 /* portIndex */) {
++mInputBufferCount;

outHeader->nOffset = 0;
outHeader->nFilledLen = (mWidth * mHeight * 3) / 2;
outHeader->nFilledLen = frameSize;

List<BufferInfo *>::iterator it = outQueue.begin();
while ((*it)->mHeader != outHeader) {
Expand Down
26 changes: 21 additions & 5 deletions media/libstagefright/codecs/on2/h264dec/SoftAVC.cpp
Expand Up @@ -202,7 +202,12 @@ void SoftAVC::onQueueFilled(OMX_U32 /* portIndex */) {
}

if (mFirstPicture && !outQueue.empty()) {
drainOneOutputBuffer(mFirstPictureId, mFirstPicture);
if (!drainOneOutputBuffer(mFirstPictureId, mFirstPicture)) {
ALOGE("Drain failed");
notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
mSignalledError = true;
return;
}
delete[] mFirstPicture;
mFirstPicture = NULL;
mFirstPictureId = -1;
Expand Down Expand Up @@ -242,15 +247,20 @@ void SoftAVC::saveFirstOutputBuffer(int32_t picId, uint8_t *data) {
memcpy(mFirstPicture, data, pictureSize);
}

void SoftAVC::drainOneOutputBuffer(int32_t picId, uint8_t* data) {
bool SoftAVC::drainOneOutputBuffer(int32_t picId, uint8_t* data) {
List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
BufferInfo *outInfo = *outQueue.begin();
outQueue.erase(outQueue.begin());
OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
OMX_U32 frameSize = mWidth * mHeight * 3 / 2;
if (outHeader->nAllocLen - outHeader->nOffset < frameSize) {
android_errorWriteLog(0x534e4554, "27833616");
return false;
}
outQueue.erase(outQueue.begin());
OMX_BUFFERHEADERTYPE *header = mPicToHeaderMap.valueFor(picId);
outHeader->nTimeStamp = header->nTimeStamp;
outHeader->nFlags = header->nFlags;
outHeader->nFilledLen = mWidth * mHeight * 3 / 2;
outHeader->nFilledLen = frameSize;

uint8_t *dst = outHeader->pBuffer + outHeader->nOffset;
const uint8_t *srcY = data;
Expand All @@ -265,6 +275,7 @@ void SoftAVC::drainOneOutputBuffer(int32_t picId, uint8_t* data) {
delete header;
outInfo->mOwnedByUs = false;
notifyFillBufferDone(outHeader);
return true;
}

void SoftAVC::drainAllOutputBuffers(bool eos) {
Expand All @@ -277,7 +288,12 @@ void SoftAVC::drainAllOutputBuffers(bool eos) {
mHandle, &decodedPicture, eos /* flush */)) {
int32_t picId = decodedPicture.picId;
uint8_t *data = (uint8_t *) decodedPicture.pOutputPicture;
drainOneOutputBuffer(picId, data);
if (!drainOneOutputBuffer(picId, data)) {
ALOGE("Drain failed");
notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
mSignalledError = true;
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion media/libstagefright/codecs/on2/h264dec/SoftAVC.h
Expand Up @@ -71,7 +71,7 @@ struct SoftAVC : public SoftVideoDecoderOMXComponent {

status_t initDecoder();
void drainAllOutputBuffers(bool eos);
void drainOneOutputBuffer(int32_t picId, uint8_t *data);
bool drainOneOutputBuffer(int32_t picId, uint8_t *data);
void saveFirstOutputBuffer(int32_t pidId, uint8_t *data);
CropSettingsMode handleCropParams(const H264SwDecInfo& decInfo);

Expand Down

0 comments on commit 73d0aa2

Please sign in to comment.