Merge cherrypicks of [3628718, 3628929, 3628848, 3628813, 3628719, 3628980, 3628930, 3628931, 3628903, 3628759, 3629000, 3629001, 3629002, 3629003, 3629040, 3629041, 3629042, 3629043, 3629044, 3629045, 3628974, 3629022, 3628981, 3628849, 3628932, 3628933, 3628934, 3628935, 3628936, 3628937, 3628938, 3628939, 3629060, 3628982, 3628983, 3628984] into oc-m5-release

Change-Id: Ic07f3ba081bc5315cce0acfe30a30d1f162fa7e3
diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp
index 96a1b35..e80d0e5 100644
--- a/libMpegTPDec/src/tpdec_asc.cpp
+++ b/libMpegTPDec/src/tpdec_asc.cpp
@@ -118,7 +118,9 @@
 
 /*
  * Read the extension for height info.
- * return 0 if successfull or -1 if the CRC failed.
+ * return 0 if successfull,
+ *       -1 if the CRC failed,
+ *       -2 if invalid HeightInfo.
  */
 static
 int CProgramConfig_ReadHeightExt(
@@ -146,15 +148,21 @@
 
     for (i=0; i < pPce->NumFrontChannelElements; i++)
     {
-      pPce->FrontElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2);
+      if ((pPce->FrontElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2)) >= PC_NUM_HEIGHT_LAYER) {
+        err = -2; /* height information is out of the valid range */
+      }
     }
     for (i=0; i < pPce->NumSideChannelElements; i++)
     {
-      pPce->SideElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2);
+      if ((pPce->SideElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2)) >= PC_NUM_HEIGHT_LAYER) {
+        err = -2; /* height information is out of the valid range */
+      }
     }
     for (i=0; i < pPce->NumBackChannelElements; i++)
     {
-      pPce->BackElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2);
+      if ((pPce->BackElementHeightInfo[i] = (UCHAR) FDKreadBits(bs,2)) >= PC_NUM_HEIGHT_LAYER) {
+        err = -2; /* height information is out of the valid range */
+      }
     }
     FDKbyteAlign(bs, alignmentAnchor);
 
@@ -163,6 +171,13 @@
       /* CRC failed */
       err = -1;
     }
+    if (err!=0) {
+      /* Reset whole height information in case an error occured during parsing. The return
+         value ensures that pPce->isValid is set to 0 and implicit channel mapping is used. */
+      FDKmemclear(pPce->FrontElementHeightInfo, sizeof(pPce->FrontElementHeightInfo));
+      FDKmemclear(pPce->SideElementHeightInfo, sizeof(pPce->SideElementHeightInfo));
+      FDKmemclear(pPce->BackElementHeightInfo, sizeof(pPce->BackElementHeightInfo));
+    }
   }
   else {
     /* No valid extension data found -> restore the initial bitbuffer state */