X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fjacosubdec.c;h=c8bded02fefb69dcdcc8a5d7e02cc2787c022703;hb=bc70684e74a185d7b80c8b80bdedda659cb581b8;hp=f6be5df2d7d7a275d9ef75f3fce7edd811e78371;hpb=c6892f59eb0e9f2a9ec1f55b21a5841a60540e1f;p=ffmpeg diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c index f6be5df2d7d..c8bded02fef 100644 --- a/libavformat/jacosubdec.c +++ b/libavformat/jacosubdec.c @@ -48,7 +48,7 @@ static int timed_line(const char *ptr) (sscanf(ptr, "@%u @%u %c", &fs, &fe, &c) == 3 && fs < fe)); } -static int jacosub_probe(AVProbeData *p) +static int jacosub_probe(const AVProbeData *p) { const char *ptr = p->buf; const char *ptr_end = p->buf + p->buf_size; @@ -107,6 +107,7 @@ static const char *read_ts(JACOsubContext *jacosub, const char *buf, unsigned hs, ms, ss, fs; // hours, minutes, seconds, frame start unsigned he, me, se, fe; // hours, minutes, seconds, frame end int ts_start, ts_end; + int64_t ts_start64, ts_end64; /* timed format */ if (sscanf(buf, "%u:%u:%u.%u %u:%u:%u.%u %n", @@ -124,10 +125,10 @@ static const char *read_ts(JACOsubContext *jacosub, const char *buf, return NULL; shift_and_ret: - ts_start = (ts_start + jacosub->shift) * 100 / jacosub->timeres; - ts_end = (ts_end + jacosub->shift) * 100 / jacosub->timeres; - *start = ts_start; - *duration = ts_end - ts_start; + ts_start64 = (ts_start + (int64_t)jacosub->shift) * 100LL / jacosub->timeres; + ts_end64 = (ts_end + (int64_t)jacosub->shift) * 100LL / jacosub->timeres; + *start = ts_start64; + *duration = ts_end64 - ts_start64; return buf + len; } @@ -135,6 +136,7 @@ static int get_shift(int timeres, const char *buf) { int sign = 1; int a = 0, b = 0, c = 0, d = 0; + int64_t ret; #define SSEP "%*1[.:]" int n = sscanf(buf, "%d"SSEP"%d"SSEP"%d"SSEP"%d", &a, &b, &c, &d); #undef SSEP @@ -144,13 +146,22 @@ static int get_shift(int timeres, const char *buf) a = FFABS(a); } + ret = 0; switch (n) { - case 4: return sign * ((a*3600 + b*60 + c) * timeres + d); - case 3: return sign * (( a*60 + b) * timeres + c); - case 2: return sign * (( a) * timeres + b); + case 4: + ret = sign * (((int64_t)a*3600 + b*60 + c) * timeres + d); + break; + case 3: + ret = sign * (( (int64_t)a*60 + b) * timeres + c); + break; + case 2: + ret = sign * (( (int64_t)a) * timeres + b); + break; } + if ((int)ret != ret) + ret = 0; - return 0; + return ret; } static int jacosub_read_header(AVFormatContext *s) @@ -187,8 +198,11 @@ static int jacosub_read_header(AVFormatContext *s) AVPacket *sub; sub = ff_subtitles_queue_insert(&jacosub->q, line, len, merge_line); - if (!sub) - return AVERROR(ENOMEM); + if (!sub) { + av_bprint_finalize(&header, NULL); + ret = AVERROR(ENOMEM); + goto fail; + } sub->pos = pos; merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n"); continue; @@ -237,7 +251,7 @@ static int jacosub_read_header(AVFormatContext *s) /* SHIFT and TIMERES affect the whole script so packet timing can only be * done in a second pass */ for (i = 0; i < jacosub->q.nb_subs; i++) { - AVPacket *sub = &jacosub->q.subs[i]; + AVPacket *sub = jacosub->q.subs[i]; read_ts(jacosub, sub->data, &sub->pts, &sub->duration); } ff_subtitles_queue_finalize(s, &jacosub->q); @@ -262,7 +276,7 @@ static int jacosub_read_seek(AVFormatContext *s, int stream_index, min_ts, ts, max_ts, flags); } -AVInputFormat ff_jacosub_demuxer = { +const AVInputFormat ff_jacosub_demuxer = { .name = "jacosub", .long_name = NULL_IF_CONFIG_SMALL("JACOsub subtitle format"), .priv_data_size = sizeof(JACOsubContext),