History

Add protection for memcpy overlap

Haibo Zhu committed 11 years ago

Commit 6b4912c1 parent 6b503842 files · +15 −6Browse files

Showing the changes to codec/decoder (2 of 2 files). Show all

Unified · Split

2 files
  1. codec/decoder/core/src/error_concealment.cpp +8 −1
  2. codec/decoder/core/src/manage_dec_ref.cpp +7 −5
codec/decoder/core/src/error_concealment.cpp+8−1
@@ -93,6 +93,8 @@ void DoErrorConFrameCopy (PWelsDecoderContext pCtx) { · 92 unmodified lines
93 memset (pDstPic->pData[0], 128, uiHeightInPixelY * iStrideY);93 memset (pDstPic->pData[0], 128, uiHeightInPixelY * iStrideY);
94 memset (pDstPic->pData[1], 128, (uiHeightInPixelY >> 1) * iStrideUV);94 memset (pDstPic->pData[1], 128, (uiHeightInPixelY >> 1) * iStrideUV);
95 memset (pDstPic->pData[2], 128, (uiHeightInPixelY >> 1) * iStrideUV);95 memset (pDstPic->pData[2], 128, (uiHeightInPixelY >> 1) * iStrideUV);
96 } else if (pSrcPic == pDstPic) {
97 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConFrameCopy()::EC memcpy overlap.");
96 } else { //has ref pic here98 } else { //has ref pic here
97 memcpy (pDstPic->pData[0], pSrcPic->pData[0], uiHeightInPixelY * iStrideY);99 memcpy (pDstPic->pData[0], pSrcPic->pData[0], uiHeightInPixelY * iStrideY);
98 memcpy (pDstPic->pData[1], pSrcPic->pData[1], (uiHeightInPixelY >> 1) * iStrideUV);100 memcpy (pDstPic->pData[1], pSrcPic->pData[1], (uiHeightInPixelY >> 1) * iStrideUV);
@@ -117,6 +119,10 @@ void DoErrorConSliceCopy (PWelsDecoderContext pCtx) { · 18 unmodified lines
117 uint8_t* pSrcData, *pDstData;119 uint8_t* pSrcData, *pDstData;
118 uint32_t iSrcStride; // = pSrcPic->iLinesize[0];120 uint32_t iSrcStride; // = pSrcPic->iLinesize[0];
119 uint32_t iDstStride = pDstPic->iLinesize[0];121 uint32_t iDstStride = pDstPic->iLinesize[0];
122 if (pSrcPic == pDstPic) {
123 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConSliceCopy()::EC memcpy overlap.");
124 return;
125 }
120 for (int32_t iMbY = 0; iMbY < iMbHeight; ++iMbY) {126 for (int32_t iMbY = 0; iMbY < iMbHeight; ++iMbY) {
121 for (int32_t iMbX = 0; iMbX < iMbWidth; ++iMbX) {127 for (int32_t iMbX = 0; iMbX < iMbWidth; ++iMbX) {
122 iMbXyIndex = iMbY * iMbWidth + iMbX;128 iMbXyIndex = iMbY * iMbWidth + iMbX;
@@ -384,7 +390,8 @@ void DoErrorConSliceMVCopy (PWelsDecoderContext pCtx) { · 261 unmodified lines
384 sMCRefMem.iPicHeight = pDstPic->iHeightInPixel;390 sMCRefMem.iPicHeight = pDstPic->iHeightInPixel;
385 if (pDstPic == pSrcPic) {391 if (pDstPic == pSrcPic) {
386 // output error info, EC will be ignored in DoMbECMvCopy392 // output error info, EC will be ignored in DoMbECMvCopy
387 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "DoErrorConSliceMVCopy()::pPreviousPic and pDec use same buffer, ignored.");393 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "DoErrorConSliceMVCopy()::EC memcpy overlap.");
394 return;
388 }395 }
389 }396 }
390 397
codec/decoder/core/src/manage_dec_ref.cpp+7−5
@@ -131,14 +131,16 @@ int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) { · 130 unmodified lines
131 bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)131 bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)
132 && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);132 && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);
133 133
134 if (bCopyPrevious) {134 if (!bCopyPrevious) {
135 memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);
136 memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
137 memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
138 } else {
139 memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);135 memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);
140 memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);136 memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
141 memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2);137 memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
138 } else if (pRef == pCtx->pPreviousDecodedPictureInDpb) {
139 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap.");
140 } else {
141 memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);
142 memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
143 memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
142 }144 }
143 pRef->iFrameNum = 0;145 pRef->iFrameNum = 0;
144 pRef->iFramePoc = 0;146 pRef->iFramePoc = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t