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

read_header() guards the zero-frames case before touching index_entries[0] 
(bink.c:227) but read_seek() dereferences it unconditionally, so any seek into 
a .bik that declares zero frames - which opens fine - crashes with SIGSEGV on a 
NULL index. Add the missing guard, returning AVERROR(EINVAL). Full analysis in 
the commit message; 48-byte repro sample available on request. make fate passes.


>From 2b24ec5c3ac53322de2fee1278d894a07c8909cb Mon Sep 17 00:00:00 2001
From: Richard Desmarais <[email protected]>
Date: Thu, 12 Nov 2026 10:05:56 -0500
Subject: [PATCH] avformat/bink: do not dereference the index in read_seek()
 when it is empty

read_header() adds one index entry per frame, bounded by the frame count
from the header, and guards the zero-frames case before touching
index_entries[0] (bink.c:227). read_seek() has no such guard and
dereferences index_entries[0] unconditionally, so any seek into a Bink
file that declares zero frames (which opens fine) crashes with SIGSEGV:

    ret = avio_seek(s->pb, vsti->index_entries[0].pos + bink->smush_size, 
SEEK_SET);

Reproduce with a 48-byte sample (BIK header, zero frames):
    ffmpeg -ss 1 -f bink -i poc.bik -f null -
before: "SEGV on unknown address 0x000000000000" (ASAN), the demuxer
keeps a NULL index when nb_frames == 0;
after: "no index entries", AVERROR(EINVAL).

Signed-off-by: Richard Desmarais <[email protected]>
---
 libavformat/bink.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/bink.c b/libavformat/bink.c
index 6becc590310..a1b0fed5dc9 100644
--- a/libavformat/bink.c
+++ b/libavformat/bink.c
@@ -314,6 +314,13 @@ static int read_seek(AVFormatContext *s, int stream_index, 
int64_t timestamp, in
         return -1;
 
     /* seek to the first frame */
+    if (!vsti->index_entries) {
+        /* read_header() adds index entries only for files with a positive
+         * frame count; such a stream has nothing to seek to. */
+        av_log(s, AV_LOG_ERROR, "no index entries\n");
+        return AVERROR(EINVAL);
+    }
+
     ret = avio_seek(s->pb, vsti->index_entries[0].pos + bink->smush_size, 
SEEK_SET);
     if (ret < 0)
         return ret;
-- 
2.54.0

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

Reply via email to