diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2017-05-06 01:42:53 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2017-05-20 03:41:33 +0200 |
commit | bd908055c8f72ac994d6ea5d44e7b818e570e6af (patch) | |
tree | 1e0980b96e49058f6c30640292a68dad8625a21f | |
parent | 6db01ccde7ad020265f118e8c2ba90d9cfd25cb8 (diff) | |
download | ffmpeg-bd908055c8f72ac994d6ea5d44e7b818e570e6af.tar.gz |
avcodec/htmlsubtitles: Check for string truncation and return error
Fixes out of array access
Fixes: 1354/clusterfuzz-testcase-minimized-5520132195483648
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit f4ae3cce64bd46b1d539bdeac39753f83015f114)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/srtdec.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index a9e7a53559..0fd651c2f0 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -49,11 +49,12 @@ typedef struct SrtStack { static void rstrip_spaces_buf(AVBPrint *buf) { - while (buf->len > 0 && buf->str[buf->len - 1] == ' ') - buf->str[--buf->len] = 0; + if (av_bprint_is_complete(buf)) + while (buf->len > 0 && buf->str[buf->len - 1] == ' ') + buf->str[--buf->len] = 0; } -static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst, +static int srt_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *in, int x1, int y1, int x2, int y2) { char *param, buffer[128], tmp[128]; @@ -191,10 +192,15 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst, line_start = 0; } + if (!av_bprint_is_complete(dst)) + return AVERROR(ENOMEM); + while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2)) dst->len -= 2; dst->str[dst->len] = 0; rstrip_spaces_buf(dst); + + return 0; } static int srt_decode_frame(AVCodecContext *avctx, |