From 7bc4626a587a6d5a0df34bbef01ea670cdaf5213 Mon Sep 17 00:00:00 2001 From: Ivandro Ismael Date: Tue, 30 Aug 2016 16:28:34 +0100 Subject: [PATCH] [DvdSubPes] - Working on #1932. --- libse/TransportStream/DvbSubPes.cs | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libse/TransportStream/DvbSubPes.cs b/libse/TransportStream/DvbSubPes.cs index a5e163472..efc5b96b2 100644 --- a/libse/TransportStream/DvbSubPes.cs +++ b/libse/TransportStream/DvbSubPes.cs @@ -59,7 +59,7 @@ namespace Nikse.SubtitleEdit.Core.TransportStream HeaderDataLength = buffer[index + 8]; - if (buffer.Length < index + 9 + HeaderDataLength) + if (buffer.Length <= index + 9 + HeaderDataLength) return; if (StreamId == 0xBD) // 10111101 binary = 189 decimal = 0xBD hex -> private_stream_1 @@ -68,26 +68,26 @@ namespace Nikse.SubtitleEdit.Core.TransportStream if (id >= 0x20 && id <= 0x40) // x3f 0r x40 ? SubPictureStreamId = id; } - - int tempIndex = index + 9; - if (PresentationTimestampDecodeTimestampFlags == Helper.B00000010 || - PresentationTimestampDecodeTimestampFlags == Helper.B00000011) + if (index + 9 + 4 < buffer.Length) { - PresentationTimestamp = (ulong)buffer[tempIndex + 4] >> 1; - PresentationTimestamp += (ulong)buffer[tempIndex + 3] << 7; - PresentationTimestamp += (ulong)(buffer[tempIndex + 2] & Helper.B11111110) << 14; - PresentationTimestamp += (ulong)buffer[tempIndex + 1] << 22; - PresentationTimestamp += (ulong)(buffer[tempIndex + 0] & Helper.B00001110) << 29; + int tempIndex = index + 9; + if (PresentationTimestampDecodeTimestampFlags == Helper.B00000010 || PresentationTimestampDecodeTimestampFlags == Helper.B00000011) + { + PresentationTimestamp = (ulong)buffer[tempIndex + 4] >> 1; + PresentationTimestamp += (ulong)buffer[tempIndex + 3] << 7; + PresentationTimestamp += (ulong)(buffer[tempIndex + 2] & Helper.B11111110) << 14; + PresentationTimestamp += (ulong)buffer[tempIndex + 1] << 22; + PresentationTimestamp += (ulong)(buffer[tempIndex + 0] & Helper.B00001110) << 29; + } + if (PresentationTimestampDecodeTimestampFlags == Helper.B00000011) + { + DecodeTimestamp = (ulong)buffer[tempIndex + 4] >> 1; + DecodeTimestamp += (ulong)buffer[tempIndex + 3] << 7; + DecodeTimestamp += (ulong)(buffer[tempIndex + 2] & Helper.B11111110) << 14; + DecodeTimestamp += (ulong)buffer[tempIndex + 1] << 22; + DecodeTimestamp += (ulong)(buffer[tempIndex + 0] & Helper.B00001110) << 29; + } } - if (PresentationTimestampDecodeTimestampFlags == Helper.B00000011) - { - DecodeTimestamp = (ulong)buffer[tempIndex + 4] >> 1; - DecodeTimestamp += (ulong)buffer[tempIndex + 3] << 7; - DecodeTimestamp += (ulong)(buffer[tempIndex + 2] & Helper.B11111110) << 14; - DecodeTimestamp += (ulong)buffer[tempIndex + 1] << 22; - DecodeTimestamp += (ulong)(buffer[tempIndex + 0] & Helper.B00001110) << 29; - } - int dataIndex = index + HeaderDataLength + 24 - Mpeg2HeaderLength; int dataSize = Length - (4 + HeaderDataLength);