[FFmpeg-devel] [PATCH 2/2] avformat/assenc: fix strstr calls on non-string

Tim Angus tim at ngus.net
Tue Jan 31 13:13:49 EET 2023


In the write_header function of the ASS encoder, extradata is
searched for a substring using the strstr function. strstr expects a
null terminated C string as its first parameter, but extradata is
(notionally) not one of these, meaning that the calls to strstr only
happen to work because (presumably) they encounter a 0 byte somewhere
downstream of extradata. I say notionally because often extradata will
in fact be null terminated (which causes other problems, see parent
commit).

Signed-off-by: Tim Angus <tim at ngus.net>
---
 libavformat/assenc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/assenc.c b/libavformat/assenc.c
index 4c9ea6f982..f6f5293bb7 100644
--- a/libavformat/assenc.c
+++ b/libavformat/assenc.c
@@ -83,12 +83,12 @@ static int write_header(AVFormatContext *s)
         if (header_string[strlen(header_string) - 1] != '\n')
             avio_printf(s->pb, "\r\n");
 
-        av_free(header_string);
-
-        ass->ssa_mode = !strstr(par->extradata, "\n[V4+ Styles]");
-        if (!strstr(par->extradata, "\n[Events]"))
+        ass->ssa_mode = !strstr(header_string, "\n[V4+ Styles]");
+        if (!strstr(header_string, "\n[Events]"))
             avio_printf(s->pb, "[Events]\r\nFormat: %s, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n",
                         ass->ssa_mode ? "Marked" : "Layer");
+
+        av_free(header_string);
     }
 
     return 0;
-- 
2.25.1



More information about the ffmpeg-devel mailing list