Add protection for memcpy overlap

This commit is contained in:
Haibo Zhu 2015-08-05 09:23:32 +08:00
parent 6b503843ec
commit 6b4912c716
2 changed files with 15 additions and 6 deletions

View File

@ -93,6 +93,8 @@ void DoErrorConFrameCopy (PWelsDecoderContext pCtx) {
memset (pDstPic->pData[0], 128, uiHeightInPixelY * iStrideY);
memset (pDstPic->pData[1], 128, (uiHeightInPixelY >> 1) * iStrideUV);
memset (pDstPic->pData[2], 128, (uiHeightInPixelY >> 1) * iStrideUV);
} else if (pSrcPic == pDstPic) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConFrameCopy()::EC memcpy overlap.");
} else { //has ref pic here
memcpy (pDstPic->pData[0], pSrcPic->pData[0], uiHeightInPixelY * iStrideY);
memcpy (pDstPic->pData[1], pSrcPic->pData[1], (uiHeightInPixelY >> 1) * iStrideUV);
@ -117,6 +119,10 @@ void DoErrorConSliceCopy (PWelsDecoderContext pCtx) {
uint8_t* pSrcData, *pDstData;
uint32_t iSrcStride; // = pSrcPic->iLinesize[0];
uint32_t iDstStride = pDstPic->iLinesize[0];
if (pSrcPic == pDstPic) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConSliceCopy()::EC memcpy overlap.");
return;
}
for (int32_t iMbY = 0; iMbY < iMbHeight; ++iMbY) {
for (int32_t iMbX = 0; iMbX < iMbWidth; ++iMbX) {
iMbXyIndex = iMbY * iMbWidth + iMbX;
@ -384,7 +390,8 @@ void DoErrorConSliceMVCopy (PWelsDecoderContext pCtx) {
sMCRefMem.iPicHeight = pDstPic->iHeightInPixel;
if (pDstPic == pSrcPic) {
// output error info, EC will be ignored in DoMbECMvCopy
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "DoErrorConSliceMVCopy()::pPreviousPic and pDec use same buffer, ignored.");
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConSliceMVCopy()::EC memcpy overlap.");
return;
}
}

View File

@ -131,14 +131,16 @@ int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) {
bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)
&& (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);
if (bCopyPrevious) {
memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);
memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
} else {
if (!bCopyPrevious) {
memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);
memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
} else if (pRef == pCtx->pPreviousDecodedPictureInDpb) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap.");
} else {
memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);
memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
}
pRef->iFrameNum = 0;
pRef->iFramePoc = 0;