aboutsummaryrefslogtreecommitdiffstats
path: root/libMpegTPDec/src/tpdec_lib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libMpegTPDec/src/tpdec_lib.cpp')
-rw-r--r--libMpegTPDec/src/tpdec_lib.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp
index 3603a77..a4c0521 100644
--- a/libMpegTPDec/src/tpdec_lib.cpp
+++ b/libMpegTPDec/src/tpdec_lib.cpp
@@ -488,7 +488,8 @@ TRANSPORTDEC_ERROR transportDec_InBandConfig(HANDLE_TRANSPORTDEC hTp,
for (int i = 0; i < 2; i++) {
if (i > 0) {
- FDKpushBack(hBs, newConfigLength * 8 - FDKgetValidBits(hBs));
+ FDKpushBack(hBs,
+ (INT)newConfigLength * 8 - (INT)FDKgetValidBits(hBs));
configMode = AC_CM_ALLOC_MEM;
}
/* config transport decoder */
@@ -669,10 +670,14 @@ TRANSPORTDEC_ERROR transportDec_FillData(const HANDLE_TRANSPORTDEC hTp,
if (*pBytesValid == 0) {
/* nothing to do */
return TRANSPORTDEC_OK;
- }
-
- if (hTp->numberOfRawDataBlocks <= 0) {
+ } else {
+ const int bytesValid = *pBytesValid;
FDKfeedBuffer(hBs, pBuffer, bufferSize, pBytesValid);
+
+ if (hTp->numberOfRawDataBlocks > 0) {
+ hTp->globalFramePos += (bytesValid - *pBytesValid) * 8;
+ hTp->accessUnitAnchor[layer] = FDKgetValidBits(hBs);
+ }
}
}
@@ -930,6 +935,11 @@ static TRANSPORTDEC_ERROR transportDec_readHeader(
}
}
}
+ /* if an error is detected terminate config parsing to avoid that an
+ * invalid config is accepted in the second pass */
+ if (err != TRANSPORTDEC_OK) {
+ break;
+ }
}
} else {
/* Reset CRC because the next bits are the beginning of a
@@ -982,6 +992,9 @@ static TRANSPORTDEC_ERROR transportDec_readHeader(
CLatmDemux_GetNrOfSubFrames(&hTp->parser.latm);
if (hTp->transportFmt == TT_MP4_LOAS) {
syncLayerFrameBits -= startPos - (INT)FDKgetValidBits(hBs) - (13);
+ if (syncLayerFrameBits <= 0) {
+ err = TRANSPORTDEC_SYNC_ERROR;
+ }
}
}
} else {
@@ -1157,6 +1170,11 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp,
&rawDataBlockLength, &fTraverseMoreFrames,
&syncLayerFrameBits, &fConfigFound,
&headerBits);
+ if (headerBits > bitsAvail) {
+ err = (headerBits < (INT)hBs->hBitBuf.bufBits)
+ ? TRANSPORTDEC_NOT_ENOUGH_BITS
+ : TRANSPORTDEC_SYNC_ERROR;
+ }
if (TPDEC_IS_FATAL_ERROR(err)) {
/* Rewind - TPDEC_SYNCSKIP, in order to look for a synch one bit ahead
* next time. Ensure that the bit amount lands at a multiple of
@@ -1187,8 +1205,6 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp,
}
if (err == TRANSPORTDEC_NOT_ENOUGH_BITS) {
- /* Enforce reading of new data */
- hTp->numberOfRawDataBlocks = 0;
break;
}
@@ -1269,8 +1285,9 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp,
if (!(hTp->flags & (TPDEC_LOST_FRAMES_PENDING | TPDEC_IGNORE_BUFFERFULLNESS |
TPDEC_SYNCOK)) &&
err == TRANSPORTDEC_OK) {
- err = additionalHoldOffNeeded(hTp, transportDec_GetBufferFullness(hTp),
- FDKgetValidBits(hBs) - syncLayerFrameBits);
+ err =
+ additionalHoldOffNeeded(hTp, transportDec_GetBufferFullness(hTp),
+ (INT)FDKgetValidBits(hBs) - syncLayerFrameBits);
if (err == TRANSPORTDEC_NOT_ENOUGH_BITS) {
hTp->holdOffFrames++;
}
@@ -1279,7 +1296,9 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp,
/* Rewind for retry because of not enough bits */
if (err == TRANSPORTDEC_NOT_ENOUGH_BITS) {
FDKpushBack(hBs, headerBits);
+ hTp->numberOfRawDataBlocks = numRawDataBlocksPrevious;
headerBits = 0;
+ rawDataBlockLength = rawDataBlockLengthPrevious;
} else {
/* reset hold off frame counter */
hTp->holdOffFrames = 0;
@@ -1466,7 +1485,7 @@ TRANSPORTDEC_ERROR transportDec_ReadAccessUnit(const HANDLE_TRANSPORTDEC hTp,
for (i = 0; i < 2; i++) {
if (i > 0) {
- FDKpushBack(hBs, bsStart - FDKgetValidBits(hBs));
+ FDKpushBack(hBs, bsStart - (INT)FDKgetValidBits(hBs));
configMode = AC_CM_ALLOC_MEM;
}