Mercurial > mplayer.hg
changeset 34976:482418e9e922
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.
author | cboesch |
---|---|
date | Fri, 10 Aug 2012 20:25:04 +0000 |
parents | 66caf74d2a52 |
children | b569e40af1c0 |
files | sub/subassconvert.c |
diffstat | 1 files changed, 14 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 */