From f0a9bf3ffe16bf2b39aa1b7c6aebb80d698d0f4d Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Wed, 24 May 2023 08:59:22 -0700 Subject: [PATCH] Fix TS probing by requiring 2-3 packet start bytes to be matched Fixes #5501 --- src/demux/tsdemuxer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/demux/tsdemuxer.ts b/src/demux/tsdemuxer.ts index 8add100249d..ab2d9a73516 100644 --- a/src/demux/tsdemuxer.ts +++ b/src/demux/tsdemuxer.ts @@ -111,7 +111,14 @@ class TSDemuxer implements Demuxer { if (!foundPat && parsePID(data, j) === 0) { foundPat = true; } - if (foundPat && j + PACKET_LENGTH > scanwindow) { + if (foundPat && data[j + PACKET_LENGTH] === 0x47) { + // If length supports 3 packets, confirm + if ( + length > j + PACKET_LENGTH * 2 && + data[j + PACKET_LENGTH * 2] !== 0x47 + ) { + return -1; + } return i; } } else {