1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '84f2847de394ac447f53306bd4dd73e1af6ea5e4'

* commit '84f2847de394ac447f53306bd4dd73e1af6ea5e4':
  xl: return a meaningful error code.
  xan: return a meaningful error code.
  xxan: return meaningful error codes.
  zmbv: return more meaningful error codes.
  yop: use a meaningful error code.
  c93: return meaningful error codes.
  bmv: return meaningful error codes.
  bmp: return meaningful error codes.
  bink: operate with pointers to AVFrames instead of whole structs.
  bink: return meaningful error codes.
  bfi: return meaningful error codes.
  bethsoftvideo: return meaningful error codes.

Conflicts:
	libavcodec/c93.c
	libavcodec/xl.c
	libavcodec/xxan.c
	libavcodec/yop.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-01-06 23:59:35 +01:00
commit 7b018e5c8d
10 changed files with 126 additions and 118 deletions

View File

@ -57,16 +57,16 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *src, *dst_offset, colour1, colour2; uint8_t *src, *dst_offset, colour1, colour2;
uint8_t *frame_end = bfi->dst + avctx->width * avctx->height; uint8_t *frame_end = bfi->dst + avctx->width * avctx->height;
uint32_t *pal; uint32_t *pal;
int i, j, height = avctx->height; int i, j, ret, height = avctx->height;
if (bfi->frame.data[0]) if (bfi->frame.data[0])
avctx->release_buffer(avctx, &bfi->frame); avctx->release_buffer(avctx, &bfi->frame);
bfi->frame.reference = 3; bfi->frame.reference = 3;
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"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return ret;
} }
bytestream2_init(&g, avpkt->data, buf_size); bytestream2_init(&g, avpkt->data, buf_size);
@ -78,7 +78,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
/* Setting the palette */ /* Setting the palette */
if (avctx->extradata_size > 768) { if (avctx->extradata_size > 768) {
av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n");
return -1; return AVERROR_INVALIDDATA;
} }
pal = (uint32_t *)bfi->frame.data[1]; pal = (uint32_t *)bfi->frame.data[1];
for (i = 0; i < avctx->extradata_size / 3; i++) { for (i = 0; i < avctx->extradata_size / 3; i++) {
@ -109,7 +109,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
if (!bytestream2_get_bytes_left(&g)) { if (!bytestream2_get_bytes_left(&g)) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Input resolution larger than actual frame.\n"); "Input resolution larger than actual frame.\n");
return -1; return AVERROR_INVALIDDATA;
} }
/* Get length and offset (if required) */ /* Get length and offset (if required) */
@ -135,7 +135,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
case 0: // normal chain case 0: // normal chain
if (length >= bytestream2_get_bytes_left(&g)) { if (length >= bytestream2_get_bytes_left(&g)) {
av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n"); av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n");
return -1; return AVERROR_INVALIDDATA;
} }
bytestream2_get_buffer(&g, dst, length); bytestream2_get_buffer(&g, dst, length);
dst += length; dst += length;

View File

@ -112,7 +112,7 @@ typedef struct BinkContext {
AVCodecContext *avctx; AVCodecContext *avctx;
DSPContext dsp; DSPContext dsp;
BinkDSPContext bdsp; BinkDSPContext bdsp;
AVFrame pic, last; AVFrame *pic, *last;
int version; ///< internal Bink file version int version; ///< internal Bink file version
int has_alpha; int has_alpha;
int swap_planes; int swap_planes;
@ -313,7 +313,7 @@ static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
dec_end = b->cur_dec + t; dec_end = b->cur_dec + t;
if (dec_end > b->data_end) { if (dec_end > b->data_end) {
av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n"); av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
v = get_bits(gb, 4); 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; dec_end = b->cur_dec + t;
if (dec_end > b->data_end) { if (dec_end > b->data_end) {
av_log(avctx, AV_LOG_ERROR, "Too many motion values\n"); av_log(avctx, AV_LOG_ERROR, "Too many motion values\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
v = get_bits(gb, 4); 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; dec_end = b->cur_dec + t;
if (dec_end > b->data_end) { if (dec_end > b->data_end) {
av_log(avctx, AV_LOG_ERROR, "Too many block type values\n"); av_log(avctx, AV_LOG_ERROR, "Too many block type values\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
v = get_bits(gb, 4); 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]; int run = bink_rlelens[v - 12];
if (dec_end - b->cur_dec < run) if (dec_end - b->cur_dec < run)
return -1; return AVERROR_INVALIDDATA;
memset(b->cur_dec, last, run); memset(b->cur_dec, last, run);
b->cur_dec += 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; dec_end = b->cur_dec + t;
if (dec_end > b->data_end) { if (dec_end > b->data_end) {
av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n"); av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n");
return -1; return AVERROR_INVALIDDATA;
} }
while (b->cur_dec < dec_end) { while (b->cur_dec < dec_end) {
v = GET_HUFF(gb, b->tree); 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; dec_end = b->cur_dec + t;
if (dec_end > b->data_end) { if (dec_end > b->data_end) {
av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n"); av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); 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; v = (v ^ sign) - sign;
} }
if (dst_end - dst < 1) if (dst_end - dst < 1)
return -1; return AVERROR_INVALIDDATA;
*dst++ = v; *dst++ = v;
len--; len--;
for (i = 0; i < len; i += 8) { for (i = 0; i < len; i += 8) {
len2 = FFMIN(len - i, 8); len2 = FFMIN(len - i, 8);
if (dst_end - dst < len2) if (dst_end - dst < len2)
return -1; return AVERROR_INVALIDDATA;
bsize = get_bits(gb, 4); bsize = get_bits(gb, 4);
if (bsize) { if (bsize) {
for (j = 0; j < len2; j++) { for (j = 0; j < len2; j++) {
@ -489,7 +489,7 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b,
*dst++ = v; *dst++ = v;
if (v < -32768 || v > 32767) { if (v < -32768 || v > 32767) {
av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v); av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v);
return -1; return AVERROR_INVALIDDATA;
} }
} }
} else { } else {
@ -545,7 +545,7 @@ static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num)
CHECK_READ_VAL(gb, b, len); CHECK_READ_VAL(gb, b, len);
if (b->data_end - b->cur_dec < len * (1 + (bits > 8))) if (b->data_end - b->cur_dec < len * (1 + (bits > 8)))
return -1; return AVERROR_INVALIDDATA;
if (bits <= 8) { if (bits <= 8) {
if (!issigned) { if (!issigned) {
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
@ -798,7 +798,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, static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
int is_key, int is_chroma) int is_key, int is_chroma)
{ {
int blk; int blk, ret;
int i, j, bx, by; int i, j, bx, by;
uint8_t *dst, *ref, *ref_start, *ref_end; uint8_t *dst, *ref, *ref_start, *ref_end;
int v, col[2]; int v, col[2];
@ -810,24 +810,24 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
int ybias = is_key ? -15 : 0; int ybias = is_key ? -15 : 0;
int qp; 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 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 bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
binkb_init_bundles(c); binkb_init_bundles(c);
ref_start = c->pic.data[plane_idx]; ref_start = c->pic->data[plane_idx];
ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; ref_end = c->pic->data[plane_idx] + (bh * c->pic->linesize[plane_idx] + bw) * 8;
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
coordmap[i] = (i & 7) + (i >> 3) * stride; coordmap[i] = (i & 7) + (i >> 3) * stride;
for (by = 0; by < bh; by++) { for (by = 0; by < bh; by++) {
for (i = 0; i < BINKB_NB_SRC; i++) { for (i = 0; i < BINKB_NB_SRC; i++) {
if (binkb_read_bundle(c, gb, i) < 0) if ((ret = binkb_read_bundle(c, gb, i)) < 0)
return -1; 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) { for (bx = 0; bx < bw; bx++, dst += 8) {
blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES);
switch (blk) { switch (blk) {
@ -845,7 +845,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
i += run; i += run;
if (i > 64) { if (i > 64) {
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (mode) { if (mode) {
v = binkb_get_value(c, BINKB_SRC_COLORS); v = binkb_get_value(c, BINKB_SRC_COLORS);
@ -931,7 +931,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
break; break;
default: default:
av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk);
return -1; return AVERROR_INVALIDDATA;
} }
} }
} }
@ -944,7 +944,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, static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
int is_chroma) int is_chroma)
{ {
int blk; int blk, ret;
int i, j, bx, by; int i, j, bx, by;
uint8_t *dst, *prev, *ref, *ref_start, *ref_end; uint8_t *dst, *prev, *ref, *ref_start, *ref_end;
int v, col[2]; int v, col[2];
@ -955,7 +955,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
LOCAL_ALIGNED_16(int32_t, dctblock, [64]); LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
int coordmap[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 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 bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
int width = c->avctx->width >> is_chroma; int width = c->avctx->width >> is_chroma;
@ -964,39 +964,39 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
for (i = 0; i < BINK_NB_SRC; i++) for (i = 0; i < BINK_NB_SRC; i++)
read_bundle(gb, c, i); read_bundle(gb, c, i);
ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx]
: c->pic.data[plane_idx]; : c->pic->data[plane_idx];
ref_end = ref_start 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++) for (i = 0; i < 64; i++)
coordmap[i] = (i & 7) + (i >> 3) * stride; coordmap[i] = (i & 7) + (i >> 3) * stride;
for (by = 0; by < bh; by++) { for (by = 0; by < bh; by++) {
if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES]) < 0) if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0)
return -1; return ret;
if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES]) < 0) if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0)
return -1; return ret;
if (read_colors(gb, &c->bundle[BINK_SRC_COLORS], c) < 0) if ((ret = read_colors(gb, &c->bundle[BINK_SRC_COLORS], c)) < 0)
return -1; return ret;
if (read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN]) < 0) if ((ret = read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN])) < 0)
return -1; return ret;
if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF]) < 0) if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF])) < 0)
return -1; return ret;
if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF]) < 0) if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF])) < 0)
return -1; return ret;
if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0) < 0) if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0)
return -1; return ret;
if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1) < 0) if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0)
return -1; return ret;
if (read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN]) < 0) if ((ret = read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN])) < 0)
return -1; return ret;
if (by == bh) if (by == bh)
break; break;
dst = 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] prev = (c->last->data[plane_idx] ? c->last->data[plane_idx]
: c->pic.data[plane_idx]) + 8*by*stride; : c->pic->data[plane_idx]) + 8*by*stride;
for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
blk = get_value(c, BINK_SRC_BLOCK_TYPES); blk = get_value(c, BINK_SRC_BLOCK_TYPES);
// 16x16 block type on odd line means part of the already decoded block, so skip it // 16x16 block type on odd line means part of the already decoded block, so skip it
@ -1022,7 +1022,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
i += run; i += run;
if (i > 64) { if (i > 64) {
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
v = get_value(c, BINK_SRC_COLORS); v = get_value(c, BINK_SRC_COLORS);
@ -1062,7 +1062,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
break; break;
default: default:
av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk); av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk);
return -1; return AVERROR_INVALIDDATA;
} }
if (blk != FILL_BLOCK) if (blk != FILL_BLOCK)
c->bdsp.scale_block(ublock, dst, stride); c->bdsp.scale_block(ublock, dst, stride);
@ -1077,7 +1077,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
if (ref < ref_start || ref > ref_end) { if (ref < ref_start || ref > ref_end) {
av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
bx*8 + xoff, by*8 + yoff); bx*8 + xoff, by*8 + yoff);
return -1; return AVERROR_INVALIDDATA;
} }
c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8);
break; break;
@ -1090,7 +1090,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
i += run; i += run;
if (i > 64) { if (i > 64) {
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (get_bits1(gb)) { if (get_bits1(gb)) {
v = get_value(c, BINK_SRC_COLORS); v = get_value(c, BINK_SRC_COLORS);
@ -1111,7 +1111,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
if (ref < ref_start || ref > ref_end) { if (ref < ref_start || ref > ref_end) {
av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
bx*8 + xoff, by*8 + yoff); bx*8 + xoff, by*8 + yoff);
return -1; return AVERROR_INVALIDDATA;
} }
c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8);
c->dsp.clear_block(block); c->dsp.clear_block(block);
@ -1160,7 +1160,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
break; break;
default: default:
av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk);
return -1; return AVERROR_INVALIDDATA;
} }
} }
} }
@ -1174,21 +1174,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
{ {
BinkContext * const c = avctx->priv_data; BinkContext * const c = avctx->priv_data;
GetBitContext gb; GetBitContext gb;
int plane, plane_idx; int plane, plane_idx, ret;
int bits_count = pkt->size << 3; int bits_count = pkt->size << 3;
if (c->version > 'b') { if (c->version > 'b') {
if(c->pic.data[0]) if(c->pic->data[0])
avctx->release_buffer(avctx, &c->pic); 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"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return ret;
} }
} else { } 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"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1; return ret;
} }
} }
@ -1196,8 +1196,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
if (c->has_alpha) { if (c->has_alpha) {
if (c->version >= 'i') if (c->version >= 'i')
skip_bits_long(&gb, 32); skip_bits_long(&gb, 32);
if (bink_decode_plane(c, &gb, 3, 0) < 0) if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0)
return -1; return ret;
} }
if (c->version >= 'i') if (c->version >= 'i')
skip_bits_long(&gb, 32); skip_bits_long(&gb, 32);
@ -1206,11 +1206,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3);
if (c->version > 'b') { if (c->version > 'b') {
if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0)
return -1; return ret;
} else { } else {
if (binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane) < 0) if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0)
return -1; return ret;
} }
if (get_bits_count(&gb) >= bits_count) if (get_bits_count(&gb) >= bits_count)
break; break;
@ -1218,10 +1218,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
emms_c(); emms_c();
*got_frame = 1; *got_frame = 1;
*(AVFrame*)data = c->pic; *(AVFrame*)data = *c->pic;
if (c->version > 'b') if (c->version > 'b')
FFSWAP(AVFrame, c->pic, c->last); FFSWAP(AVFrame*, c->pic, c->last);
/* always report that the buffer was completely consumed */ /* always report that the buffer was completely consumed */
return pkt->size; return pkt->size;
@ -1264,13 +1264,13 @@ static av_cold int decode_init(AVCodecContext *avctx)
BinkContext * const c = avctx->priv_data; BinkContext * const c = avctx->priv_data;
static VLC_TYPE table[16 * 128][2]; static VLC_TYPE table[16 * 128][2];
static int binkb_initialised = 0; static int binkb_initialised = 0;
int i; int i, ret;
int flags; int flags;
c->version = avctx->codec_tag >> 24; c->version = avctx->codec_tag >> 24;
if (avctx->extradata_size < 4) { if (avctx->extradata_size < 4) {
av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n");
return -1; return AVERROR_INVALIDDATA;
} }
flags = AV_RL32(avctx->extradata); flags = AV_RL32(avctx->extradata);
c->has_alpha = flags & BINK_FLAG_ALPHA; c->has_alpha = flags & BINK_FLAG_ALPHA;
@ -1287,12 +1287,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
} }
c->avctx = avctx; c->avctx = avctx;
c->pic.data[0] = NULL; c->pic = avcodec_alloc_frame();
c->last = avcodec_alloc_frame();
if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { if (!c->pic || !c->last) {
return 1; 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)
return ret;
avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P;
avctx->idct_algo = FF_IDCT_BINK; avctx->idct_algo = FF_IDCT_BINK;
@ -1315,10 +1320,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
{ {
BinkContext * const c = avctx->priv_data; BinkContext * const c = avctx->priv_data;
if (c->pic.data[0]) if (c->pic->data[0])
avctx->release_buffer(avctx, &c->pic); avctx->release_buffer(avctx, c->pic);
if (c->last.data[0]) if (c->last->data[0])
avctx->release_buffer(avctx, &c->last); avctx->release_buffer(avctx, c->last);
avcodec_free_frame(&c->pic);
avcodec_free_frame(&c->last);
free_bundles(c); free_bundles(c);
return 0; return 0;

View File

@ -49,7 +49,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
unsigned int depth; unsigned int depth;
BiCompression comp; BiCompression comp;
unsigned int ihsize; unsigned int ihsize;
int i, j, n, linesize; int i, j, n, linesize, ret;
uint32_t rgb[3]; uint32_t rgb[3];
uint32_t alpha = 0; uint32_t alpha = 0;
uint8_t *ptr; uint8_t *ptr;
@ -59,13 +59,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if (buf_size < 14) { if (buf_size < 14) {
av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size); 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' || if (bytestream_get_byte(&buf) != 'B' ||
bytestream_get_byte(&buf) != 'M') { bytestream_get_byte(&buf) != 'M') {
av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
return -1; return AVERROR_INVALIDDATA;
} }
fsize = bytestream_get_le32(&buf); fsize = bytestream_get_le32(&buf);
@ -82,7 +82,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
ihsize = bytestream_get_le32(&buf); /* more header size */ ihsize = bytestream_get_le32(&buf); /* more header size */
if (ihsize + 14 > hsize) { if (ihsize + 14 > hsize) {
av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", 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 */ /* sometimes file size is set to some headers size, set a real size in that case */
@ -92,7 +92,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if (fsize <= hsize) { if (fsize <= hsize) {
av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n", av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n",
fsize, hsize); fsize, hsize);
return -1; return AVERROR_INVALIDDATA;
} }
switch (ihsize) { switch (ihsize) {
@ -110,13 +110,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n"); av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n");
return -1; return AVERROR_PATCHWELCOME;
} }
/* planes */ /* planes */
if (bytestream_get_le16(&buf) != 1) { if (bytestream_get_le16(&buf) != 1) {
av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n"); av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n");
return -1; return AVERROR_INVALIDDATA;
} }
depth = bytestream_get_le16(&buf); depth = bytestream_get_le16(&buf);
@ -129,7 +129,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if (comp != BMP_RGB && comp != BMP_BITFIELDS && comp != BMP_RLE4 && if (comp != BMP_RGB && comp != BMP_BITFIELDS && comp != BMP_RLE4 &&
comp != BMP_RLE8) { comp != BMP_RLE8) {
av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp); av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp);
return -1; return AVERROR_INVALIDDATA;
} }
if (comp == BMP_BITFIELDS) { if (comp == BMP_BITFIELDS) {
@ -195,26 +195,26 @@ static int bmp_decode_frame(AVCodecContext *avctx,
avctx->pix_fmt = AV_PIX_FMT_PAL8; avctx->pix_fmt = AV_PIX_FMT_PAL8;
} else { } else {
av_log(avctx, AV_LOG_ERROR, "Unknown palette for %d-colour BMP\n", 1<<depth); av_log(avctx, AV_LOG_ERROR, "Unknown palette for %d-colour BMP\n", 1<<depth);
return -1; return AVERROR_INVALIDDATA;
} }
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth); av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth);
return -1; return AVERROR_INVALIDDATA;
} }
if (avctx->pix_fmt == AV_PIX_FMT_NONE) { if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (p->data[0]) if (p->data[0])
avctx->release_buffer(avctx, p); avctx->release_buffer(avctx, p);
p->reference = 0; 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"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return ret;
} }
p->pict_type = AV_PICTURE_TYPE_I; p->pict_type = AV_PICTURE_TYPE_I;
p->key_frame = 1; p->key_frame = 1;
@ -228,7 +228,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
if (n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8) { if (n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8) {
av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
dsize, n * avctx->height); dsize, n * avctx->height);
return -1; return AVERROR_INVALIDDATA;
} }
// RLE may skip decoding some picture areas, so blank picture before decoding // RLE may skip decoding some picture areas, so blank picture before decoding
@ -333,7 +333,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n"); av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n");
return -1; return AVERROR_INVALIDDATA;
} }
} }

View File

@ -68,7 +68,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
int i; int i;
if (src_len <= 0) if (src_len <= 0)
return -1; return AVERROR_INVALIDDATA;
if (forward) { if (forward) {
src = source; src = source;
@ -92,7 +92,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
*/ */
if (!mode || (tmplen == 4)) { if (!mode || (tmplen == 4)) {
if (src < source || src >= source_end) if (src < source || src >= source_end)
return -1; return AVERROR_INVALIDDATA;
val = *src; val = *src;
read_two_nibbles = 1; read_two_nibbles = 1;
} else { } else {
@ -105,7 +105,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
return -1; return -1;
if (!read_two_nibbles) { if (!read_two_nibbles) {
if (src < source || src >= source_end) if (src < source || src >= source_end)
return -1; return AVERROR_INVALIDDATA;
shift += 2; shift += 2;
val |= *src << shift; val |= *src << shift;
if (*src & 0xC) if (*src & 0xC)
@ -141,7 +141,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
if (mode >= 4) if (mode >= 4)
mode -= 3; mode -= 3;
if (FFABS(dst_end - dst) < len) if (FFABS(dst_end - dst) < len)
return -1; return AVERROR_INVALIDDATA;
switch (mode) { switch (mode) {
case 1: case 1:
if (forward) { if (forward) {
@ -149,7 +149,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
dst - frame + SCREEN_WIDE + frame_off < 0 || dst - frame + SCREEN_WIDE + frame_off < 0 ||
frame_end - dst < frame_off + len || frame_end - dst < frame_off + len ||
frame_end - dst < len) frame_end - dst < len)
return -1; return AVERROR_INVALIDDATA;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
dst[i] = dst[frame_off + i]; dst[i] = dst[frame_off + i];
dst += len; dst += len;
@ -159,7 +159,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
dst - frame + SCREEN_WIDE + frame_off < 0 || dst - frame + SCREEN_WIDE + frame_off < 0 ||
frame_end - dst < frame_off + len || frame_end - dst < frame_off + len ||
frame_end - dst < len) frame_end - dst < len)
return -1; return AVERROR_INVALIDDATA;
for (i = len - 1; i >= 0; i--) for (i = len - 1; i >= 0; i--)
dst[i] = dst[frame_off + i]; dst[i] = dst[frame_off + i];
} }
@ -167,13 +167,13 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame,
case 2: case 2:
if (forward) { if (forward) {
if (source + src_len - src < len) if (source + src_len - src < len)
return -1; return AVERROR_INVALIDDATA;
memcpy(dst, src, len); memcpy(dst, src, len);
dst += len; dst += len;
src += len; src += len;
} else { } else {
if (src - source < len) if (src - source < len)
return -1; return AVERROR_INVALIDDATA;
dst -= len; dst -= len;
src -= len; src -= len;
memcpy(dst, src, len); memcpy(dst, src, len);

View File

@ -134,7 +134,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
newpic->reference = 3; newpic->reference = 3;
newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
if ((ret = avctx->reget_buffer(avctx, newpic))) { if ((ret = avctx->reget_buffer(avctx, newpic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret; return ret;
} }
@ -166,8 +166,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
switch (block_type) { switch (block_type) {
case C93_8X8_FROM_PREV: case C93_8X8_FROM_PREV:
offset = bytestream2_get_le16(&gb); offset = bytestream2_get_le16(&gb);
if (copy_block(avctx, out, copy_from, offset, 8, stride)) if ((ret = copy_block(avctx, out, copy_from, offset, 8, stride)) < 0)
return AVERROR_INVALIDDATA; return ret;
break; break;
case C93_4X4_FROM_CURR: case C93_4X4_FROM_CURR:
@ -176,9 +176,9 @@ static int decode_frame(AVCodecContext *avctx, void *data,
for (j = 0; j < 8; j += 4) { for (j = 0; j < 8; j += 4) {
for (i = 0; i < 8; i += 4) { for (i = 0; i < 8; i += 4) {
offset = bytestream2_get_le16(&gb); offset = bytestream2_get_le16(&gb);
if (copy_block(avctx, &out[j*stride+i], if ((ret = copy_block(avctx, &out[j*stride+i],
copy_from, offset, 4, stride)) copy_from, offset, 4, stride)) < 0)
return AVERROR_INVALIDDATA; return ret;
} }
} }
break; break;

View File

@ -116,7 +116,7 @@ static int xan_huffman_decode(unsigned char *dest, int dest_len,
while (val != 0x16) { while (val != 0x16) {
unsigned idx = val - 0x17 + get_bits1(&gb) * byte; unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
if (idx >= 2 * byte) if (idx >= 2 * byte)
return -1; return AVERROR_INVALIDDATA;
val = src[idx]; val = src[idx];
if (val < 0x16) { if (val < 0x16) {

View File

@ -69,7 +69,7 @@ static int decode_frame(AVCodecContext *avctx,
avctx->release_buffer(avctx, p); avctx->release_buffer(avctx, p);
p->reference = 0; p->reference = 0;
if ((ret = ff_get_buffer(avctx, p)) < 0) { if ((ret = ff_get_buffer(avctx, p)) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
} }

View File

@ -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); dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size);
if (dec_size < 0) { if (dec_size < 0) {
av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n"); av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n");
return AVERROR_INVALIDDATA; return dec_size;
} }
U = s->pic.data[1]; U = s->pic.data[1];

View File

@ -85,7 +85,8 @@ static av_cold int yop_decode_init(AVCodecContext *avctx)
if (avctx->width & 1 || avctx->height & 1 || if (avctx->width & 1 || avctx->height & 1 ||
av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
return -1; av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n");
return AVERROR_INVALIDDATA;
} }
if (!avctx->extradata) { if (!avctx->extradata) {

View File

@ -485,7 +485,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
zret = inflateReset(&c->zstream); zret = inflateReset(&c->zstream);
if (zret != Z_OK) { if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
return -1; return AVERROR_UNKNOWN;
} }
c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8));
@ -642,7 +642,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
zret = inflateInit(&c->zstream); zret = inflateInit(&c->zstream);
if (zret != Z_OK) { if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
return -1; return AVERROR_UNKNOWN;
} }
return 0; return 0;