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/core/src/manage_dec_ref.cpp (1 of 2 files). Show all

Unified · Split

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
131131 bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)
132132 && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);
133133
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 {
134+ if (!bCopyPrevious) {
139135 memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);
140136 memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
141137 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);
142144 }
143145 pRef->iFrameNum = 0;
144146 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