]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/htmlsubtitles: Be a bit more picky on syntax
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 1 Jul 2017 22:09:42 +0000 (00:09 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Tue, 18 Jul 2017 20:14:16 +0000 (22:14 +0200)
This reduces the number of strstr() calls per byte
This diasalows empty tags like '< >' as well as '<' in tags like '<ab<cd<<ef>'

Fixes timeout
Fixes: 1817/clusterfuzz-testcase-minimized-5104230530547712
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/htmlsubtitles.c

index 9575464063139c7b33914549cb674cd7f9ce8ce6..e6bac713c160d4271a556375ff05b559b749d978 100644 (file)
@@ -110,13 +110,13 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in)
         case '<':
             tag_close = in[1] == '/';
             len = 0;
-            if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) {
+            if (sscanf(in+tag_close+1, "%127[^<>]>%n", buffer, &len) >= 1 && len > 0) {
                 const char *tagname = buffer;
                 while (*tagname == ' ')
                     tagname++;
                 if ((param = strchr(tagname, ' ')))
                     *param++ = 0;
-                if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
+                if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack) && *tagname) ||
                     ( tag_close && sptr > 0 && !av_strcasecmp(stack[sptr-1].tag, tagname))) {
                     int i, j, unknown = 0;
                     in += len + tag_close;