From fc2a94c15e775d5d7367f1ca71447ca6db689227 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 16:09:39 +0100 Subject: [PATCH 01/12] bethsoftvideo: return meaningful error codes. --- libavcodec/bethsoftvideo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/bethsoftvideo.c b/libavcodec/bethsoftvideo.c index 316adb6c79..77bf49cf47 100644 --- a/libavcodec/bethsoftvideo.c +++ b/libavcodec/bethsoftvideo.c @@ -75,9 +75,9 @@ static int bethsoftvid_decode_frame(AVCodecContext *avctx, int code, ret; int yoffset; - if (avctx->reget_buffer(avctx, &vid->frame)) { + if ((ret = avctx->reget_buffer(avctx, &vid->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } wrap_to_next_line = vid->frame.linesize[0] - avctx->width; @@ -105,7 +105,7 @@ static int bethsoftvid_decode_frame(AVCodecContext *avctx, case VIDEO_YOFF_P_FRAME: yoffset = bytestream2_get_le16(&vid->g); if(yoffset >= avctx->height) - return -1; + return AVERROR_INVALIDDATA; dst += vid->frame.linesize[0] * yoffset; } From 86e09b9e605e89855aa44724439b6e5b7fd93e4c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 16:09:39 +0100 Subject: [PATCH 02/12] bfi: return meaningful error codes. --- libavcodec/bfi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/bfi.c b/libavcodec/bfi.c index 50b20bacf9..1971c0c855 100644 --- a/libavcodec/bfi.c +++ b/libavcodec/bfi.c @@ -55,16 +55,16 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, uint8_t *src, *dst_offset, colour1, colour2; uint8_t *frame_end = bfi->dst + avctx->width * avctx->height; uint32_t *pal; - int i, j, height = avctx->height; + int i, j, ret, height = avctx->height; if (bfi->frame.data[0]) avctx->release_buffer(avctx, &bfi->frame); bfi->frame.reference = 1; - if (ff_get_buffer(avctx, &bfi->frame) < 0) { + if ((ret = ff_get_buffer(avctx, &bfi->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } bytestream2_init(&g, avpkt->data, buf_size); @@ -76,7 +76,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, /* Setting the palette */ if (avctx->extradata_size > 768) { av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); - return -1; + return AVERROR_INVALIDDATA; } pal = (uint32_t *)bfi->frame.data[1]; for (i = 0; i < avctx->extradata_size / 3; i++) { @@ -104,7 +104,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, if (!bytestream2_get_bytes_left(&g)) { av_log(avctx, AV_LOG_ERROR, "Input resolution larger than actual frame.\n"); - return -1; + return AVERROR_INVALIDDATA; } /* Get length and offset (if required) */ @@ -130,7 +130,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, case 0: // normal chain if (length >= bytestream2_get_bytes_left(&g)) { av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n"); - return -1; + return AVERROR_INVALIDDATA; } bytestream2_get_buffer(&g, dst, length); dst += length; From 86d4e754226a54ea87933f34f6a3c9d97bab147f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 21:47:37 +0100 Subject: [PATCH 03/12] bink: return meaningful error codes. --- libavcodec/bink.c | 109 ++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/libavcodec/bink.c b/libavcodec/bink.c index 059601debf..25b4f1402e 100644 --- a/libavcodec/bink.c +++ b/libavcodec/bink.c @@ -313,7 +313,7 @@ static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -335,7 +335,7 @@ static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle * dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many motion values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -370,7 +370,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many block type values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_bits(gb, 4); @@ -386,7 +386,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) int run = bink_rlelens[v - 12]; if (dec_end - b->cur_dec < run) - return -1; + return AVERROR_INVALIDDATA; memset(b->cur_dec, last, run); b->cur_dec += run; } @@ -404,7 +404,7 @@ static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n"); - return -1; + return AVERROR_INVALIDDATA; } while (b->cur_dec < dec_end) { v = GET_HUFF(gb, b->tree); @@ -424,7 +424,7 @@ static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c) dec_end = b->cur_dec + t; if (dec_end > b->data_end) { av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); @@ -470,13 +470,13 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, v = (v ^ sign) - sign; } if (dst_end - dst < 1) - return -1; + return AVERROR_INVALIDDATA; *dst++ = v; len--; for (i = 0; i < len; i += 8) { len2 = FFMIN(len - i, 8); if (dst_end - dst < len2) - return -1; + return AVERROR_INVALIDDATA; bsize = get_bits(gb, 4); if (bsize) { for (j = 0; j < len2; j++) { @@ -489,7 +489,7 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, *dst++ = v; if (v < -32768 || v > 32767) { av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v); - return -1; + return AVERROR_INVALIDDATA; } } } else { @@ -545,7 +545,7 @@ static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num) CHECK_READ_VAL(gb, b, len); if (b->data_end - b->cur_dec < len * (1 + (bits > 8))) - return -1; + return AVERROR_INVALIDDATA; if (bits <= 8) { if (!issigned) { for (i = 0; i < len; i++) @@ -794,7 +794,7 @@ static inline void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stri static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_key, int is_chroma) { - int blk; + int blk, ret; int i, j, bx, by; uint8_t *dst, *ref, *ref_start, *ref_end; int v, col[2]; @@ -819,8 +819,8 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, for (by = 0; by < bh; by++) { for (i = 0; i < BINKB_NB_SRC; i++) { - if (binkb_read_bundle(c, gb, i) < 0) - return -1; + if ((ret = binkb_read_bundle(c, gb, i)) < 0) + return ret; } dst = c->pic.data[plane_idx] + 8*by*stride; @@ -841,7 +841,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (mode) { v = binkb_get_value(c, BINKB_SRC_COLORS); @@ -927,7 +927,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -940,7 +940,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_chroma) { - int blk; + int blk, ret; int i, j, bx, by; uint8_t *dst, *prev, *ref, *ref_start, *ref_end; int v, col[2]; @@ -969,24 +969,24 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, coordmap[i] = (i & 7) + (i >> 3) * stride; for (by = 0; by < bh; by++) { - if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES]) < 0) - return -1; - if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES]) < 0) - return -1; - if (read_colors(gb, &c->bundle[BINK_SRC_COLORS], c) < 0) - return -1; - if (read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN]) < 0) - return -1; - if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF]) < 0) - return -1; - if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF]) < 0) - return -1; - if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0) < 0) - return -1; - if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1) < 0) - return -1; - if (read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN]) < 0) - return -1; + if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0) + return ret; + if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0) + return ret; + if ((ret = read_colors(gb, &c->bundle[BINK_SRC_COLORS], c)) < 0) + return ret; + if ((ret = read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN])) < 0) + return ret; + if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF])) < 0) + return ret; + if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF])) < 0) + return ret; + if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0) + return ret; + if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0) + return ret; + if ((ret = read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN])) < 0) + return ret; if (by == bh) break; @@ -1018,7 +1018,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_value(c, BINK_SRC_COLORS); @@ -1058,7 +1058,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } if (blk != FILL_BLOCK) c->bdsp.scale_block(ublock, dst, stride); @@ -1073,7 +1073,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, if (ref < ref_start || ref > ref_end) { av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", bx*8 + xoff, by*8 + yoff); - return -1; + return AVERROR_INVALIDDATA; } c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); break; @@ -1086,7 +1086,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, i += run; if (i > 64) { av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); - return -1; + return AVERROR_INVALIDDATA; } if (get_bits1(gb)) { v = get_value(c, BINK_SRC_COLORS); @@ -1107,7 +1107,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, if (ref < ref_start || ref > ref_end) { av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", bx*8 + xoff, by*8 + yoff); - return -1; + return AVERROR_INVALIDDATA; } c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); c->dsp.clear_block(block); @@ -1151,7 +1151,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, break; default: av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -1165,21 +1165,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac { BinkContext * const c = avctx->priv_data; GetBitContext gb; - int plane, plane_idx; + int plane, plane_idx, ret; int bits_count = pkt->size << 3; if (c->version > 'b') { if(c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - if(ff_get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } } else { - if(avctx->reget_buffer(avctx, &c->pic) < 0){ + if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } } @@ -1187,8 +1187,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac if (c->has_alpha) { if (c->version >= 'i') skip_bits_long(&gb, 32); - if (bink_decode_plane(c, &gb, 3, 0) < 0) - return -1; + if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0) + return ret; } if (c->version >= 'i') skip_bits_long(&gb, 32); @@ -1197,11 +1197,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); if (c->version > 'b') { - if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) - return -1; + if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0) + return ret; } else { - if (binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane) < 0) - return -1; + if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0) + return ret; } if (get_bits_count(&gb) >= bits_count) break; @@ -1268,13 +1268,13 @@ static av_cold int decode_init(AVCodecContext *avctx) BinkContext * const c = avctx->priv_data; static VLC_TYPE table[16 * 128][2]; static int binkb_initialised = 0; - int i; + int i, ret; int flags; c->version = avctx->codec_tag >> 24; if (avctx->extradata_size < 4) { av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); - return -1; + return AVERROR_INVALIDDATA; } flags = AV_RL32(avctx->extradata); c->has_alpha = flags & BINK_FLAG_ALPHA; @@ -1297,6 +1297,9 @@ static av_cold int decode_init(AVCodecContext *avctx) return 1; } + if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) + return ret; + avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; avctx->idct_algo = FF_IDCT_BINK; From 6a97ea65b647f8b0acfb869321c7a45e39eb65a4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 08:23:11 +0100 Subject: [PATCH 04/12] bink: operate with pointers to AVFrames instead of whole structs. This is more correct and avoids breaking extended_data. --- libavcodec/bink.c | 56 +++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/libavcodec/bink.c b/libavcodec/bink.c index 25b4f1402e..0967ad9895 100644 --- a/libavcodec/bink.c +++ b/libavcodec/bink.c @@ -112,7 +112,7 @@ typedef struct BinkContext { AVCodecContext *avctx; DSPContext dsp; BinkDSPContext bdsp; - AVFrame pic, last; + AVFrame *pic, *last; int version; ///< internal Bink file version int has_alpha; int swap_planes; @@ -806,13 +806,13 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int ybias = is_key ? -15 : 0; int qp; - const int stride = c->pic.linesize[plane_idx]; + const int stride = c->pic->linesize[plane_idx]; int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; binkb_init_bundles(c); - ref_start = c->pic.data[plane_idx]; - ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; + ref_start = c->pic->data[plane_idx]; + ref_end = c->pic->data[plane_idx] + (bh * c->pic->linesize[plane_idx] + bw) * 8; for (i = 0; i < 64; i++) coordmap[i] = (i & 7) + (i >> 3) * stride; @@ -823,7 +823,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, return ret; } - dst = c->pic.data[plane_idx] + 8*by*stride; + dst = c->pic->data[plane_idx] + 8*by*stride; for (bx = 0; bx < bw; bx++, dst += 8) { blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); switch (blk) { @@ -951,7 +951,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, LOCAL_ALIGNED_16(int32_t, dctblock, [64]); int coordmap[64]; - const int stride = c->pic.linesize[plane_idx]; + const int stride = c->pic->linesize[plane_idx]; int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; int width = c->avctx->width >> is_chroma; @@ -960,10 +960,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, for (i = 0; i < BINK_NB_SRC; i++) read_bundle(gb, c, i); - ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] - : c->pic.data[plane_idx]; + ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx] + : c->pic->data[plane_idx]; ref_end = ref_start - + (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8; + + (bw - 1 + c->last->linesize[plane_idx] * (bh - 1)) * 8; for (i = 0; i < 64; i++) coordmap[i] = (i & 7) + (i >> 3) * stride; @@ -990,9 +990,9 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, if (by == bh) break; - dst = c->pic.data[plane_idx] + 8*by*stride; - prev = (c->last.data[plane_idx] ? c->last.data[plane_idx] - : c->pic.data[plane_idx]) + 8*by*stride; + dst = c->pic->data[plane_idx] + 8*by*stride; + prev = (c->last->data[plane_idx] ? c->last->data[plane_idx] + : c->pic->data[plane_idx]) + 8*by*stride; for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { blk = get_value(c, BINK_SRC_BLOCK_TYPES); // 16x16 block type on odd line means part of the already decoded block, so skip it @@ -1169,15 +1169,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac int bits_count = pkt->size << 3; if (c->version > 'b') { - if(c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); + if(c->pic->data[0]) + avctx->release_buffer(avctx, c->pic); - if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { + if ((ret = ff_get_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } } else { - if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) { + if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } @@ -1209,10 +1209,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac emms_c(); *got_frame = 1; - *(AVFrame*)data = c->pic; + *(AVFrame*)data = *c->pic; if (c->version > 'b') - FFSWAP(AVFrame, c->pic, c->last); + FFSWAP(AVFrame*, c->pic, c->last); /* always report that the buffer was completely consumed */ return pkt->size; @@ -1291,10 +1291,12 @@ static av_cold int decode_init(AVCodecContext *avctx) } c->avctx = avctx; - c->pic.data[0] = NULL; - - if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { - return 1; + c->pic = avcodec_alloc_frame(); + c->last = avcodec_alloc_frame(); + if (!c->pic || !c->last) { + avcodec_free_frame(&c->pic); + avcodec_free_frame(&c->last); + return AVERROR(ENOMEM); } if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) @@ -1322,10 +1324,12 @@ static av_cold int decode_end(AVCodecContext *avctx) { BinkContext * const c = avctx->priv_data; - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - if (c->last.data[0]) - avctx->release_buffer(avctx, &c->last); + if (c->pic->data[0]) + avctx->release_buffer(avctx, c->pic); + if (c->last->data[0]) + avctx->release_buffer(avctx, c->last); + avcodec_free_frame(&c->pic); + avcodec_free_frame(&c->last); free_bundles(c); return 0; From abcc235481db3a351d1fc3d02a97312d2d19c540 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Nov 2012 09:26:36 +0100 Subject: [PATCH 05/12] bmp: return meaningful error codes. --- libavcodec/bmp.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c index 9c8988c83a..5ca73baa4f 100644 --- a/libavcodec/bmp.c +++ b/libavcodec/bmp.c @@ -49,7 +49,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, unsigned int depth; BiCompression comp; unsigned int ihsize; - int i, j, n, linesize; + int i, j, n, linesize, ret; uint32_t rgb[3]; uint8_t *ptr; int dsize; @@ -58,13 +58,13 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (buf_size < 14) { av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size); - return -1; + return AVERROR_INVALIDDATA; } if (bytestream_get_byte(&buf) != 'B' || bytestream_get_byte(&buf) != 'M') { av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); - return -1; + return AVERROR_INVALIDDATA; } fsize = bytestream_get_le32(&buf); @@ -81,7 +81,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, ihsize = bytestream_get_le32(&buf); /* more header size */ if (ihsize + 14 > hsize) { av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize); - return -1; + return AVERROR_INVALIDDATA; } /* sometimes file size is set to some headers size, set a real size in that case */ @@ -91,7 +91,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (fsize <= hsize) { av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n", fsize, hsize); - return -1; + return AVERROR_INVALIDDATA; } switch (ihsize) { @@ -108,13 +108,13 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n"); - return -1; + return AVERROR_PATCHWELCOME; } /* planes */ if (bytestream_get_le16(&buf) != 1) { av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n"); - return -1; + return AVERROR_INVALIDDATA; } depth = bytestream_get_le16(&buf); @@ -127,7 +127,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (comp != BMP_RGB && comp != BMP_BITFIELDS && comp != BMP_RLE4 && comp != BMP_RLE8) { av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp); - return -1; + return AVERROR_INVALIDDATA; } if (comp == BMP_BITFIELDS) { @@ -192,26 +192,26 @@ static int bmp_decode_frame(AVCodecContext *avctx, avctx->pix_fmt = AV_PIX_FMT_PAL8; } else { av_log(avctx, AV_LOG_ERROR, "Unknown palette for %d-colour BMP\n", 1<pix_fmt == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); - return -1; + return AVERROR_INVALIDDATA; } if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -225,7 +225,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, if (n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8) { av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", dsize, n * avctx->height); - return -1; + return AVERROR_INVALIDDATA; } // RLE may skip decoding some picture areas, so blank picture before decoding @@ -346,7 +346,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n"); - return -1; + return AVERROR_INVALIDDATA; } } From 2b011a43e9e56065052418c3b151226fb8bc8de9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Nov 2012 10:10:13 +0100 Subject: [PATCH 06/12] bmv: return meaningful error codes. --- libavcodec/bmv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/bmv.c b/libavcodec/bmv.c index a7f21eceb2..a082d3ced7 100644 --- a/libavcodec/bmv.c +++ b/libavcodec/bmv.c @@ -67,7 +67,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, int i; if (src_len <= 0) - return -1; + return AVERROR_INVALIDDATA; if (forward) { src = source; @@ -91,7 +91,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, */ if (!mode || (tmplen == 4)) { if (src < source || src >= source_end) - return -1; + return AVERROR_INVALIDDATA; val = *src; read_two_nibbles = 1; } else { @@ -102,7 +102,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, for (;;) { if (!read_two_nibbles) { if (src < source || src >= source_end) - return -1; + return AVERROR_INVALIDDATA; shift += 2; val |= *src << shift; if (*src & 0xC) @@ -137,7 +137,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, if (mode >= 4) mode -= 3; if (FFABS(dst_end - dst) < len) - return -1; + return AVERROR_INVALIDDATA; switch (mode) { case 1: if (forward) { @@ -145,7 +145,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, dst - frame + SCREEN_WIDE + frame_off < 0 || frame_end - dst < frame_off + len || frame_end - dst < len) - return -1; + return AVERROR_INVALIDDATA; for (i = 0; i < len; i++) dst[i] = dst[frame_off + i]; dst += len; @@ -155,7 +155,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, dst - frame + SCREEN_WIDE + frame_off < 0 || frame_end - dst < frame_off + len || frame_end - dst < len) - return -1; + return AVERROR_INVALIDDATA; for (i = len - 1; i >= 0; i--) dst[i] = dst[frame_off + i]; } @@ -163,13 +163,13 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, case 2: if (forward) { if (source + src_len - src < len) - return -1; + return AVERROR_INVALIDDATA; memcpy(dst, src, len); dst += len; src += len; } else { if (src - source < len) - return -1; + return AVERROR_INVALIDDATA; dst -= len; src -= len; memcpy(dst, src, len); From 11c3f2047e94719765dae8b19a8023689056e767 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Nov 2012 10:29:28 +0100 Subject: [PATCH 07/12] c93: return meaningful error codes. --- libavcodec/c93.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/c93.c b/libavcodec/c93.c index b820f5a9da..b7205855bb 100644 --- a/libavcodec/c93.c +++ b/libavcodec/c93.c @@ -79,7 +79,7 @@ static inline int copy_block(AVCodecContext *avctx, uint8_t *to, if (from_y + height > HEIGHT) { av_log(avctx, AV_LOG_ERROR, "invalid offset %d during C93 decoding\n", offset); - return -1; + return AVERROR_INVALIDDATA; } if (overflow > 0) { @@ -123,16 +123,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, AVFrame *picture = data; GetByteContext gb; uint8_t *out; - int stride, i, x, y, b, bt = 0; + int stride, ret, i, x, y, b, bt = 0; c93->currentpic ^= 1; newpic->reference = 1; newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; - if (avctx->reget_buffer(avctx, newpic)) { + if ((ret = avctx->reget_buffer(avctx, newpic)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } stride = newpic->linesize[0]; @@ -162,8 +162,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, switch (block_type) { case C93_8X8_FROM_PREV: offset = bytestream2_get_le16(&gb); - if (copy_block(avctx, out, copy_from, offset, 8, stride)) - return -1; + if ((ret = copy_block(avctx, out, copy_from, offset, 8, stride)) < 0) + return ret; break; case C93_4X4_FROM_CURR: @@ -172,9 +172,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, for (j = 0; j < 8; j += 4) { for (i = 0; i < 8; i += 4) { offset = bytestream2_get_le16(&gb); - if (copy_block(avctx, &out[j*stride+i], - copy_from, offset, 4, stride)) - return -1; + if ((ret = copy_block(avctx, &out[j*stride+i], + copy_from, offset, 4, stride)) < 0) + return ret; } } break; @@ -221,7 +221,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, default: av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n", block_type, x, y); - return -1; + return AVERROR_INVALIDDATA; } bt >>= 4; out += 8; From 01b60883ea3af2794c4279bfe7f01c31e7f55a61 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Nov 2012 20:49:17 +0100 Subject: [PATCH 08/12] yop: use a meaningful error code. --- libavcodec/yop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/yop.c b/libavcodec/yop.c index 0b9cdfebe2..69700bd266 100644 --- a/libavcodec/yop.c +++ b/libavcodec/yop.c @@ -86,7 +86,7 @@ static av_cold int yop_decode_init(AVCodecContext *avctx) if (avctx->width & 1 || avctx->height & 1 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n"); - return -1; + return AVERROR_INVALIDDATA; } avctx->pix_fmt = AV_PIX_FMT_PAL8; From aaf208329f6ed21f51d7bcfa6b50ea41e0825c4e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Nov 2012 18:18:12 +0100 Subject: [PATCH 09/12] zmbv: return more meaningful error codes. --- libavcodec/zmbv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 0733fa70d4..8e0db8b531 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -485,7 +485,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } tmp = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8)); @@ -639,7 +639,7 @@ static av_cold int decode_init(AVCodecContext *avctx) zret = inflateInit(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } return 0; From 4aebb8d999f0a5005081c50211be3d3c7474d330 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 16 Nov 2012 06:31:39 +0100 Subject: [PATCH 10/12] xxan: return meaningful error codes. --- libavcodec/xxan.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c index 9e874540b5..c28ba2f964 100644 --- a/libavcodec/xxan.c +++ b/libavcodec/xxan.c @@ -133,7 +133,7 @@ static int xan_unpack(XanContext *s, } if (dest + size + size2 > dest_end || dest - orig_dest + size < back) - return -1; + return AVERROR_INVALIDDATA; bytestream2_get_buffer(&s->gb, dest, size); dest += size; av_memcpy_backptr(dest, back, size2); @@ -143,7 +143,7 @@ static int xan_unpack(XanContext *s, size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4; if (dest_end - dest < size) - return -1; + return AVERROR_INVALIDDATA; bytestream2_get_buffer(&s->gb, dest, size); dest += size; if (finish) @@ -167,7 +167,7 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off) return 0; if (chroma_off + 4 >= bytestream2_get_bytes_left(&s->gb)) { av_log(avctx, AV_LOG_ERROR, "Invalid chroma block position\n"); - return -1; + return AVERROR_INVALIDDATA; } bytestream2_seek(&s->gb, chroma_off + 4, SEEK_SET); mode = bytestream2_get_le16(&s->gb); @@ -178,7 +178,7 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off) if (offset >= bytestream2_get_bytes_left(&s->gb)) { av_log(avctx, AV_LOG_ERROR, "Invalid chroma block offset\n"); - return -1; + return AVERROR_INVALIDDATA; } bytestream2_skip(&s->gb, offset); @@ -186,7 +186,7 @@ static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off) dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size); if (dec_size < 0) { av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n"); - return -1; + return dec_size; } U = s->pic.data[1]; @@ -384,7 +384,7 @@ static int xan_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "Unknown frame type %d\n", ftype); - return -1; + return AVERROR_INVALIDDATA; } if (ret) return ret; From d47dabbac24e1a00ce15079a5d3dc9d5be79e6b2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 16 Nov 2012 06:36:15 +0100 Subject: [PATCH 11/12] xan: return a meaningful error code. --- libavcodec/xan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/xan.c b/libavcodec/xan.c index 8c90bb6ab0..14a2d23f49 100644 --- a/libavcodec/xan.c +++ b/libavcodec/xan.c @@ -114,7 +114,7 @@ static int xan_huffman_decode(unsigned char *dest, int dest_len, while (val != 0x16) { unsigned idx = val - 0x17 + get_bits1(&gb) * byte; if (idx >= 2 * byte) - return -1; + return AVERROR_INVALIDDATA; val = src[idx]; if (val < 0x16) { From 84f2847de394ac447f53306bd4dd73e1af6ea5e4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 16 Nov 2012 11:32:09 +0100 Subject: [PATCH 12/12] xl: return a meaningful error code. --- libavcodec/xl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/xl.c b/libavcodec/xl.c index 1cadeab561..ab45a5e35a 100644 --- a/libavcodec/xl.c +++ b/libavcodec/xl.c @@ -49,7 +49,7 @@ static int decode_frame(AVCodecContext *avctx, VideoXLContext * const a = avctx->priv_data; AVFrame * const p = &a->pic; uint8_t *Y, *U, *V; - int i, j; + int i, j, ret; int stride; uint32_t val; int y0, y1, y2, y3 = 0, c0 = 0, c1 = 0; @@ -58,9 +58,9 @@ static int decode_frame(AVCodecContext *avctx, avctx->release_buffer(avctx, p); p->reference = 0; - if(ff_get_buffer(avctx, p) < 0){ + if ((ret = ff_get_buffer(avctx, p)) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type= AV_PICTURE_TYPE_I; p->key_frame= 1;