shithub: openh264

Download patch

ref: 518a317201d6bea5e5f61669d154e059f662a60c
parent: c1f66ea21ba869a4dcf901ad6edfbbaa8cca2618
author: Karina <ruil2@cisco.com>
date: Wed Nov 30 10:41:44 EST 2016

fix memory lenght issue

--- a/codec/encoder/core/src/set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/set_mb_syn_cavlc.cpp
@@ -251,7 +251,8 @@
   SCabacCtx* pCtx = &pSlice->sCabacCtx;
   memcpy (&pDss->sStoredCabac, pCtx, sizeof (SCabacCtx));
   if (pDss->pRestoreBuffer) {
-    int32_t iLen = GetBsPosCabac (pSlice) - pDss->iStartPos;
+    int32_t iPosBitOffset =  GetBsPosCabac (pSlice) - pDss->iStartPos;
+    int32_t iLen = ((iPosBitOffset >> 3) + ((iPosBitOffset & 0x07) ? 1 : 0));
     memcpy (pDss->pRestoreBuffer, pCtx->m_pBufStart, iLen);
   }
   pDss->uiLastMbQp =  pSlice->uiLastMbQp;
@@ -260,9 +261,9 @@
 int32_t StashPopMBStatusCabac (SDynamicSlicingStack* pDss, SSlice* pSlice) {
   SCabacCtx* pCtx = &pSlice->sCabacCtx;
   memcpy (pCtx, &pDss->sStoredCabac, sizeof (SCabacCtx));
-
   if (pDss->pRestoreBuffer) {
-    int32_t iLen = GetBsPosCabac (pSlice) - pDss->iStartPos;
+    int32_t iPosBitOffset = GetBsPosCabac (pSlice) - pDss->iStartPos;
+    int32_t iLen = ((iPosBitOffset >> 3) + ((iPosBitOffset & 0x07) ? 1 : 0));
     memcpy (pCtx->m_pBufStart, pDss->pRestoreBuffer, iLen);
   }
   pSlice->uiLastMbQp = pDss->uiLastMbQp;