[FFmpeg-devel] [PATCH] lavc/srtdec: handle leading whitespace before tag names

Rodger Combs rodger.combs at gmail.com
Wed Jul 15 19:27:04 CEST 2015


This fixes cases like `</ font>`.
---
 libavcodec/srtdec.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index ed3af95..c26eb74 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -59,6 +59,7 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
     char *param, buffer[128], tmp[128];
     int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0;
     SrtStack stack[16];
+    const char *tagname;
 
     stack[0].tag[0] = 0;
     strcpy(stack[0].param[PARAM_SIZE],  "{\\fs}");
@@ -114,16 +115,19 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
         case '<':
             tag_close = in[1] == '/';
             len = 0;
-            if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) {
-                if ((param = strchr(buffer, ' ')))
+            if (sscanf(in+1+tag_close, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) {
+                tagname = buffer;
+                while (*tagname == ' ')
+                    tagname++;
+                if ((param = strchr(tagname, ' ')))
                     *param++ = 0;
                 if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
-                    ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, buffer))) {
+                    ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, tagname))) {
                     int i, j, unknown = 0;
                     in += len + tag_close;
                     if (!tag_close)
                         memset(stack+sptr, 0, sizeof(*stack));
-                    if (!strcmp(buffer, "font")) {
+                    if (!strcmp(tagname, "font")) {
                         if (tag_close) {
                             for (i=PARAM_NUMBER-1; i>=0; i--)
                                 if (stack[sptr-1].param[i][0])
@@ -166,7 +170,7 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
                                 if (stack[sptr].param[i][0])
                                     av_bprintf(dst, "%s", stack[sptr].param[i]);
                         }
-                    } else if (!buffer[1] && strspn(buffer, "bisu") == 1) {
+                    } else if (!tagname[1] && strspn(tagname, "bisu") == 1) {
                         av_bprintf(dst, "{\\%c%d}", buffer[0], !tag_close);
                     } else {
                         unknown = 1;
@@ -178,7 +182,7 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
                         in -= len + tag_close;
                         av_bprint_chars(dst, *in, 1);
                     } else
-                        av_strlcpy(stack[sptr++].tag, buffer,
+                        av_strlcpy(stack[sptr++].tag, tagname,
                                    sizeof(stack[0].tag));
                     break;
                 }
-- 
2.4.1



More information about the ffmpeg-devel mailing list