[FFmpeg-devel] [PATCH 3/3] avformat/mpeg: Fix filename extension check for subtitle file
Michael Niedermayer
michael at niedermayer.cc
Sat May 6 16:25:03 EEST 2023
This fixes undefined behavior and other issues.
No testcase, this was found by code review
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavformat/mpeg.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
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);
}
--
2.17.1
More information about the ffmpeg-devel
mailing list