aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-08-24 03:19:40 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-09-27 00:35:00 +0200
commit1a311ad99a57ec3cd4f821f8a4c22973e2b4d740 (patch)
treeebeab4f736591fe057231efc10e63cc094886012
parentef8145270f4a91216b24b1552c73e7eda140c8b6 (diff)
downloadffmpeg-1a311ad99a57ec3cd4f821f8a4c22973e2b4d740.tar.gz
jpeg2000: check log2_cblk dimensions
Fixes out of array access Fixes Ticket2895 Found-by: Piotr Bandurski <ami_stuff@o2.pl> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 9a271a9368eaabf99e6c2046103acb33957e63b7) Conflicts: libavcodec/jpeg2000dec.c Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Conflicts: libavcodec/j2kdec.c Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/j2kdec.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index 78a24698a2..e4da2def00 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -28,6 +28,7 @@
#include "avcodec.h"
#include "bytestream.h"
#include "j2k.h"
+#include "libavutil/avassert.h"
#include "libavutil/common.h"
#define JP2_SIG_TYPE 0x6A502020
@@ -289,6 +290,10 @@ static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c)
c->log2_cblk_width = bytestream_get_byte(&s->buf) + 2; // cblk width
c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
+ if (c->log2_cblk_width > 6 || c->log2_cblk_height > 6) {
+ return AVERROR_PATCHWELCOME;
+ }
+
c->cblk_style = bytestream_get_byte(&s->buf);
if (c->cblk_style != 0){ // cblk style
av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
@@ -705,6 +710,9 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
+ av_assert0(width <= J2K_MAX_CBLKW);
+ av_assert0(height <= J2K_MAX_CBLKH);
+
for (y = 0; y < height+2; y++)
memset(t1->flags[y], 0, (width+2)*sizeof(int));