PR #24666 opened by xiujunwang-dev
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24666
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24666.patch

A valid JPEG can contain byte sequences that satisfy cavsvideo_probe(), causing 
CAVS to score 51 while jpeg_pipe scores 26.

Keep the high CAVS score only when the sequence header is found at the start of 
the probed stream. Otherwise return AVPROBE_SCORE_EXTENSION / 2 so stronger 
probes can win.

Before:
- cavsvideo: 51
- jpeg_pipe: 26

After:
- cavsvideo: 25
- jpeg_pipe: 26

Tests:
- fate-cavs-demux
- fate-probe-format-jpeg-not-cavsvideo

The FATE sample upload will be requested via [email protected] after 
this PR is created.

Sample: probe-format/jpeg-not-cavsvideo
SHA-256: 83e94c45afe4aff2028195010d67d934bbfee9a0f640ea47ff1893a891587c10


>From fd3dde26533e843e79f9192f9954fffcd47ab3eb Mon Sep 17 00:00:00 2001
From: Xiujun Wang <[email protected]>
Date: Thu, 24 Sep 2026 20:15:18 +0800
Subject: [PATCH] avformat/cavsvideodec: reduce probe score for prefixed
 streams

cavsvideo_probe() returns a high score whenever it finds a valid
sequence and picture start code, even when the sequence header appears
only after unrelated leading data. This can make valid JPEG files probe
as CAVS.

Keep the high score when the sequence header is at the start of the
probed stream. Otherwise return AVPROBE_SCORE_EXTENSION / 2 so stronger
probes can win.

Signed-off-by: Xiujun Wang <[email protected]>
---
 libavformat/cavsvideodec.c | 7 +++++--
 tests/fate/probe.mak       | 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavformat/cavsvideodec.c b/libavformat/cavsvideodec.c
index b89851fbbb..24a9aee8c1 100644
--- a/libavformat/cavsvideodec.c
+++ b/libavformat/cavsvideodec.c
@@ -34,7 +34,7 @@
 static int cavsvideo_probe(const AVProbeData *p)
 {
     uint32_t code= -1;
-    int pic=0, seq=0, slice_pos = 0;
+    int pic=0, seq=0, slice_pos = 0, seq_at_start = 0;
     const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size;
 
     while (ptr < end) {
@@ -50,6 +50,8 @@ static int cavsvideo_probe(const AVProbeData *p)
             }
             if (code == CAVS_SEQ_START_CODE) {
                 seq++;
+                if (ptr == p->buf + 4)
+                    seq_at_start = 1;
                 /* check for the only currently supported profile */
                 if (*ptr != CAVS_PROFILE_JIZHUN && *ptr != 
CAVS_PROFILE_GUANGDIAN)
                     return 0;
@@ -63,7 +65,8 @@ static int cavsvideo_probe(const AVProbeData *p)
         }
     }
     if(seq && seq*9<=pic*10)
-        return AVPROBE_SCORE_EXTENSION+1;
+        return seq_at_start ? AVPROBE_SCORE_EXTENSION + 1 :
+                              AVPROBE_SCORE_EXTENSION / 2;
     return 0;
 }
 
diff --git a/tests/fate/probe.mak b/tests/fate/probe.mak
index e94206f981..220f874a9a 100644
--- a/tests/fate/probe.mak
+++ b/tests/fate/probe.mak
@@ -25,6 +25,9 @@ fate-probe-format-mpegts-png-prefix: REF = mpegts
 FATE_PROBE_FORMAT-$(call ALLYES, IMAGE_TIFF_PIPE_DEMUXER MPEGTS_DEMUXER) += 
fate-probe-format-tiff-not-mpegts
 fate-probe-format-tiff-not-mpegts: REF = tiff_pipe
 
+FATE_PROBE_FORMAT-$(call ALLYES, IMAGE_JPEG_PIPE_DEMUXER CAVSVIDEO_DEMUXER) += 
fate-probe-format-jpeg-not-cavsvideo
+fate-probe-format-jpeg-not-cavsvideo: REF = jpeg_pipe
+
 FATE_PROBE_FORMAT = $(FATE_PROBE_FORMAT-yes)
 
 FATE_SAMPLES_FFPROBE += $(FATE_PROBE_FORMAT)
-- 
2.52.0

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

Reply via email to