From d5909e833f85a86c39f3c3713532702221c7e332 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Sun, 26 Nov 2017 00:19:01 +0100 Subject: [PATCH] Fixing incomplete PES data --- data_pes.go | 9 +++++++++ data_psi.go | 1 + 2 files changed, 10 insertions(+) diff --git a/data_pes.go b/data_pes.go index fc91009..d3fbc15 100644 --- a/data_pes.go +++ b/data_pes.go @@ -1,5 +1,7 @@ package astits +import "github.com/asticode/go-astilog" + // P-STD buffer scales const ( PSTDBufferScale128Bytes = 0 @@ -134,6 +136,13 @@ func parsePESHeader(i []byte, offset *int) (h *PESHeader, dataStart, dataEnd int dataEnd = len(i) } + // Check for incomplete data + // TODO Throw away the data? + if dataEnd > len(i) { + astilog.Debug("PES dataEnd > len(i), needs fixing") + dataEnd = len(i) + } + // Optional header if hasPESOptionalHeader(h.StreamID) { h.OptionalHeader, dataStart = parsePESOptionalHeader(i, offset) diff --git a/data_psi.go b/data_psi.go index 5fa0980..64ff47a 100644 --- a/data_psi.go +++ b/data_psi.go @@ -212,6 +212,7 @@ func hasCRC32(tableType string) bool { } // psiTableType returns the psi table type based on the table id +// Page: 28 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf func psiTableType(tableID int) string { switch { case tableID == 0x4a: