# HG changeset patch # User cboesch # Date 1344630304 0 # Node ID 482418e9e922a1b57ee04fbe9b840ae4d7125485 # Parent 66caf74d2a5271447eeb216814d3d40908c95345 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. diff -r 66caf74d2a52 -r 482418e9e922 sub/subassconvert.c --- a/sub/subassconvert.c Fri Aug 10 18:43:21 2012 +0000 +++ b/sub/subassconvert.c Fri Aug 10 20:25:04 2012 +0000 @@ -197,50 +197,46 @@ 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 @@ 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 */