summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-10-03 01:50:27 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-03-12 18:03:48 +0100
commitbb6a8a0509d5fcc93aff6e3c62135ed5f6f9cb25 (patch)
tree736a28125fa2e3a02f10471792d1efefbe54deb5
parent1704a7b67dce9acacee9ebd381b8f5b63a9bc486 (diff)
downloadffmpeg-bb6a8a0509d5fcc93aff6e3c62135ed5f6f9cb25.tar.gz
avcodec/mjpegdec: check bits per pixel for changes similar to dimensions
Fixes out of array accesses Fixes: asan_heap-oob_16668e9_2_asan_heap-oob_16668e9_346_miss_congeniality_pegasus_mjpg.avi Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 5c378d6a6df8243f06c87962b873bd563e58cd39) Conflicts: libavcodec/mjpegdec.c (cherry picked from commit 94371a404c663c3dae3d542fa43951567ab67f82) Conflicts: libavcodec/mjpegdec.c Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/mjpegdec.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 9aee5956c1..d0520a3c2a 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -216,21 +216,21 @@ int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
{
- int len, nb_components, i, width, height, pix_fmt_id;
+ int len, nb_components, i, width, height, bits, pix_fmt_id;
s->cur_scan = 0;
s->upscale_h = s->upscale_v = 0;
/* XXX: verify len field validity */
len = get_bits(&s->gb, 16);
- s->bits = get_bits(&s->gb, 8);
+ bits = get_bits(&s->gb, 8);
if (s->pegasus_rct)
- s->bits = 9;
- if (s->bits == 9 && !s->pegasus_rct)
+ bits = 9;
+ if (bits == 9 && !s->pegasus_rct)
s->rct = 1; // FIXME ugly
- if (s->bits != 8 && !s->lossless) {
+ if (bits != 8 && !s->lossless) {
av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n");
return -1;
}
@@ -262,7 +262,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
return AVERROR_INVALIDDATA;
}
}
- if (s->ls && !(s->bits <= 8 || nb_components == 1)) {
+ if (s->ls && !(bits <= 8 || nb_components == 1)) {
av_log(s->avctx, AV_LOG_ERROR,
"only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n");
return -1;
@@ -306,11 +306,14 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
/* if different size, realloc/alloc picture */
/* XXX: also check h_count and v_count */
- if (width != s->width || height != s->height) {
+ if ( width != s->width || height != s->height
+ || bits != s->bits
+ ) {
av_freep(&s->qscale_table);
s->width = width;
s->height = height;
+ s->bits = bits;
s->interlaced = 0;
/* test interlaced mode */