From efdee7e6733b14a67dbda6d47b2d26bb0a66c174 Mon Sep 17 00:00:00 2001 From: Andreas Cadhalpun Date: Fri, 27 Nov 2015 21:20:09 +0100 Subject: [PATCH] Imported Upstream version 2.8.3 --- Changelog | 37 +++++++++++++++++++++++++++++++++++ RELEASE | 2 +- VERSION | 2 +- doc/Doxyfile | 2 +- libavcodec/aacps.c | 2 +- libavcodec/aacsbr_template.c | 10 ++++++++++ libavcodec/avrndec.c | 2 +- libavcodec/cabac.c | 5 ++++- libavcodec/cabac.h | 2 +- libavcodec/cabac_functions.h | 6 ++++-- libavcodec/dds.c | 21 ++++++++++++++++++++ libavcodec/dpx.c | 4 ++-- libavcodec/dvdsubdec.c | 2 +- libavcodec/dxtory.c | 4 ++-- libavcodec/error_resilience.c | 15 +++++++++----- libavcodec/flashsv.c | 8 ++++++++ libavcodec/h264_cabac.c | 5 ++++- libavcodec/h264_slice.c | 5 ++++- libavcodec/hqx.c | 4 ++-- libavcodec/ivi.c | 3 ++- libavcodec/jpeg2000.c | 13 ++++++++++-- libavcodec/jpeg2000.h | 18 ++++++++--------- libavcodec/jpeg2000dec.c | 18 +++++++++++++---- libavcodec/jpeg2000dwt.c | 8 ++++---- libavcodec/jpeg2000dwt.h | 4 ++-- libavcodec/mpegvideo.c | 1 + libavcodec/pngdec.c | 5 ++++- libavcodec/sbr.h | 1 + libavcodec/smacker.c | 4 ++++ libavcodec/takdec.c | 4 ++-- libavcodec/utils.c | 2 +- libavcodec/wmaprodec.c | 5 +++++ libavformat/brstm.c | 2 +- libavformat/matroskadec.c | 1 + libavformat/mxfdec.c | 10 ++++++++++ libavformat/rtmpcrypt.c | 7 ++++++- libavformat/utils.c | 2 +- libavutil/softfloat.h | 2 ++ 38 files changed, 196 insertions(+), 52 deletions(-) diff --git a/Changelog b/Changelog index f539e6347..7e70b1120 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,43 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. +version 2.8.3 +- avcodec/cabac: Check initial cabac decoder state +- avcodec/cabac_functions: Fix "left shift of negative value -31767" +- avcodec/h264_slice: Limit max_contexts when slice_context_count is initialized +- rtmpcrypt: Do the xtea decryption in little endian mode +- avformat/matroskadec: Check subtitle stream before dereferencing +- avcodec/pngdec: Replace assert by request for sample for unsupported TRNS cases +- avformat/utils: Do not init parser if probing is unfinished +- avcodec/jpeg2000dec: Fix potential integer overflow with tile dimensions +- avcodec/jpeg2000: Use av_image_check_size() in ff_jpeg2000_init_component() +- avcodec/wmaprodec: Check for overread in decode_packet() +- avcodec/smacker: Check that the data size is a multiple of a sample vector +- avcodec/takdec: Skip last p2 sample (which is unused) +- avcodec/dxtory: Fix input size check in dxtory_decode_v1_410() +- avcodec/dxtory: Fix input size check in dxtory_decode_v1_420() +- avcodec/error_resilience: avoid accessing previous or next frames tables beyond height +- avcodec/dpx: Move need_align to act per line +- avcodec/flashsv: Check size before updating it +- avcodec/ivi: Check image dimensions +- avcodec/utils: Better check for channels in av_get_audio_frame_duration() +- avcodec/jpeg2000dec: Check for duplicate SIZ marker +- aacsbr: don't call sbr_dequant twice without intermediate read_sbr_data +- hqx: correct type and size check of info_offset +- mxfdec: check edit_rate also for physical_track +- avcodec/jpeg2000: Change coord to 32bit to support larger than 32k width or height +- avcodec/jpeg2000dec: Check SIZ dimensions to be within the supported range +- avcodec/jpeg2000: Check comp coords to be within the supported size +- mpegvideo: clear overread in clear_context +- avcodec/avrndec: Use the AVFrame format instead of the context +- dds: disable palette flag for compressed images +- dds: validate compressed source buffer size +- dds: validate source buffer size before copying +- dvdsubdec: validate offset2 similar to offset1 +- brstm: reject negative sample rate +- aacps: avoid division by zero in stereo_processing +- softfloat: assert when the argument of av_sqrt_sf is negative + version 2.8.2 - various fixes in the aac_fixed decoder - various fixes in softfloat diff --git a/RELEASE b/RELEASE index 1817afea4..9f8d8a916 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -2.8.2 +2.8.3 diff --git a/VERSION b/VERSION index 1817afea4..9f8d8a916 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.8.2 +2.8.3 diff --git a/doc/Doxyfile b/doc/Doxyfile index 5e9a9033b..f4e3ca8eb 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -31,7 +31,7 @@ PROJECT_NAME = FFmpeg # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 2.8.2 +PROJECT_NUMBER = 2.8.3 # With the PROJECT_LOGO tag one can specify a logo or icon that is included # in the documentation. The maximum height of the logo should not exceed 55 diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c index 1165d9be3..ccc79ffc1 100644 --- a/libavcodec/aacps.c +++ b/libavcodec/aacps.c @@ -940,7 +940,7 @@ static void stereo_processing(PSContext *ps, INTFLOAT (*l)[32][2], INTFLOAT (*r) LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]); int start = ps->border_position[e]; int stop = ps->border_position[e+1]; - INTFLOAT width = Q30(1.f) / (stop - start); + INTFLOAT width = Q30(1.f) / ((stop - start) ? (stop - start) : 1); #if USE_FIXED width <<= 1; #endif diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c index 8a0268d12..a49940a07 100644 --- a/libavcodec/aacsbr_template.c +++ b/libavcodec/aacsbr_template.c @@ -70,6 +70,7 @@ av_cold void AAC_RENAME(ff_aac_sbr_init)(void) /** Places SBR in pure upsampling mode. */ static void sbr_turnoff(SpectralBandReplication *sbr) { sbr->start = 0; + sbr->ready_for_dequant = 0; // Init defults used in pure upsampling mode sbr->kx[1] = 32; //Typo in spec, kx' inits to 32 sbr->m[1] = 0; @@ -177,6 +178,7 @@ static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext SpectrumParameters old_spectrum_params; sbr->start = 1; + sbr->ready_for_dequant = 0; // Save last spectrum parameters variables to compare to new ones memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)); @@ -1032,6 +1034,7 @@ static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, unsigned int cnt = get_bits_count(gb); sbr->id_aac = id_aac; + sbr->ready_for_dequant = 1; if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) { if (read_sbr_single_channel_element(ac, sbr, gb)) { @@ -1449,6 +1452,12 @@ void AAC_RENAME(ff_sbr_apply)(AACContext *ac, SpectralBandReplication *sbr, int sbr_turnoff(sbr); } + if (sbr->start && !sbr->ready_for_dequant) { + av_log(ac->avctx, AV_LOG_ERROR, + "No quantized data read for sbr_dequant.\n"); + sbr_turnoff(sbr); + } + if (!sbr->kx_and_m_pushed) { sbr->kx[0] = sbr->kx[1]; sbr->m[0] = sbr->m[1]; @@ -1458,6 +1467,7 @@ void AAC_RENAME(ff_sbr_apply)(AACContext *ac, SpectralBandReplication *sbr, int if (sbr->start) { sbr_dequant(sbr, id_aac); + sbr->ready_for_dequant = 0; } for (ch = 0; ch < nch; ch++) { /* decode channel */ diff --git a/libavcodec/avrndec.c b/libavcodec/avrndec.c index 5e40d664d..695c4912f 100644 --- a/libavcodec/avrndec.c +++ b/libavcodec/avrndec.c @@ -113,7 +113,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int shift = p->height - avctx->height; int subsample_h, subsample_v; - av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &subsample_h, &subsample_v); + av_pix_fmt_get_chroma_sub_sample(p->format, &subsample_h, &subsample_v); p->data[0] += p->linesize[0] * shift; if (p->data[2]) { diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index 8cc9333e0..f298336ea 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -51,7 +51,7 @@ void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size){ * * @param buf_size size of buf in bits */ -void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ +int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ c->bytestream_start= c->bytestream= buf; c->bytestream_end= buf + buf_size; @@ -64,6 +64,9 @@ void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ #endif c->low+= ((*c->bytestream++)<<2) + 2; c->range= 0x1FE; + if ((c->range<<(CABAC_BITS+1)) < c->low) + return AVERROR_INVALIDDATA; + return 0; } void ff_init_cabac_states(void) diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h index f9eafed10..857211c9d 100644 --- a/libavcodec/cabac.h +++ b/libavcodec/cabac.h @@ -56,7 +56,7 @@ typedef struct CABACContext{ }CABACContext; void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); -void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); +int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); void ff_init_cabac_states(void); #endif /* AVCODEC_CABAC_H */ diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h index 15dba29f8..2d1d2a6b8 100644 --- a/libavcodec/cabac_functions.h +++ b/libavcodec/cabac_functions.h @@ -74,7 +74,8 @@ static inline void renorm_cabac_decoder_once(CABACContext *c){ #ifndef get_cabac_inline static void refill2(CABACContext *c){ - int i, x; + int i; + unsigned x; x= c->low ^ (c->low-1); i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)]; @@ -190,7 +191,8 @@ static av_unused const uint8_t* skip_bytes(CABACContext *c, int n) { #endif if ((int) (c->bytestream_end - ptr) < n) return NULL; - ff_init_cabac_decoder(c, ptr + n, c->bytestream_end - ptr - n); + if (ff_init_cabac_decoder(c, ptr + n, c->bytestream_end - ptr - n) < 0) + return NULL; return ptr; } diff --git a/libavcodec/dds.c b/libavcodec/dds.c index a604d5690..9e29ada78 100644 --- a/libavcodec/dds.c +++ b/libavcodec/dds.c @@ -141,6 +141,12 @@ static int parse_pixel_format(AVCodecContext *avctx) normal_map = flags & DDPF_NORMALMAP; fourcc = bytestream2_get_le32(gbc); + if (ctx->compressed && ctx->paletted) { + av_log(avctx, AV_LOG_WARNING, + "Disabling invalid palette flag for compressed dds.\n"); + ctx->paletted = 0; + } + bpp = bytestream2_get_le32(gbc); // rgbbitcount r = bytestream2_get_le32(gbc); // rbitmask g = bytestream2_get_le32(gbc); // gbitmask @@ -642,9 +648,18 @@ static int dds_decode(AVCodecContext *avctx, void *data, return ret; if (ctx->compressed) { + int size = (avctx->coded_height / TEXTURE_BLOCK_H) * + (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio; ctx->slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); + if (bytestream2_get_bytes_left(gbc) < size) { + av_log(avctx, AV_LOG_ERROR, + "Compressed Buffer is too small (%d < %d).\n", + bytestream2_get_bytes_left(gbc), size); + return AVERROR_INVALIDDATA; + } + /* Use the decompress function on the texture, one block per thread. */ ctx->tex_data = gbc->buffer; avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count); @@ -666,6 +681,12 @@ static int dds_decode(AVCodecContext *avctx, void *data, frame->palette_has_changed = 1; } + if (bytestream2_get_bytes_left(gbc) < frame->height * linesize) { + av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", + bytestream2_get_bytes_left(gbc), frame->height * linesize); + return AVERROR_INVALIDDATA; + } + av_image_copy_plane(frame->data[0], frame->linesize[0], gbc->buffer, linesize, linesize, frame->height); diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c index 15c939fca..af7276adb 100644 --- a/libavcodec/dpx.c +++ b/libavcodec/dpx.c @@ -348,11 +348,11 @@ static int decode_frame(AVCodecContext *avctx, // For 12 bit, ignore alpha if (elements == 4) buf += 2; - // Jump to next aligned position - buf += need_align; } for (i = 0; i < 3; i++) ptr[i] += p->linesize[i]; + // Jump to next aligned position + buf += need_align; } break; case 16: diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index 7120f10a5..f00982440 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -346,7 +346,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, } } the_end: - if (offset1 >= 0) { + if (offset1 >= 0 && offset2 >= 0) { int w, h; uint8_t *bitmap; diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c index 62bdd32ce..578ac02ef 100644 --- a/libavcodec/dxtory.c +++ b/libavcodec/dxtory.c @@ -65,7 +65,7 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic, uint8_t *Y1, *Y2, *Y3, *Y4, *U, *V; int ret; - if (src_size < avctx->width * avctx->height * 9LL / 8) { + if (src_size < FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) * 9LL / 8) { av_log(avctx, AV_LOG_ERROR, "packet too small\n"); return AVERROR_INVALIDDATA; } @@ -108,7 +108,7 @@ static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic, uint8_t *Y1, *Y2, *U, *V; int ret; - if (src_size < avctx->width * avctx->height * 3LL / 2) { + if (src_size < FFALIGN(avctx->width, 2) * FFALIGN(avctx->height, 2) * 3LL / 2) { av_log(avctx, AV_LOG_ERROR, "packet too small\n"); return AVERROR_INVALIDDATA; } diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 2c741a4a1..5a75faddf 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -381,14 +381,19 @@ static void guess_mv(ERContext *s) #define MV_UNCHANGED 1 const int mb_stride = s->mb_stride; const int mb_width = s->mb_width; - const int mb_height = s->mb_height; + int mb_height = s->mb_height; int i, depth, num_avail; int mb_x, mb_y, mot_step, mot_stride; + if (s->last_pic.f && s->last_pic.f->data[0]) + mb_height = FFMIN(mb_height, (s->last_pic.f->height+15)>>4); + if (s->next_pic.f && s->next_pic.f->data[0]) + mb_height = FFMIN(mb_height, (s->next_pic.f->height+15)>>4); + set_mv_strides(s, &mot_step, &mot_stride); num_avail = 0; - for (i = 0; i < s->mb_num; i++) { + for (i = 0; i < mb_width * mb_height; i++) { const int mb_xy = s->mb_index2xy[i]; int f = 0; int error = s->error_status_table[mb_xy]; @@ -413,7 +418,7 @@ static void guess_mv(ERContext *s) if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width / 2) { - for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + for (mb_y = 0; mb_y < mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; int mv_dir = (s->last_pic.f && s->last_pic.f->data[0]) ? MV_DIR_FORWARD : MV_DIR_BACKWARD; @@ -442,7 +447,7 @@ static void guess_mv(ERContext *s) int score_sum = 0; changed = 0; - for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + for (mb_y = 0; mb_y < mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int mb_xy = mb_x + mb_y * s->mb_stride; int mv_predictor[8][2] = { { 0 } }; @@ -675,7 +680,7 @@ skip_last_mv: if (none_left) return; - for (i = 0; i < s->mb_num; i++) { + for (i = 0; i < mb_width * mb_height; i++) { int mb_xy = s->mb_index2xy[i]; if (fixed[mb_xy]) fixed[mb_xy] = MV_FROZEN; diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c index 69b56d116..90e1d43cd 100644 --- a/libavcodec/flashsv.c +++ b/libavcodec/flashsv.c @@ -413,6 +413,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, } if (has_diff) { + if (size < 3) { + av_log(avctx, AV_LOG_ERROR, "size too small for diff\n"); + return AVERROR_INVALIDDATA; + } if (!s->keyframe) { av_log(avctx, AV_LOG_ERROR, "Inter frame without keyframe\n"); @@ -440,6 +444,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data, int row = get_bits(&gb, 8); av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_curr %dx%d\n", i, j, col, row); + if (size < 3) { + av_log(avctx, AV_LOG_ERROR, "size too small for zlibprime_curr\n"); + return AVERROR_INVALIDDATA; + } size -= 2; avpriv_request_sample(avctx, "zlibprime_curr"); return AVERROR_PATCHWELCOME; diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index c1c8b8085..04d412b74 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -2026,6 +2026,7 @@ decode_intra_mb: const int mb_size = ff_h264_mb_sizes[h->sps.chroma_format_idc] * h->sps.bit_depth_luma >> 3; const uint8_t *ptr; + int ret; // We assume these blocks are very rare so we do not optimize it. // FIXME The two following lines get the bitstream position in the cabac @@ -2042,7 +2043,9 @@ decode_intra_mb: sl->intra_pcm_ptr = ptr; ptr += mb_size; - ff_init_cabac_decoder(&sl->cabac, ptr, sl->cabac.bytestream_end - ptr); + ret = ff_init_cabac_decoder(&sl->cabac, ptr, sl->cabac.bytestream_end - ptr); + if (ret < 0) + return ret; // All blocks are present h->cbp_table[mb_xy] = 0xf7ef; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 9642dc55d..843cfd097 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1097,6 +1097,7 @@ static int h264_slice_header_init(H264Context *h) nb_slices = max_slices; } h->slice_context_count = nb_slices; + h->max_contexts = FFMIN(h->max_contexts, nb_slices); if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) { ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]); @@ -2371,9 +2372,11 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) align_get_bits(&sl->gb); /* init cabac */ - ff_init_cabac_decoder(&sl->cabac, + ret = ff_init_cabac_decoder(&sl->cabac, sl->gb.buffer + get_bits_count(&sl->gb) / 8, (get_bits_left(&sl->gb) + 7) / 8); + if (ret < 0) + return ret; ff_h264_init_cabac_states(h, sl); diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c index 8060c7a31..138d96041 100644 --- a/libavcodec/hqx.c +++ b/libavcodec/hqx.c @@ -417,8 +417,8 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data, info_tag = AV_RL32(src); if (info_tag == MKTAG('I', 'N', 'F', 'O')) { - int info_offset = AV_RL32(src + 4); - if (info_offset > UINT32_MAX - 8 || info_offset + 8 > avpkt->size) { + unsigned info_offset = AV_RL32(src + 4); + if (info_offset > INT_MAX || info_offset + 8 > avpkt->size) { av_log(avctx, AV_LOG_ERROR, "Invalid INFO header offset: 0x%08"PRIX32" is too large.\n", info_offset); diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c index 4525ff494..eab42bb53 100644 --- a/libavcodec/ivi.c +++ b/libavcodec/ivi.c @@ -30,6 +30,7 @@ #define BITSTREAM_READER_LE #include "libavutil/attributes.h" +#include "libavutil/imgutils.h" #include "libavutil/timer.h" #include "avcodec.h" #include "get_bits.h" @@ -310,7 +311,7 @@ av_cold int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, ivi_free_buffers(planes); - if (cfg->pic_width < 1 || cfg->pic_height < 1 || + if (av_image_check_size(cfg->pic_width, cfg->pic_height, 0, NULL) < 0 || cfg->luma_bands < 1 || cfg->chroma_bands < 1) return AVERROR_INVALIDDATA; diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index 09654e82f..abf8834b1 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -28,6 +28,7 @@ #include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/imgutils.h" #include "libavutil/mem.h" #include "avcodec.h" #include "jpeg2000.h" @@ -210,9 +211,17 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, codsty->nreslevels2decode - 1, codsty->transform)) return ret; - // component size comp->coord is uint16_t so ir cannot overflow + + if (av_image_check_size(comp->coord[0][1] - comp->coord[0][0], + comp->coord[1][1] - comp->coord[1][0], 0, avctx)) + return AVERROR_INVALIDDATA; csize = (comp->coord[0][1] - comp->coord[0][0]) * (comp->coord[1][1] - comp->coord[1][0]); + if (comp->coord[0][1] - comp->coord[0][0] > 32768 || + comp->coord[1][1] - comp->coord[1][0] > 32768) { + av_log(avctx, AV_LOG_ERROR, "component size too large\n"); + return AVERROR_PATCHWELCOME; + } if (codsty->transform == FF_DWT97) { csize += AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*comp->f_data); @@ -450,7 +459,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, return AVERROR(ENOMEM); for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) { Jpeg2000Cblk *cblk = prec->cblk + cblkno; - uint16_t Cx0, Cy0; + int Cx0, Cy0; /* Compute coordinates of codeblocks */ /* Compute Cx0*/ diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h index 7a21c4e45..ed3b421ad 100644 --- a/libavcodec/jpeg2000.h +++ b/libavcodec/jpeg2000.h @@ -174,21 +174,21 @@ typedef struct Jpeg2000Cblk { int nb_terminationsinc; int data_start[JPEG2000_MAX_PASSES]; Jpeg2000Pass passes[JPEG2000_MAX_PASSES]; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} } Jpeg2000Cblk; // code block typedef struct Jpeg2000Prec { - uint16_t nb_codeblocks_width; - uint16_t nb_codeblocks_height; + int nb_codeblocks_width; + int nb_codeblocks_height; Jpeg2000TgtNode *zerobits; Jpeg2000TgtNode *cblkincl; Jpeg2000Cblk *cblk; int decoded_layers; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} } Jpeg2000Prec; // precinct typedef struct Jpeg2000Band { - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} uint16_t log2_cblk_width, log2_cblk_height; int i_stepsize; // quantization stepsize float f_stepsize; // quantization stepsize @@ -197,8 +197,8 @@ typedef struct Jpeg2000Band { typedef struct Jpeg2000ResLevel { uint8_t nbands; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} - uint16_t num_precincts_x, num_precincts_y; // number of precincts in x/y direction + int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} + int num_precincts_x, num_precincts_y; // number of precincts in x/y direction uint8_t log2_prec_width, log2_prec_height; // exponent of precinct size Jpeg2000Band *band; } Jpeg2000ResLevel; // resolution level @@ -208,8 +208,8 @@ typedef struct Jpeg2000Component { DWTContext dwt; float *f_data; int *i_data; - uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- can be reduced with lowres option - uint16_t coord_o[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- original values from jpeg2000 headers + int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- can be reduced with lowres option + int coord_o[2][2]; // border coordinates {{x0, x1}, {y0, y1}} -- original values from jpeg2000 headers } Jpeg2000Component; /* misc tools */ diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 88a1677e8..214ff056d 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -30,6 +30,7 @@ #include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/imgutils.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" @@ -279,6 +280,10 @@ static int get_siz(Jpeg2000DecoderContext *s) avpriv_request_sample(s->avctx, "Support for image offsets"); return AVERROR_PATCHWELCOME; } + if (av_image_check_size(s->width, s->height, 0, s->avctx)) { + avpriv_request_sample(s->avctx, "Large Dimensions"); + return AVERROR_PATCHWELCOME; + } if (ncomponents <= 0) { av_log(s->avctx, AV_LOG_ERROR, "Invalid number of components: %d\n", @@ -826,10 +831,10 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) if (!tile->comp) return AVERROR(ENOMEM); - tile->coord[0][0] = av_clip(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x, s->width); - tile->coord[0][1] = av_clip((tilex + 1) * s->tile_width + s->tile_offset_x, s->image_offset_x, s->width); - tile->coord[1][0] = av_clip(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y, s->height); - tile->coord[1][1] = av_clip((tiley + 1) * s->tile_height + s->tile_offset_y, s->image_offset_y, s->height); + tile->coord[0][0] = av_clip(tilex * (int64_t)s->tile_width + s->tile_offset_x, s->image_offset_x, s->width); + tile->coord[0][1] = av_clip((tilex + 1) * (int64_t)s->tile_width + s->tile_offset_x, s->image_offset_x, s->width); + tile->coord[1][0] = av_clip(tiley * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height); + tile->coord[1][1] = av_clip((tiley + 1) * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height); for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; @@ -1812,6 +1817,7 @@ static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s) memset(s->properties, 0, sizeof(s->properties)); memset(&s->poc , 0, sizeof(s->poc)); s->numXtiles = s->numYtiles = 0; + s->ncomponents = 0; } static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) @@ -1869,6 +1875,10 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s) switch (marker) { case JPEG2000_SIZ: + if (s->ncomponents) { + av_log(s->avctx, AV_LOG_ERROR, "Duplicate SIZ\n"); + return AVERROR_INVALIDDATA; + } ret = get_siz(s); if (!s->tile) s->numXtiles = s->numYtiles = 0; diff --git a/libavcodec/jpeg2000dwt.c b/libavcodec/jpeg2000dwt.c index 28ac6c429..2bf25a8c4 100644 --- a/libavcodec/jpeg2000dwt.c +++ b/libavcodec/jpeg2000dwt.c @@ -534,7 +534,7 @@ static void dwt_decode97_int(DWTContext *s, int32_t *t) data[i] = (data[i] + ((1<>1)) >> I_PRESHIFT; } -int ff_jpeg2000_dwt_init(DWTContext *s, uint16_t border[2][2], +int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2], int decomp_levels, int type) { int i, j, lev = decomp_levels, maxlen, @@ -623,7 +623,7 @@ void ff_dwt_destroy(DWTContext *s) #define MAX_W 256 -static int test_dwt(int *array, int *ref, uint16_t border[2][2], int decomp_levels, int type, int max_diff) { +static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, int type, int max_diff) { int ret, j; DWTContext s1={{{0}}}, *s= &s1; int64_t err2 = 0; @@ -662,7 +662,7 @@ static int test_dwt(int *array, int *ref, uint16_t border[2][2], int decomp_leve return 0; } -static int test_dwtf(float *array, float *ref, uint16_t border[2][2], int decomp_levels, float max_diff) { +static int test_dwtf(float *array, float *ref, int border[2][2], int decomp_levels, float max_diff) { int ret, j; DWTContext s1={{{0}}}, *s= &s1; double err2 = 0; @@ -708,7 +708,7 @@ static float reff [MAX_W * MAX_W]; int main(void) { AVLFG prng; int i,j; - uint16_t border[2][2]; + int border[2][2]; int ret, decomp_levels; av_lfg_init(&prng, 1); diff --git a/libavcodec/jpeg2000dwt.h b/libavcodec/jpeg2000dwt.h index 57297d412..718d183ac 100644 --- a/libavcodec/jpeg2000dwt.h +++ b/libavcodec/jpeg2000dwt.h @@ -42,7 +42,7 @@ enum DWTType { typedef struct DWTContext { /// line lengths { horizontal, vertical } in consecutive decomposition levels - uint16_t linelen[FF_DWT_MAX_DECLVLS][2]; + int linelen[FF_DWT_MAX_DECLVLS][2]; uint8_t mod[FF_DWT_MAX_DECLVLS][2]; ///< coordinates (x0, y0) of decomp. levels mod 2 uint8_t ndeclevels; ///< number of decomposition levels uint8_t type; ///< 0 for 9/7; 1 for 5/3 @@ -57,7 +57,7 @@ typedef struct DWTContext { * @param decomp_levels number of decomposition levels * @param type 0 for DWT 9/7; 1 for DWT 5/3 */ -int ff_jpeg2000_dwt_init(DWTContext *s, uint16_t border[2][2], +int ff_jpeg2000_dwt_init(DWTContext *s, int border[2][2], int decomp_levels, int type); int ff_dwt_encode(DWTContext *s, void *t); diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index f28f7e886..4a40cf96d 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -815,6 +815,7 @@ static void clear_context(MpegEncContext *s) s->parse_context.buffer = NULL; s->parse_context.buffer_size = 0; + s->parse_context.overread = 0; s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; s->picture = NULL; diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 614c6a522..b4d1fb59a 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -663,7 +663,10 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, break; default: - av_assert0(0); + avpriv_request_sample(avctx, "bit depth %d " + "and color type %d with TRNS", + s->bit_depth, s->color_type); + return AVERROR_INVALIDDATA; } s->bpp += byte_depth; diff --git a/libavcodec/sbr.h b/libavcodec/sbr.h index 66a88a289..91ab82c7a 100644 --- a/libavcodec/sbr.h +++ b/libavcodec/sbr.h @@ -137,6 +137,7 @@ typedef struct AACSBRContext { struct SpectralBandReplication { int sample_rate; int start; + int ready_for_dequant; int id_aac; int reset; SpectrumParameters spectrum_params; diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index b2fc29b13..4014e8d04 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -670,6 +670,10 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ frame->nb_samples = unp_size / (avctx->channels * (bits + 1)); + if (unp_size % (avctx->channels * (bits + 1))) { + av_log(avctx, AV_LOG_ERROR, "unp_size %d is odd\n", unp_size); + return AVERROR(EINVAL); + } if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; samples = (int16_t *)frame->data[0]; diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c index 2acdb924c..c83fb66c5 100644 --- a/libavcodec/takdec.c +++ b/libavcodec/takdec.c @@ -632,7 +632,7 @@ static int decorrelate(TAKDecContext *s, int c1, int c2, int length) for (; length2 > 0; length2 -= tmp) { tmp = FFMIN(length2, x); - for (i = 0; i < tmp; i++) + for (i = 0; i < tmp - (tmp == length2); i++) s->residues[filter_order + i] = *p2++ >> dshift; for (i = 0; i < tmp; i++) { @@ -656,7 +656,7 @@ static int decorrelate(TAKDecContext *s, int c1, int c2, int length) *p1++ = v; } - memcpy(s->residues, &s->residues[tmp], 2 * filter_order); + memmove(s->residues, &s->residues[tmp], 2 * filter_order); } emms_c(); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index f51070c5b..735e71a04 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3490,7 +3490,7 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) return frame_bytes * 8 / bps; } - if (ch > 0) { + if (ch > 0 && ch < INT_MAX/16) { /* calc from frame_bytes and channels */ switch (id) { case AV_CODEC_ID_ADPCM_AFC: diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index 19dc335b3..7f6d3edd2 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -1623,6 +1623,11 @@ static int decode_packet(AVCodecContext *avctx, void *data, s->packet_done = 1; } + if (remaining_bits(s, gb) < 0) { + av_log(avctx, AV_LOG_ERROR, "Overread %d\n", -remaining_bits(s, gb)); + s->packet_loss = 1; + } + if (s->packet_done && !s->packet_loss && remaining_bits(s, gb) > 0) { /** save the rest of the data so that it can be decoded diff --git a/libavformat/brstm.c b/libavformat/brstm.c index f2bc03884..7ad40b0b1 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -205,7 +205,7 @@ static int read_header(AVFormatContext *s) avio_skip(s->pb, 1); // padding st->codec->sample_rate = bfstm ? read32(s) : read16(s); - if (!st->codec->sample_rate) + if (st->codec->sample_rate <= 0) return AVERROR_INVALIDDATA; if (!bfstm) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 43ad9af0d..3449a2922 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3088,6 +3088,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; tracks[i].end_timecode = 0; if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE && + tracks[i].stream && tracks[i].stream->discard != AVDISCARD_ALL) { index_sub = av_index_search_timestamp( tracks[i].stream, st->index_entries[index].timestamp, diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 00d420b44..2c18549f5 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1776,6 +1776,16 @@ static int mxf_parse_physical_source_package(MXFContext *mxf, MXFTrack *source_t continue; } + if (physical_track->edit_rate.num <= 0 || + physical_track->edit_rate.den <= 0) { + av_log(mxf->fc, AV_LOG_WARNING, + "Invalid edit rate (%d/%d) found on structural" + " component #%d, defaulting to 25/1\n", + physical_track->edit_rate.num, + physical_track->edit_rate.den, i); + physical_track->edit_rate = (AVRational){25, 1}; + } + for (k = 0; k < physical_track->sequence->structural_components_count; k++) { if (!(mxf_tc = mxf_resolve_timecode_component(mxf, &physical_track->sequence->structural_components_refs[k]))) continue; diff --git a/libavformat/rtmpcrypt.c b/libavformat/rtmpcrypt.c index 2065ec660..377190985 100644 --- a/libavformat/rtmpcrypt.c +++ b/libavformat/rtmpcrypt.c @@ -184,9 +184,14 @@ int ff_rtmpe_compute_secret_key(URLContext *h, const uint8_t *serverdata, static void rtmpe8_sig(const uint8_t *in, uint8_t *out, int key_id) { struct AVXTEA ctx; + uint8_t tmpbuf[8]; av_xtea_init(&ctx, rtmpe8_keys[key_id]); - av_xtea_crypt(&ctx, out, in, 1, NULL, 0); + AV_WB32(tmpbuf, AV_RL32(in)); + AV_WB32(tmpbuf + 4, AV_RL32(in + 4)); + av_xtea_crypt(&ctx, tmpbuf, tmpbuf, 1, NULL, 0); + AV_WL32(out, AV_RB32(tmpbuf)); + AV_WL32(out + 4, AV_RB32(tmpbuf + 4)); } static void rtmpe9_sig(const uint8_t *in, uint8_t *out, int key_id) diff --git a/libavformat/utils.c b/libavformat/utils.c index e67147c24..386ce37a7 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3139,7 +3139,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->codec->time_base = st->time_base; } // only for the split stuff - if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) { + if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && st->request_probe <= 0) { st->parser = av_parser_init(st->codec->codec_id); if (st->parser) { if (st->need_parsing == AVSTREAM_PARSE_HEADERS) { diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h index facfbc242..7488753d6 100644 --- a/libavutil/softfloat.h +++ b/libavutil/softfloat.h @@ -179,6 +179,8 @@ static av_always_inline SoftFloat av_sqrt_sf(SoftFloat val) if (val.mant == 0) val.exp = MIN_EXP; + else if (val.mant < 0) + abort(); else { tabIndex = (val.mant - 0x20000000) >> 20;