History

add safety check for bit-reading for headers

Licai Guo committed 12 years ago

Commit a3c38b51 parent e79769f7 files · +676 −488Browse files

Showing the changes to codec/decoder/core/src/decode_slice.cpp (1 of 7 files). Show all

Unified · Split

codec/decoder/core/src/decode_slice.cpp+27−11
@@ -271,7 +271,7 @@ int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { · 270 unmodified lines
271}271}
272 272
273void WelsMbCopy (uint8_t* pDst, int32_t iStrideDst, uint8_t* pSrc, int32_t iStrideSrc,273void WelsMbCopy (uint8_t* pDst, int32_t iStrideDst, uint8_t* pSrc, int32_t iStrideSrc,
274 int32_t iHeight, int32_t iWidth) {274 int32_t iHeight, int32_t iWidth) {
275 int32_t i;275 int32_t i;
276 int32_t iOffsetDst = 0, iOffsetSrc = 0;276 int32_t iOffsetDst = 0, iOffsetSrc = 0;
277 for (i = 0; i < iHeight; i++) {277 for (i = 0; i < iHeight; i++) {
@@ -491,13 +491,16 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 213 unmodified lines
491 int32_t iMbXy = pCurLayer->iMbXyIndex;491 int32_t iMbXy = pCurLayer->iMbXyIndex;
492 int32_t iNMbMode, i;492 int32_t iNMbMode, i;
493 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;493 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
494 uint32_t uiCode;
495 int32_t iCode;
494 496
495 ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);497 ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);
496 498
497 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;499 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
498 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;500 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;
499 501
500 uiMbType = BsGetUe (pBs);502 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_type
503 uiMbType = uiCode;
501 if (uiMbType > 25) {504 if (uiMbType > 25) {
502 return ERR_INFO_INVALID_MB_TYPE;505 return ERR_INFO_INVALID_MB_TYPE;
503 }506 }
@@ -561,7 +564,8 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 57 unmodified lines
561 }564 }
562 565
563 //uiCbp566 //uiCbp
564 uiCbp = BsGetUe (pBs);567 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern
568 uiCbp = uiCode;
565 //G.9.1 Alternative parsing process for coded pBlock pattern569 //G.9.1 Alternative parsing process for coded pBlock pattern
566 if (uiCbp > 47)570 if (uiCbp > 47)
567 return ERR_INFO_INVALID_CBP;571 return ERR_INFO_INVALID_CBP;
@@ -603,7 +607,8 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 35 unmodified lines
603 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {607 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
604 int32_t iQpDelta, iId8x8, iId4x4;608 int32_t iQpDelta, iId8x8, iId4x4;
605 609
606 iQpDelta = BsGetSe (pBs);610 WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta
611 iQpDelta = iCode;
607 612
608 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range613 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
609 return ERR_INFO_INVALID_QP;614 return ERR_INFO_INVALID_QP;
@@ -732,9 +737,11 @@ int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur) { · 122 unmodified lines
732 PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;737 PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;
733 int32_t iBaseModeFlag;738 int32_t iBaseModeFlag;
734 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15739 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15
740 uint32_t uiCode;
735 741
736 if (pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) {742 if (pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) {
737 iBaseModeFlag = BsGetOneBit (pBs);743 WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag
744 iBaseModeFlag = uiCode;
738 } else {745 } else {
739 iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag;746 iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag;
740 }747 }
@@ -769,11 +776,14 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 28 unmodified lines
769 776
770 int32_t iNMbMode, i;777 int32_t iNMbMode, i;
771 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;778 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
779 uint32_t uiCode;
780 int32_t iCode;
772 781
773 ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);782 ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);
774 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23783 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23
775 784
776 uiMbType = BsGetUe (pBs);785 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_type
786 uiMbType = uiCode;
777 if (uiMbType < 5) { //inter MB type787 if (uiMbType < 5) { //inter MB type
778 int16_t iMotionVector[LIST_A][30][MV_A];788 int16_t iMotionVector[LIST_A][30][MV_A];
779 789
@@ -785,7 +795,8 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 5 unmodified lines
785 }795 }
786 796
787 if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) {797 if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) {
788 pCurLayer->pResidualPredFlag[iMbXy] = BsGetOneBit (pBs);798 WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //residual_prediction_flag
799 pCurLayer->pResidualPredFlag[iMbXy] = uiCode;
789 } else {800 } else {
790 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;801 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;
791 }802 }
@@ -882,7 +893,8 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 90 unmodified lines
882 }893 }
883 894
884 if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) {895 if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) {
885 uiCbp = BsGetUe (pBs);896 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern
897 uiCbp = uiCode;
886 {898 {
887 if (uiCbp > 47)899 if (uiCbp > 47)
888 return ERR_INFO_INVALID_CBP;900 return ERR_INFO_INVALID_CBP;
@@ -918,7 +930,8 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 29 unmodified lines
918 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {930 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
919 int32_t iQpDelta, iId8x8, iId4x4;931 int32_t iQpDelta, iId8x8, iId4x4;
920 932
921 iQpDelta = BsGetSe (pBs);933 WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta
934 iQpDelta = iCode;
922 935
923 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range936 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
924 return ERR_INFO_INVALID_QP;937 return ERR_INFO_INVALID_QP;
@@ -1048,9 +1061,11 @@ int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur) { · 123 unmodified lines
1048 int32_t iMbXy = pCurLayer->iMbXyIndex;1061 int32_t iMbXy = pCurLayer->iMbXyIndex;
1049 int32_t iBaseModeFlag, i;1062 int32_t iBaseModeFlag, i;
1050 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.151063 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15
1064 uint32_t uiCode;
1051 1065
1052 if (-1 == pSlice->iMbSkipRun) {1066 if (-1 == pSlice->iMbSkipRun) {
1053 pSlice->iMbSkipRun = BsGetUe (pBs);1067 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_skip_run
1068 pSlice->iMbSkipRun = uiCode;
1054 if (-1 == pSlice->iMbSkipRun) {1069 if (-1 == pSlice->iMbSkipRun) {
1055 return -1;1070 return -1;
1056 }1071 }
@@ -1094,7 +1109,8 @@ int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur) { · 37 unmodified lines
1094 }1109 }
1095 1110
1096 if (pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) {1111 if (pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) {
1097 iBaseModeFlag = BsGetOneBit (pBs);1112 WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag
1113 iBaseModeFlag = uiCode;
1098 } else {1114 } else {
1099 iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag;1115 iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag;
1100 }1116 }

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