summaryrefslogtreecommitdiff
path: root/libavcodec/jpeg2000dec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-07-01 10:01:14 +0200
committerLuca Barbato <lu_zero@gentoo.org>2013-07-02 20:05:45 +0200
commitb564784a207b1395d2b5a41e580539df04651096 (patch)
treef896c009222af02ba9d3de125c5a3660ff032573 /libavcodec/jpeg2000dec.c
parent2c3901b2c34b5e1f556d0e19c4cc218fdcbec695 (diff)
jpeg2000: Check that there is a SOT before SOD
Avoid overreads. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec/jpeg2000dec.c')
-rw-r--r--libavcodec/jpeg2000dec.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 1b40912152..d0608f97f4 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1236,6 +1236,22 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
marker = bytestream2_get_be16u(&s->g);
oldpos = bytestream2_tell(&s->g);
+ if (marker == JPEG2000_SOD) {
+ Jpeg2000Tile *tile;
+ Jpeg2000TilePart *tp;
+
+ if (s->curtileno < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "Missing SOT\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ tile = s->tile + s->curtileno;
+ tp = tile->tile_part + tile->tp_idx;
+ bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_end - s->g.buffer);
+ bytestream2_skip(&s->g, tp->tp_end - s->g.buffer);
+
+ continue;
+ }
if (marker == JPEG2000_EOC)
break;