Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 5 files). Show all
Unified · Split
| @@ -155,7 +155,7 @@ int32_t ParseRefPicListReordering (PBitStringAux pBs, PSliceHeader pSh) { · 154 unmodified lines | ||
| 155 | 155 | int32_t iList = 0; |
| 156 | 156 | const ESliceType keSt = pSh->eSliceType; |
| 157 | 157 | PRefPicListReorderSyn pRefPicListReordering = &pSh->pRefPicListReordering; |
| 158 | − | |
| 158 | + PSps pSps = pSh->pSps; | |
| 159 | 159 | if (keSt == I_SLICE || keSt == SI_SLICE) |
| 160 | 160 | return ERR_NONE; |
| 161 | 161 | |
| @@ -166,7 +166,7 @@ int32_t ParseRefPicListReordering (PBitStringAux pBs, PSliceHeader pSh) { · 4 unmodified lines | ||
| 166 | 166 | if (pRefPicListReordering->bRefPicListReorderingFlag[iList]) { |
| 167 | 167 | int32_t iIdx = 0; |
| 168 | 168 | do { |
| 169 | − const uint8_t kuiIdc = BsGetUe (pBs); | |
| 169 | + const uint32_t kuiIdc = BsGetUe (pBs); | |
| 170 | 170 | |
| 171 | 171 | //Fixed the referrence list reordering crash issue.(fault kIdc value > 3 case)--- |
| 172 | 172 | if ((iIdx >= MAX_REF_PIC_COUNT) || (kuiIdc > 3)) { |
| @@ -180,7 +180,12 @@ int32_t ParseRefPicListReordering (PBitStringAux pBs, PSliceHeader pSh) { · 7 unmodified lines | ||
| 180 | 180 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING); |
| 181 | 181 | |
| 182 | 182 | if (kuiIdc == 0 || kuiIdc == 1) { |
| 183 | − pRefPicListReordering->sReorderingSyn[iList][iIdx].uiAbsDiffPicNumMinus1 = BsGetUe (pBs); // uiAbsDiffPicNumMinus1 | |
| 183 | + // abs_diff_pic_num_minus1 should be in range 0 to MaxPicNum-1, MaxPicNum is derived as | |
| 184 | + // 2^(4+log2_max_frame_num_minus4) | |
| 185 | + uint32_t uiTmp = BsGetUe (pBs); | |
| 186 | + WELS_CHECK_SE_UPPER_ERROR_NOLOG (uiTmp, (1 << pSps->uiLog2MaxFrameNum), "abs_diff_pic_num_minus1", | |
| 187 | + GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING)); | |
| 188 | + pRefPicListReordering->sReorderingSyn[iList][iIdx].uiAbsDiffPicNumMinus1 = uiTmp; // uiAbsDiffPicNumMinus1 | |
| 184 | 189 | } else if (kuiIdc == 2) { |
| 185 | 190 | pRefPicListReordering->sReorderingSyn[iList][iIdx].uiLongTermPicNum = BsGetUe (pBs); |
| 186 | 191 | } |
| @@ -199,7 +204,7 @@ int32_t ParseRefPicListReordering (PBitStringAux pBs, PSliceHeader pSh) { · 12 unmodified lines | ||
| 199 | 204 | int32_t ParseDecRefPicMarking (PWelsDecoderContext pCtx, PBitStringAux pBs, PSliceHeader pSh, PSps pSps, |
| 200 | 205 | const bool kbIdrFlag) { |
| 201 | 206 | PRefPicMarking const kpRefMarking = &pSh->sRefMarking; |
| 202 | − | |
| 207 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 203 | 208 | if (kbIdrFlag) { |
| 204 | 209 | kpRefMarking->bNoOutputOfPriorPicsFlag = !!BsGetOneBit (pBs); |
| 205 | 210 | kpRefMarking->bLongTermRefFlag = !!BsGetOneBit (pBs); |
| @@ -447,6 +452,13 @@ int32_t CheckSpsId (PWelsDecoderContext pCtx, PSubsetSps* ppSubsetSps, PSps* ppS · 241 unmodified lines | ||
| 447 | 452 | } |
| 448 | 453 | |
| 449 | 454 | #endif |
| 455 | + | |
| 456 | +#define SLICE_HEADER_IDR_PIC_ID_MAX 65535 | |
| 457 | +#define SLICE_HEADER_REDUNDANT_PIC_CNT_MAX 127 | |
| 458 | +#define SLICE_HEADER_ALPHAC0_BETA_OFFSET_MIN -12 | |
| 459 | +#define SLICE_HEADER_ALPHAC0_BETA_OFFSET_MAX 12 | |
| 460 | +#define SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MIN -12 | |
| 461 | +#define SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MAX 12 | |
| 450 | 462 | /* |
| 451 | 463 | * decode_slice_header_avc |
| 452 | 464 | * Parse slice header of bitstream in avc for storing data structure |
| @@ -465,6 +477,7 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 12 unmodified lines | ||
| 465 | 477 | int32_t iRet = ERR_NONE; |
| 466 | 478 | uint8_t uiSliceType = 0; |
| 467 | 479 | uint8_t uiQualityId = BASE_QUALITY_ID; |
| 480 | + uint32_t uiTmp; | |
| 468 | 481 | bool bIdrFlag = false; |
| 469 | 482 | bool bSgChangeCycleInvolved = false; // involved slice group change cycle ? |
| 470 | 483 | |
| @@ -489,6 +502,7 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 18 unmodified lines | ||
| 489 | 502 | |
| 490 | 503 | kpCurNal->sNalData.sVclNal.bSliceHeaderExtFlag = kbExtensionFlag; |
| 491 | 504 | |
| 505 | + // first_mb_in_slice | |
| 492 | 506 | pSliceHead->iFirstMbInSlice = BsGetUe (pBs); |
| 493 | 507 | |
| 494 | 508 | uiSliceType = BsGetUe (pBs); |
| @@ -500,7 +514,7 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 5 unmodified lines | ||
| 500 | 514 | if (uiSliceType > 4) |
| 501 | 515 | uiSliceType -= 5; |
| 502 | 516 | |
| 503 | − if((eNalType == NAL_UNIT_CODED_SLICE_IDR) && (uiSliceType != 2)){ | |
| 517 | + if ((eNalType == NAL_UNIT_CODED_SLICE_IDR) && (uiSliceType != 2)) { | |
| 504 | 518 | WelsLog (pCtx, WELS_LOG_WARNING, "Invalid slice type(%d) in IDR picture. \n", uiSliceType); |
| 505 | 519 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE); |
| 506 | 520 | } |
| @@ -566,6 +580,9 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 59 unmodified lines | ||
| 566 | 580 | WelsLog (pCtx, WELS_LOG_WARNING, "non existing SPS referenced\n"); |
| 567 | 581 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS); |
| 568 | 582 | } |
| 583 | + // check first_mb_in_slice | |
| 584 | + WELS_CHECK_SE_UPPER_ERROR ((uint32_t) (pSliceHead->iFirstMbInSlice), pSps->uiTotalMbCount, "first_mb_in_slice", | |
| 585 | + GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_FIRST_MB_IN_SLICE)); | |
| 569 | 586 | pSliceHead->iFrameNum = BsGetBits (pBs, pSps->uiLog2MaxFrameNum); |
| 570 | 587 | |
| 571 | 588 | pSliceHead->bFieldPicFlag = false; |
| @@ -584,7 +601,11 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 12 unmodified lines | ||
| 584 | 601 | pSliceHead->iFrameNum); |
| 585 | 602 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_FRAME_NUM); |
| 586 | 603 | } |
| 587 | − pSliceHead->uiIdrPicId = BsGetUe (pBs); /* uiIdrPicId */ | |
| 604 | + uiTmp = BsGetUe (pBs); | |
| 605 | + // standard 7.4.3 idr_pic_id should be in range 0 to 65535, inclusive. | |
| 606 | + WELS_CHECK_SE_UPPER_ERROR (uiTmp, SLICE_HEADER_IDR_PIC_ID_MAX, "idr_pic_id", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, | |
| 607 | + ERR_INFO_INVALID_IDR_PIC_ID)); | |
| 608 | + pSliceHead->uiIdrPicId = uiTmp; /* uiIdrPicId */ | |
| 588 | 609 | #ifdef LONG_TERM_REF |
| 589 | 610 | pCtx->uiCurIdrPicId = pSliceHead->uiIdrPicId; |
| 590 | 611 | #endif |
| @@ -606,7 +627,11 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 15 unmodified lines | ||
| 606 | 627 | |
| 607 | 628 | pSliceHead->iRedundantPicCnt = 0; |
| 608 | 629 | if (pPps->bRedundantPicCntPresentFlag) { |
| 609 | − pSliceHead->iRedundantPicCnt = BsGetUe (pBs); | |
| 630 | + uiTmp = BsGetUe (pBs); | |
| 631 | + // standard section 7.4.3, redundant_pic_cnt should be in range 0 to 127, inclusive. | |
| 632 | + WELS_CHECK_SE_UPPER_ERROR (uiTmp, SLICE_HEADER_REDUNDANT_PIC_CNT_MAX, "redundant_pic_cnt", | |
| 633 | + GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REDUNDANT_PIC_CNT)); | |
| 634 | + pSliceHead->iRedundantPicCnt = uiTmp; | |
| 610 | 635 | } |
| 611 | 636 | |
| 612 | 637 | //set defaults, might be overriden a few line later |
| @@ -695,7 +720,13 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 82 unmodified lines | ||
| 695 | 720 | } |
| 696 | 721 | if (pSliceHead->uiDisableDeblockingFilterIdc != 1) { |
| 697 | 722 | pSliceHead->iSliceAlphaC0Offset = BsGetSe (pBs) * 2; // slice_alpha_c0_offset_div2 |
| 723 | + WELS_CHECK_SE_BOTH_ERROR (pSliceHead->iSliceAlphaC0Offset, SLICE_HEADER_ALPHAC0_BETA_OFFSET_MIN, | |
| 724 | + SLICE_HEADER_ALPHAC0_BETA_OFFSET_MAX, "slice_alpha_c0_offset_div2 * 2", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, | |
| 725 | + ERR_INFO_INVALID_SLICE_ALPHA_C0_OFFSET_DIV2)); | |
| 698 | 726 | pSliceHead->iSliceBetaOffset = BsGetSe (pBs) * 2; // iSliceBetaOffset |
| 727 | + WELS_CHECK_SE_BOTH_ERROR (pSliceHead->iSliceBetaOffset, SLICE_HEADER_ALPHAC0_BETA_OFFSET_MIN, | |
| 728 | + SLICE_HEADER_ALPHAC0_BETA_OFFSET_MAX, "slice_beta_offset_div2 * 2", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, | |
| 729 | + ERR_INFO_INVALID_SLICE_BETA_OFFSET_DIV2)); | |
| 699 | 730 | } |
| 700 | 731 | } |
| 701 | 732 | |
| @@ -731,7 +762,14 @@ int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, co · 29 unmodified lines | ||
| 731 | 762 | } |
| 732 | 763 | if (pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc != 1) { |
| 733 | 764 | pSliceHeadExt->iInterLayerSliceAlphaC0Offset = BsGetSe (pBs) << 1; |
| 765 | + WELS_CHECK_SE_BOTH_ERROR (pSliceHeadExt->iInterLayerSliceAlphaC0Offset, | |
| 766 | + SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MIN, SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MAX, | |
| 767 | + "inter_layer_alpha_c0_offset_div2 * 2", GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, | |
| 768 | + ERR_INFO_INVALID_SLICE_ALPHA_C0_OFFSET_DIV2)); | |
| 734 | 769 | pSliceHeadExt->iInterLayerSliceBetaOffset = BsGetSe (pBs) << 1; |
| 770 | + WELS_CHECK_SE_BOTH_ERROR (pSliceHeadExt->iInterLayerSliceBetaOffset, SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MIN, | |
| 771 | + SLICE_HEADER_INTER_LAYER_ALPHAC0_BETA_OFFSET_MAX, "inter_layer_slice_beta_offset_div2 * 2", | |
| 772 | + GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_BETA_OFFSET_DIV2)); | |
| 735 | 773 | } |
| 736 | 774 | } |
| 737 | 775 | |