aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2018-07-02 18:40:08 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2018-07-04 01:10:28 +0200
commit0898a3d9909960324e27d3a7a4f48c4effbb654a (patch)
treed2c8719c4fb06246eebb3e6e52838bc7a4aeffd6
parent7e22f5d457fa042292741c1f5c38232ba10dbea2 (diff)
downloadffmpeg-0898a3d9909960324e27d3a7a4f48c4effbb654a.tar.gz
avcodec/jpeg2000dec: Check that there are enough bytes for all tiles
Fixes: OOM Fixes: 8781/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5810709081358336 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/jpeg2000dec.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 66f11bb2b2..4071b5ce53 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -343,7 +343,10 @@ static int get_siz(Jpeg2000DecoderContext *s)
s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height);
- if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(*s->tile)) {
+ // There must be at least a SOT and SOD per tile, their minimum size is 14
+ if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(*s->tile) ||
+ s->numXtiles * s->numYtiles * 14LL > bytestream2_size(&s->g)
+ ) {
s->numXtiles = s->numYtiles = 0;
return AVERROR(EINVAL);
}