Add CRC check for PMT

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131394778
This commit is contained in:
aquilescanta 2016-08-26 06:20:18 -07:00 committed by Oliver Woodman
parent 6528aef2bb
commit d72e26ff35

View file

@ -278,7 +278,7 @@ public final class TsExtractor implements Extractor {
int crcStart = data.getPosition() - 3;
int crcEnd = data.getPosition() + sectionLength;
if (Util.crc(data.data, crcStart, crcEnd, 0xffffffff) != 0) {
if (Util.crc(data.data, crcStart, crcEnd, 0xFFFFFFFF) != 0) {
// CRC Invalid. The section gets discarded.
return;
}
@ -313,6 +313,7 @@ public final class TsExtractor implements Extractor {
private int sectionLength;
private int sectionBytesRead;
private int crc;
public PmtReader() {
pmtScratch = new ParsableBitArray(new byte[5]);
@ -337,6 +338,7 @@ public final class TsExtractor implements Extractor {
data.readBytes(pmtScratch, 3);
pmtScratch.skipBits(12); // table_id (8), section_syntax_indicator (1), 0 (1), reserved (2)
sectionLength = pmtScratch.readBits(12);
crc = Util.crc(pmtScratch.data, 0, 3, 0xFFFFFFFF);
if (sectionData.capacity() < sectionLength) {
sectionData.reset(new byte[sectionLength], sectionLength);
@ -354,6 +356,11 @@ public final class TsExtractor implements Extractor {
return;
}
if (Util.crc(sectionData.data, 0, sectionLength, crc) != 0) {
// CRC Invalid. The section gets discarded.
return;
}
// program_number (16), reserved (2), version_number (5), current_next_indicator (1),
// section_number (8), last_section_number (8), reserved (3), PCR_PID (13)
// Skip the rest of the PMT header.