From: Luca Barbato <[email protected]>
---
libavcodec/jpeg2k.c | 4 +++-
libavcodec/jpeg2kdec.c | 16 ++++++++++------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/libavcodec/jpeg2k.c b/libavcodec/jpeg2k.c
index 8936240..66558c7 100644
--- a/libavcodec/jpeg2k.c
+++ b/libavcodec/jpeg2k.c
@@ -480,7 +480,9 @@ int ff_jpeg2k_init_component(Jpeg2KComponent *comp,
void ff_jpeg2k_cleanup(Jpeg2KComponent *comp, Jpeg2KCodingStyle *codsty)
{
int reslevelno, bandno, precno;
- for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
+ for (reslevelno = 0;
+ comp->reslevel && reslevelno < codsty->nreslevels;
+ reslevelno++) {
Jpeg2KResLevel *reslevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < reslevel->nbands; bandno++) {
diff --git a/libavcodec/jpeg2kdec.c b/libavcodec/jpeg2kdec.c
index e2b50b3..fcf3676 100644
--- a/libavcodec/jpeg2kdec.c
+++ b/libavcodec/jpeg2kdec.c
@@ -1344,8 +1344,10 @@ static int jpeg2k_decode_frame(AVCodecContext *avctx,
void *data,
bytestream2_init(&s->g, avpkt->data, avpkt->size);
s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for
more tiles
- if (bytestream2_get_bytes_left(&s->g) < 2)
- return AVERROR_INVALIDDATA;
+ if (bytestream2_get_bytes_left(&s->g) < 2) {
+ ret = AVERROR_INVALIDDATA;
+ goto end;
+ }
// check if the image is in jp2 format
if (bytestream2_get_bytes_left(&s->g) >= 12 &&
@@ -1355,17 +1357,17 @@ static int jpeg2k_decode_frame(AVCodecContext *avctx,
void *data,
if (!jp2_find_codestream(s)) {
av_log(avctx, AV_LOG_ERROR,
"couldn't find jpeg2k codestream atom\n");
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto end;
}
} else {
bytestream2_seek(&s->g, 0, SEEK_SET);
- if (bytestream2_peek_be16(&s->g) != JPEG2K_SOC)
- bytestream2_skip(&s->g, 8);
}
if (bytestream2_get_be16u(&s->g) != JPEG2K_SOC) {
av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto end;
}
if (ret = jpeg2k_read_main_headers(s))
goto end;
@@ -1384,6 +1386,8 @@ static int jpeg2k_decode_frame(AVCodecContext *avctx,
void *data,
if (ret = jpeg2k_decode_tile(s, s->tile + tileno, picture))
goto end;
+ jpeg2k_dec_cleanup(s);
+
*got_frame = 1;
return bytestream2_tell(&s->g);
--
1.7.9.5
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel