Add protection for emulation prevention bytes and profile_id

This commit is contained in:
unknown 2015-11-23 19:26:28 +08:00 committed by Haibo Zhu
parent 404315ab19
commit cc6b409f12
2 changed files with 24 additions and 5 deletions

View File

@ -920,6 +920,12 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW
WELS_READ_VERIFY (BsGetBits (pBs, 8, &uiCode)); //profile_idc
uiProfileIdc = uiCode;
if (uiProfileIdc != PRO_BASELINE && uiProfileIdc != PRO_MAIN && uiProfileIdc != PRO_SCALABLE_BASELINE
&& uiProfileIdc != PRO_SCALABLE_HIGH
&& uiProfileIdc != PRO_EXTENDED && uiProfileIdc != PRO_HIGH) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "SPS ID can not be supported!\n");
return false;
}
WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //constraint_set0_flag
bConstraintSetFlags[0] = !!uiCode;
WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //constraint_set1_flag

View File

@ -662,11 +662,23 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in
//0x03 removal and extract all of NAL Unit from current raw data
pDstNal = pRawData->pCurPos;
bool bNalStartBytes = false;
while (iSrcConsumed < iSrcLength) {
if ((2 + iSrcConsumed < iSrcLength) &&
(0 == LD16 (pSrcNal + iSrcIdx)) &&
((pSrcNal[2 + iSrcIdx] == 0x03) || (pSrcNal[2 + iSrcIdx] == 0x01))) {
if (pSrcNal[2 + iSrcIdx] == 0x03) {
if ((2 + iSrcConsumed < iSrcLength) && (0 == LD16 (pSrcNal + iSrcIdx)) && (pSrcNal[2 + iSrcIdx] <= 0x03)) {
if (bNalStartBytes && (pSrcNal[2 + iSrcIdx] != 0x00 && pSrcNal[2 + iSrcIdx] != 0x01)) {
pCtx->iErrorCode |= dsBitstreamError;
return pCtx->iErrorCode;
}
if (pSrcNal[2 + iSrcIdx] == 0x02) {
pCtx->iErrorCode |= dsBitstreamError;
return pCtx->iErrorCode;
} else if (pSrcNal[2 + iSrcIdx] == 0x00) {
pDstNal[iDstIdx++] = pSrcNal[iSrcIdx++];
iSrcConsumed++;
bNalStartBytes = true;
} else if (pSrcNal[2 + iSrcIdx] == 0x03) {
if ((3 + iSrcConsumed < iSrcLength) && pSrcNal[3 + iSrcIdx] > 0x03) {
pCtx->iErrorCode |= dsBitstreamError;
return pCtx->iErrorCode;
@ -676,7 +688,8 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in
iSrcIdx += 3;
iSrcConsumed += 3;
}
} else {
} else { // 0x01
bNalStartBytes = false;
iConsumedBytes = 0;
pDstNal[iDstIdx] = pDstNal[iDstIdx + 1] = pDstNal[iDstIdx + 2] = pDstNal[iDstIdx + 3] =