PR #25078 opened by romainhedouin
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25078
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25078.patch

The PID was read from buf + 1 (i.e. always from the first packet) while the 
adaptation field control on the next line is read at the current sync byte (buf 
+ i)

Tested: make fate passes. Probing all 2569 files of the FATE suite gives the 
same detected format and score before and after

Signed-off-by: romainhedouin <[email protected]>

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From a78a9dc83f1da09baafe0f2c04d280955f4918f4 Mon Sep 17 00:00:00 2001
From: romainhedouin <[email protected]>
Date: Wed, 14 Oct 2026 21:07:20 +0200
Subject: [PATCH] avformat/mpegts: read the PID at the sync byte in analyze()

The PID was read from buf + 1, i.e. always from the first packet,
while the adaptation field control on the next line is read at the
current sync byte (buf + i). The null-packet check in probe mode thus
used the wrong packet.

Tested: make fate passes. Probing all 2569 files of the FATE suite
gives the same detected format and score before and after.

Found with the help of an AI code review; verified by hand.

Signed-off-by: romainhedouin <[email protected]>
---
 libavformat/mpegts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index c013452e97..59eaa9431c 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -621,7 +621,7 @@ static int analyze(const uint8_t *buf, int size, int 
packet_size,
 
     for (i = 0; i < size - 3; i++) {
         if (buf[i] == SYNC_BYTE) {
-            int pid = AV_RB16(buf+1) & 0x1FFF;
+            int pid = AV_RB16(buf + i + 1) & 0x1FFF;
             int asc = buf[i + 3] & 0x30;
             if (!probe || pid == 0x1FFF || asc) {
                 int x = i % packet_size;
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to