From 90fc00a623de44e137fe1601b91356e8cd8bdd54 Mon Sep 17 00:00:00 2001 From: Clément Bœsch Date: Sun, 8 Sep 2013 18:02:45 +0200 Subject: avformat/subtitles: add a next line jumper and use it. This fixes a bunch of possible overread in avformat with the idiom p += strcspn(p, "\n") + 1 (strcspn() can focus on the trailing '\0' if no '\n' is found, so the +1 leads to an overread). Note on lavf/matroskaenc: no extra subtitles.o Makefile dependency is added because only the header is required for ff_subtitles_next_line(). Note on lavf/mpsubdec: code gets slightly complex to avoid an infinite loop in the probing since there is no more forced increment. --- libavformat/srtdec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'libavformat/srtdec.c') diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c index ac783d9e3b..7f911bd05b 100644 --- a/libavformat/srtdec.c +++ b/libavformat/srtdec.c @@ -44,7 +44,7 @@ static int srt_probe(AVProbeData *p) && sscanf(ptr, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1) return AVPROBE_SCORE_MAX; num = atoi(ptr); - ptr += strcspn(ptr, "\n") + 1; + ptr += ff_subtitles_next_line(ptr); } return 0; } @@ -65,12 +65,10 @@ static int64_t get_pts(const char **buf, int *duration, int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1; int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2; *duration = end - start; - *buf += strcspn(*buf, "\n"); - *buf += !!**buf; + *buf += ff_subtitles_next_line(*buf); return start; } - *buf += strcspn(*buf, "\n"); - *buf += !!**buf; + *buf += ff_subtitles_next_line(*buf); } return AV_NOPTS_VALUE; } -- cgit v1.2.3