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

bink: return meaningful error codes.

This commit is contained in:
Anton Khirnov 2012-11-14 21:47:37 +01:00
parent 86e09b9e60
commit 86d4e75422

View File

@ -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;