diff mbox series

[FFmpeg-devel,3/3] avformat/mpeg: Fix filename extension check for subtitle file

Message ID 20230506132503.9524-3-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/3] avformat/dashdec: fail on probing non mpd file extension | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer May 6, 2023, 1:25 p.m. UTC
This fixes undefined behavior and other issues.
No testcase, this was found by code review

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/mpeg.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 781c3162d6..fdc808dc50 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -756,12 +756,17 @@  static int vobsub_read_header(AVFormatContext *s)
         }
 
         fname_len = strlen(vobsub->sub_name);
-        ext = vobsub->sub_name - 3 + fname_len;
-        if (fname_len < 4 || *(ext - 1) != '.') {
+        if (fname_len < 4) {
             av_log(s, AV_LOG_ERROR, "The input index filename is too short "
                    "to guess the associated .SUB file\n");
             return AVERROR_INVALIDDATA;
         }
+        ext = vobsub->sub_name + fname_len - 3;
+        if (*(ext - 1) != '.' || strchr(ext, '/')) {
+            av_log(s, AV_LOG_ERROR, "The input index filename needs to have a 3 letter extension "
+                   "to guess the associated .SUB file\n");
+            return AVERROR_INVALIDDATA;
+        }
         memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3);
         av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->url, vobsub->sub_name);
     }