Skip to content

Commit 9e1f179

Browse files
author
HaiboZhu
committed
Merge pull request #2171 from HaiboZhu/Bugfix_entropy_decoding_upper_check_v1.5
Add protection for unsigned int output for openh264v1.5
2 parents 32c51ec + fdc7130 commit 9e1f179

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

codec/decoder/core/inc/dec_golomb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static inline uint32_t BsGetUe (PBitStringAux pBs, uint32_t* pCode) {
179179
DUMP_BITS (pBs->uiCurBits, pBs->pCurBuf, pBs->iLeftBits, iLeadingZeroBits, iAllowedBytes, iReadBytes);
180180
}
181181

182-
*pCode = ((1 << iLeadingZeroBits) - 1 + iValue);
182+
*pCode = ((1u << iLeadingZeroBits) - 1 + iValue);
183183
return ERR_NONE;
184184
}
185185

codec/decoder/core/src/cabac_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ int32_t DecodeExpBypassCabac (PWelsCabacDecEngine pDecEngine, int32_t iCount, ui
273273
iSymTmp += (1 << iCount);
274274
++iCount;
275275
}
276-
} while (uiCode != 0 && iCount != 31);
277-
if (iCount == 31) {
276+
} while (uiCode != 0 && iCount != 16);
277+
if (iCount == 16) {
278278
return ERR_CABAC_UNEXPECTED_VALUE;
279279
}
280280

codec/decoder/core/src/decoder_core.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,25 +389,25 @@ int32_t ParseDecRefPicMarking (PWelsDecoderContext pCtx, PBitStringAux pBs, PSli
389389
int32_t iIdx = 0;
390390
do {
391391
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //memory_management_control_operation
392-
const int32_t kiMmco = uiCode;
392+
const uint32_t kuiMmco = uiCode;
393393

394-
kpRefMarking->sMmcoRef[iIdx].uiMmcoType = kiMmco;
395-
if (kiMmco == MMCO_END)
394+
kpRefMarking->sMmcoRef[iIdx].uiMmcoType = kuiMmco;
395+
if (kuiMmco == MMCO_END)
396396
break;
397397

398-
if (kiMmco == MMCO_SHORT2UNUSED || kiMmco == MMCO_SHORT2LONG) {
398+
if (kuiMmco == MMCO_SHORT2UNUSED || kuiMmco == MMCO_SHORT2LONG) {
399399
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //difference_of_pic_nums_minus1
400400
kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum = 1 + uiCode;
401401
kpRefMarking->sMmcoRef[iIdx].iShortFrameNum = (pSh->iFrameNum - kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum) & ((
402402
1 << pSps->uiLog2MaxFrameNum) - 1);
403-
} else if (kiMmco == MMCO_LONG2UNUSED) {
403+
} else if (kuiMmco == MMCO_LONG2UNUSED) {
404404
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //long_term_pic_num
405405
kpRefMarking->sMmcoRef[iIdx].uiLongTermPicNum = uiCode;
406406
}
407-
if (kiMmco == MMCO_SHORT2LONG || kiMmco == MMCO_LONG) {
407+
if (kuiMmco == MMCO_SHORT2LONG || kuiMmco == MMCO_LONG) {
408408
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //long_term_frame_idx
409409
kpRefMarking->sMmcoRef[iIdx].iLongTermFrameIdx = uiCode;
410-
} else if (kiMmco == MMCO_SET_MAX_LONG) {
410+
} else if (kuiMmco == MMCO_SET_MAX_LONG) {
411411
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //max_long_term_frame_idx_plus1
412412
kpRefMarking->sMmcoRef[iIdx].iMaxLongTermFrameIdx = -1 + uiCode;
413413
}
@@ -690,6 +690,8 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co
690690

691691
// first_mb_in_slice
692692
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //first_mb_in_slice
693+
WELS_CHECK_SE_UPPER_ERROR (uiCode, 36863u, "first_mb_in_slice", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER,
694+
ERR_INFO_INVALID_FIRST_MB_IN_SLICE));
693695
pSliceHead->iFirstMbInSlice = uiCode;
694696

695697
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //slice_type
@@ -721,13 +723,10 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co
721723
pSliceHead->eSliceType = static_cast <EWelsSliceType> (uiSliceType);
722724

723725
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //pic_parameter_set_id
726+
WELS_CHECK_SE_UPPER_ERROR (uiCode, MAX_PPS_COUNT, "iPpsId out of range", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER,
727+
ERR_INFO_PPS_ID_OVERFLOW));
724728
iPpsId = uiCode;
725729

726-
if (iPpsId >= MAX_PPS_COUNT) {
727-
WelsLog (pLogCtx, WELS_LOG_WARNING, "iPpsId out of range");
728-
return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_PPS_ID_OVERFLOW);
729-
}
730-
731730
//add check PPS available here
732731
if (pCtx->bPpsAvailFlags[iPpsId] == false) {
733732
pCtx->sDecoderStatistics.iPpsReportErrorNum++;
@@ -939,9 +938,8 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co
939938
if (pPps->bEntropyCodingModeFlag) {
940939
if (pSliceHead->eSliceType != I_SLICE && pSliceHead->eSliceType != SI_SLICE) {
941940
WELS_READ_VERIFY (BsGetUe (pBs, &uiCode));
941+
WELS_CHECK_SE_UPPER_ERROR (uiCode, SLICE_HEADER_CABAC_INIT_IDC_MAX, "cabac_init_idc", ERR_INFO_INVALID_CABAC_INIT_IDC);
942942
pSliceHead->iCabacInitIdc = uiCode;
943-
WELS_CHECK_SE_UPPER_ERROR (pSliceHead->iCabacInitIdc, SLICE_HEADER_CABAC_INIT_IDC_MAX, "cabac_init_idc",
944-
ERR_INFO_INVALID_CABAC_INIT_IDC);
945943
} else
946944
pSliceHead->iCabacInitIdc = 0;
947945
}

0 commit comments

Comments
 (0)