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/subtitles.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libavformat/subtitles.h') diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 455b374f25..96de9fa5d4 100644 --- a/libavformat/subtitles.h +++ b/libavformat/subtitles.h @@ -96,4 +96,14 @@ const char *ff_smil_get_attr_ptr(const char *s, const char *attr); */ void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf); +/** + * Get the number of characters to increment to jump to the next line, or to + * the end of the string. + */ +static av_always_inline int ff_subtitles_next_line(const char *ptr) +{ + int n = strcspn(ptr, "\n"); + return n + !!*ptr; +} + #endif /* AVFORMAT_SUBTITLES_H */ -- cgit v1.2.3