[MPlayer-cvslog] r35070 - trunk/sub/subassconvert.c

cboesch subversion at mplayerhq.hu
Fri Aug 10 22:25:04 CEST 2012


Author: cboesch
Date: Fri Aug 10 22:25:04 2012
New Revision: 35070

Log:
subassconvert: better handling of invalid SubRip tag attributes.

Markups with missing quotes should work fine now.

Note: we should replace this code with the FFmpeg decoder, which might be doing
things better.

Special thanks to Szokovacs Robert and Federico Kereki.

Modified:
   trunk/sub/subassconvert.c

Modified: trunk/sub/subassconvert.c
==============================================================================
--- trunk/sub/subassconvert.c	Fri Aug 10 20:43:21 2012	(r35069)
+++ trunk/sub/subassconvert.c	Fri Aug 10 22:25:04 2012	(r35070)
@@ -197,50 +197,46 @@ void subassconvert_subrip(const char *or
             line += 6;
 
             while (*line && *line != '>') {
-                if (strncmp(line, "size=\"", 6) == 0) {
-                    line += 6;
+                if (strncmp(line, "size=", 5) == 0) {
+                    line += 5;
+                    if (*line == '"') line++;
                     tag->size = strtol(line, &line, 10);
-                    if (*line != '"' || !tag->size)
+                    if (!tag->size)
                         break;
                     append_text(&new_line, "{\\fs%d}", tag->size);
                     has_valid_attr = 1;
-                } else if (strncmp(line, "color=\"", 7) == 0) {
-                    line += 7;
+                } else if (strncmp(line, "color=", 6) == 0) {
+                    line += 6;
+                    if (*line == '"') line++;
                     if (*line == '#') {
                         // #RRGGBB format
                         line++;
                         tag->color = strtol(line, &line, 16) & 0x00ffffff;
-                        if (*line != '"')
-                            break;
                         tag->color = ((tag->color & 0xff) << 16) |
                                       (tag->color & 0xff00) |
                                      ((tag->color & 0xff0000) >> 16) |
                                      SUBRIP_FLAG_COLOR;
                     } else {
                         // Standard web colors
-                        int i, len = indexof(line, '"');
-                        if (len <= 0)
-                            break;
+                        int i;
                         for (i = 0; i < FF_ARRAY_ELEMS(subrip_web_colors); i++) {
                             const char *color = subrip_web_colors[i].s;
-                            if (strlen(color) == len
-                                && strncasecmp(line, color, len) == 0) {
+                            const int len = strlen(color);
+                            if (strncasecmp(line, color, len) == 0) {
                                 tag->color = SUBRIP_FLAG_COLOR | subrip_web_colors[i].v;
+                                line += len;
                                 break;
                             }
                         }
 
                         if (i == FF_ARRAY_ELEMS(subrip_web_colors)) {
                             /* We didn't find any matching color */
-                            line = strchr(line, '"'); // can't be NULL, see above
+                            line += strcspn(line, "\" >");
                             mp_msg(MSGT_SUBREADER, MSGL_WARN,
                                    MSGTR_SUBTITLES_SubRip_UnknownFontColor, orig);
                             append_text(&new_line, "{\\c}");
-                            line += 2;
                             continue;
                         }
-
-                        line += len;
                     }
                     append_text(&new_line, "{\\c&H%06X&}", tag->color & 0xffffff);
                     has_valid_attr = 1;
@@ -257,7 +253,8 @@ void subassconvert_subrip(const char *or
                     append_text(&new_line, "{\\fn%.*s}", BSTR_P(tag->face));
                     has_valid_attr = 1;
                 }
-                line++;
+                if (*line != '>')
+                    line++;
             }
 
             if (!has_valid_attr || *line != '>') { /* Not valid font tag */


More information about the MPlayer-cvslog mailing list