summaryrefslogtreecommitdiff
path: root/libavcodec/jpeg2000dec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-07-01 10:01:07 +0200
committerLuca Barbato <lu_zero@gentoo.org>2013-07-02 20:05:44 +0200
commiteae63e3c156f784ee0612422f0c95131ea913c14 (patch)
tree4c0b0858f564cf83a944aa6457cbb81e1862d58a /libavcodec/jpeg2000dec.c
parent17e5d614a8647d51b9795cb8bccf97ee33ca2d58 (diff)
jpeg2000: Check component number in get_coc() and get_qcc()
Avoid overreads. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas Bertrand <nicoinattendu@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec/jpeg2000dec.c')
-rw-r--r--libavcodec/jpeg2000dec.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index ffe97eb59b..8cc1094fee 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -362,6 +362,13 @@ static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
compno = bytestream2_get_byteu(&s->g);
+ if (compno >= s->ncomponents) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Invalid compno %d. There are %d components in the image.\n",
+ compno, s->ncomponents);
+ return AVERROR_INVALIDDATA;
+ }
+
c += compno;
c->csty = bytestream2_get_byteu(&s->g);
get_cox(s, c);
@@ -440,7 +447,15 @@ static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
if (bytestream2_get_bytes_left(&s->g) < 1)
return AVERROR_INVALIDDATA;
- compno = bytestream2_get_byteu(&s->g);
+ compno = bytestream2_get_byteu(&s->g);
+
+ if (compno >= s->ncomponents) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Invalid compno %d. There are %d components in the image.\n",
+ compno, s->ncomponents);
+ return AVERROR_INVALIDDATA;
+ }
+
properties[compno] |= HAD_QCC;
return get_qcx(s, n - 1, q + compno);
}