Skip to content

Commit

Permalink
Fix frame-decode errors. (#3723)
Browse files Browse the repository at this point in the history
* Enable ReorderRefList2() which was added by the commit 1b8caef.

... and fix trivial issue of that function. This solves the some
frame decode error.

* Add workaround for frame decode error due to emulation byte.

* Fix a bug which seems due to a typo in WelsReorderRefList2()

This fixes the fuzzing test failure.

Addresses: #3772
  • Loading branch information
tyan0 authored Aug 5, 2024
1 parent e0bbb7f commit fa6d099
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions codec/decoder/core/src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,13 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in
bNalStartBytes = true;
} else if (pSrcNal[2 + iSrcIdx] == 0x03) {
if ((3 + iSrcConsumed < iSrcLength) && pSrcNal[3 + iSrcIdx] > 0x03) {
pCtx->iErrorCode |= dsBitstreamError;
return pCtx->iErrorCode;
/* Just skip */
} else {
ST16 (pDstNal + iDstIdx, 0);
iDstIdx += 2;
iSrcIdx += 3;
iSrcConsumed += 3;
}
iSrcIdx += 3;
iSrcConsumed += 3;
} else { // 0x01
bNalStartBytes = false;

Expand Down
2 changes: 1 addition & 1 deletion codec/decoder/core/src/decoder_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t
} else
iRet = WelsInitRefList (pCtx, iPoc);
if ((pCtx->eSliceType != I_SLICE && pCtx->eSliceType != SI_SLICE)) {
#if 0
#if 1
if (pCtx->pSps->uiProfileIdc != 66 && pCtx->pPps->bEntropyCodingModeFlag)
iRet = WelsReorderRefList2 (pCtx);
else
Expand Down
7 changes: 5 additions & 2 deletions codec/decoder/core/src/manage_dec_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) {
int32_t i = 0;
int32_t j = 0;
int32_t k = 0;
int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;
int32_t iMaxRefIdx = pCtx->iPicQueueNumber;
if (iMaxRefIdx > MAX_REF_PIC_COUNT) {
iMaxRefIdx = MAX_REF_PIC_COUNT;
}
const int32_t iCurFrameNum = pSliceHeader->iFrameNum;
const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;
int32_t iListCount = 1;
Expand Down Expand Up @@ -563,7 +566,7 @@ int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) {
k = iCount;
for (j = k; j <= iRefCount; j++) {
if (ppRefList[j] != NULL) {
if (!ppRefList[j]->bIsLongRef || ppLongRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum)
if (!ppRefList[j]->bIsLongRef || ppRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum)
ppRefList[k++] = ppRefList[j];
}
}
Expand Down

0 comments on commit fa6d099

Please sign in to comment.