shithub: openh264

Download patch

ref: 41698901c1393a4b8bec3dbdcb4495b7697c9391
parent: ba8e3f29679de6b9e957b001f5faf9686a6ecfc0
parent: 13db7fea7b45dd87b4d6cd9c68837964a3cbfdb2
author: Licai Guo <licaguo@cisco.com>
date: Thu Apr 24 12:47:20 EDT 2014

Merge pull request #743 from huili2/ec_refidx_return

prevent from return if ref_idx is error

--- a/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
@@ -1003,7 +1003,12 @@
       // Security check: iRefIdx should be in range 0 to num_ref_idx_l0_active_minus1, includsive
       // ref to standard section 7.4.5.1. iRefCount[0] is 1 + num_ref_idx_l0_active_minus1.
       if ((iRefIdx < 0) || (iRefIdx >= iRefCount[0]) || (ppRefPic[iRefIdx] == NULL)) { //error ref_idx
-        return ERR_INFO_INVALID_REF_INDEX;
+        if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) {
+          iRefIdx = 0;
+          pCtx->iErrorCode |= dsBitstreamError;
+        } else {
+          return ERR_INFO_INVALID_REF_INDEX;
+        }
       }
     } else {
       WelsLog (pCtx, WELS_LOG_WARNING, "inter parse: iMotionPredFlag = 1 not supported. \n");
@@ -1036,7 +1041,12 @@
       WELS_READ_VERIFY (BsGetTe0 (pBs, iRefCount[0], &uiCode)); //ref_idx_l0[ mbPartIdx ]
       iRefIdx[i] = uiCode;
       if ((iRefIdx[i] < 0) || (iRefIdx[i] >= iRefCount[0]) || (ppRefPic[iRefIdx[i]] == NULL)) { //error ref_idx
-        return ERR_INFO_INVALID_REF_INDEX;
+        if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) {
+          iRefIdx[i] = 0;
+          pCtx->iErrorCode |= dsBitstreamError;
+        } else {
+          return ERR_INFO_INVALID_REF_INDEX;
+        }
       }
     }
     for (i = 0; i < 2; i++) {
@@ -1065,7 +1075,12 @@
         WELS_READ_VERIFY (BsGetTe0 (pBs, iRefCount[0], &uiCode)); //ref_idx_l0[ mbPartIdx ]
         iRefIdx[i] = uiCode;
         if ((iRefIdx[i] < 0) || (iRefIdx[i] >= iRefCount[0]) || (ppRefPic[iRefIdx[i]] == NULL)) { //error ref_idx
-          return ERR_INFO_INVALID_REF_INDEX;
+          if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) {
+            iRefIdx[i] = 0;
+            pCtx->iErrorCode |= dsBitstreamError;
+          } else {
+            return ERR_INFO_INVALID_REF_INDEX;
+          }
         }
       } else {
         WelsLog (pCtx, WELS_LOG_WARNING, "inter parse: iMotionPredFlag = 1 not supported. \n");
@@ -1126,7 +1141,12 @@
           WELS_READ_VERIFY (BsGetTe0 (pBs, iRefCount[0], &uiCode)); //ref_idx_l0[ mbPartIdx ]
           iRefIdx[i] = uiCode;
           if ((iRefIdx[i] < 0) || (iRefIdx[i] >= iRefCount[0]) || (ppRefPic[iRefIdx[i]] == NULL)) { //error ref_idx
-            return ERR_INFO_INVALID_REF_INDEX;
+            if (pCtx->iErrorConMethod != ERROR_CON_DISABLE) {
+              iRefIdx[i] = 0;
+              pCtx->iErrorCode |= dsBitstreamError;
+            } else {
+              return ERR_INFO_INVALID_REF_INDEX;
+            }
           }
 
           pCurDqLayer->pRefIndex[0][iMbXy][uiScan4Idx  ] = pCurDqLayer->pRefIndex[0][iMbXy][uiScan4Idx + 1] =