Issue #1536 - Part 1: Add timecode checking for the WebM parser

This commit is contained in:
wolfbeast 2020-05-07 13:36:54 +02:00 • committed by Roy Tam
commit d71453cef3
2 changed files with 13 additions and 0 deletions

View file

@ -113,6 +113,7 @@ bool WebMBufferedParser::Append(const unsigned char* aBuffer, uint32_t aLength,
} else { } else {
mClusterEndOffset = -1; mClusterEndOffset = -1;
} }
mGotClusterTimecode = false;
mState = READ_ELEMENT_ID; mState = READ_ELEMENT_ID;
break; break;
case BLOCKGROUP_ID: case BLOCKGROUP_ID:
@ -121,6 +122,11 @@ bool WebMBufferedParser::Append(const unsigned char* aBuffer, uint32_t aLength,
case SIMPLEBLOCK_ID: case SIMPLEBLOCK_ID:
/* FALLTHROUGH */ /* FALLTHROUGH */
case BLOCK_ID: case BLOCK_ID:
if (!mGotClusterTimecode) {
WEBM_DEBUG("The Timecode element must appear before any Block or "
"SimpleBlock elements in a Cluster");
return false;
}
mBlockSize = mElement.mSize.mValue; mBlockSize = mElement.mSize.mValue;
mBlockTimecode = 0; mBlockTimecode = 0;
mBlockTimecodeLength = BLOCK_TIMECODE_LENGTH; mBlockTimecodeLength = BLOCK_TIMECODE_LENGTH;
@ -164,6 +170,7 @@ bool WebMBufferedParser::Append(const unsigned char* aBuffer, uint32_t aLength,
break; break;
case READ_TIMECODESCALE: case READ_TIMECODESCALE:
if (!mGotTimecodeScale) { if (!mGotTimecodeScale) {
WEBM_DEBUG("Should get the SegmentInfo first");
return false; return false;
} }
mTimecodeScale = mVInt.mValue; mTimecodeScale = mVInt.mValue;
@ -171,6 +178,7 @@ bool WebMBufferedParser::Append(const unsigned char* aBuffer, uint32_t aLength,
break; break;
case READ_CLUSTER_TIMECODE: case READ_CLUSTER_TIMECODE:
mClusterTimecode = mVInt.mValue; mClusterTimecode = mVInt.mValue;
mGotClusterTimecode = true;
mState = READ_ELEMENT_ID; mState = READ_ELEMENT_ID;
break; break;
case READ_BLOCK_TIMECODE: case READ_BLOCK_TIMECODE:
@ -190,6 +198,7 @@ bool WebMBufferedParser::Append(const unsigned char* aBuffer, uint32_t aLength,
// Don't insert invalid negative timecodes. // Don't insert invalid negative timecodes.
if (mBlockTimecode >= 0 || mClusterTimecode >= uint16_t(abs(mBlockTimecode))) { if (mBlockTimecode >= 0 || mClusterTimecode >= uint16_t(abs(mBlockTimecode))) {
if (!mGotTimecodeScale) { if (!mGotTimecodeScale) {
WEBM_DEBUG("Should get the TimecodeScale first");
return false; return false;
} }
uint64_t absTimecode = mClusterTimecode + mBlockTimecode; uint64_t absTimecode = mClusterTimecode + mBlockTimecode;

View file

@ -75,6 +75,7 @@ struct WebMBufferedParser
, mSkipBytes(0) , mSkipBytes(0)
, mTimecodeScale(1000000) , mTimecodeScale(1000000)
, mGotTimecodeScale(false) , mGotTimecodeScale(false)
, mGotClusterTimecode(false)
{ {
if (mStartOffset != 0) { if (mStartOffset != 0) {
mState = FIND_CLUSTER_SYNC; mState = FIND_CLUSTER_SYNC;
@ -260,6 +261,9 @@ private:
// True if we read the timecode scale from the segment info or have // True if we read the timecode scale from the segment info or have
// confirmed that the default value is to be used. // confirmed that the default value is to be used.
bool mGotTimecodeScale; bool mGotTimecodeScale;
// True if we've read the cluster time code.
bool mGotClusterTimecode;
}; };
class WebMBufferedState final class WebMBufferedState final