diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2019-11-21 22:43:01 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2020-04-23 21:29:01 +0200 |
commit | 2df3b2d01df0c3a84fa1d8de0cfe969fb8d0c894 (patch) | |
tree | a32fc9aa322e109cb1a7f0a11d6e548722517df0 | |
parent | 43fe5031077889f28b5bdd5404e66554d4590f4f (diff) | |
download | ffmpeg-2df3b2d01df0c3a84fa1d8de0cfe969fb8d0c894.tar.gz |
avcodec/targa: Check colors vs. available space
Fixes: Timeout (37sec -> 52ms)
Fixes: 18892/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TARGA_fuzzer-5739537854889984
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 01593278cef06dbb4491d50d03b72198d2848adf)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/targa.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libavcodec/targa.c b/libavcodec/targa.c index 215c0f51f6..879b21d13e 100644 --- a/libavcodec/targa.c +++ b/libavcodec/targa.c @@ -132,12 +132,6 @@ static int decode_frame(AVCodecContext *avctx, h = bytestream2_get_le16(&s->gb); bpp = bytestream2_get_byte(&s->gb); - if (bytestream2_get_bytes_left(&s->gb) <= idlen) { - av_log(avctx, AV_LOG_ERROR, - "Not enough data to read header\n"); - return AVERROR_INVALIDDATA; - } - flags = bytestream2_get_byte(&s->gb); if (!pal && (first_clr || colors || csize)) { @@ -146,6 +140,12 @@ static int decode_frame(AVCodecContext *avctx, first_clr = colors = csize = 0; } + if (bytestream2_get_bytes_left(&s->gb) < idlen + 2*colors) { + av_log(avctx, AV_LOG_ERROR, + "Not enough data to read header\n"); + return AVERROR_INVALIDDATA; + } + // skip identifier if any bytestream2_skip(&s->gb, idlen); |