TunerHAL Fix bug in TS Size Read

Previously in CL 19152256 the size variables for Pes and
Section event reading were made unsigned in order to
prevent negative values. However, the conversion from
int8_t directly to uint32_t still produces incorrect values.
To solve this, the values which are read in are first
converted from int8_t to uint8_t before their final
conversion.

Bug: 238797416
Test: Run on Cuttlefish with TS input, and view logging.
Old version should not work with any TS that declares a
size containing any byte with value > 0x80.

Change-Id: I55bb552bc857fd8acf16729f8cfcb9e147e07e9c
diff --git a/tv/tuner/aidl/default/Filter.cpp b/tv/tuner/aidl/default/Filter.cpp
index 4d48c04..20fe76c 100644
--- a/tv/tuner/aidl/default/Filter.cpp
+++ b/tv/tuner/aidl/default/Filter.cpp
@@ -793,7 +793,8 @@
             }
             if (prefix == 0x000001) {
                 // TODO handle mulptiple Pes filters
-                mPesSizeLeft = (mFilterOutput[i + 8] << 8) | mFilterOutput[i + 9];
+                mPesSizeLeft = (static_cast<uint8_t>(mFilterOutput[i + 8]) << 8) |
+                               static_cast<uint8_t>(mFilterOutput[i + 9]);
                 mPesSizeLeft += 6;
                 if (DEBUG_FILTER) {
                     ALOGD("[Filter] pes data length %d", mPesSizeLeft);
@@ -875,7 +876,8 @@
             }
             if (prefix == 0x000001) {
                 // TODO handle mulptiple Pes filters
-                mPesSizeLeft = (mFilterOutput[i + 8] << 8) | mFilterOutput[i + 9];
+                mPesSizeLeft = (static_cast<uint8_t>(mFilterOutput[i + 8]) << 8) |
+                               static_cast<uint8_t>(mFilterOutput[i + 9]);
                 mPesSizeLeft += 6;
                 if (DEBUG_FILTER) {
                     ALOGD("[Filter] pes data length %d", mPesSizeLeft);
@@ -973,7 +975,8 @@
         if (mSectionSizeLeft == 0) {
             // Location for sectionSize as defined by Section 2.4.4
             // Note that the first 4 bytes skipped are the TsHeader
-            mSectionSizeLeft = ((data[i + 5] & 0x0f) << 8) | (data[i + 6] & 0xff);
+            mSectionSizeLeft = ((static_cast<uint8_t>(data[i + 5]) & 0x0f) << 8) |
+                               static_cast<uint8_t>(data[i + 6]);
             mSectionSizeLeft += 3;
             if (DEBUG_FILTER) {
                 ALOGD("[Filter] section data length %d", mSectionSizeLeft);