* commit '57d11e5e28bfe0bc445ad78fc033aafa73068bb4': fraps: return meaningful error codes. kgv1dec: return meaningful error codes. kmvc: return meaningful error codes. wnv1: return meaningful error codes. dpx: return meaningful error codes. truemotion1: return meaningful error codes pnm: return meaningful error codes. Conflicts: libavcodec/dpx.c libavcodec/fraps.c libavcodec/kmvc.c libavcodec/pnm.c libavcodec/pnmdec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>tags/n1.2
@@ -71,7 +71,7 @@ static int decode_frame(AVCodecContext *avctx, | |||||
unsigned int offset; | unsigned int offset; | ||||
int magic_num, endian; | int magic_num, endian; | ||||
int x, y, i; | |||||
int x, y, i, ret; | |||||
int w, h, bits_per_color, descriptor, elements, packing, total_size; | int w, h, bits_per_color, descriptor, elements, packing, total_size; | ||||
unsigned int rgbBuffer = 0; | unsigned int rgbBuffer = 0; | ||||
@@ -93,7 +93,7 @@ static int decode_frame(AVCodecContext *avctx, | |||||
endian = 1; | endian = 1; | ||||
} else { | } else { | ||||
av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); | av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n"); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
offset = read32(&buf, endian); | offset = read32(&buf, endian); | ||||
@@ -105,8 +105,8 @@ static int decode_frame(AVCodecContext *avctx, | |||||
buf = avpkt->data + 0x304; | buf = avpkt->data + 0x304; | ||||
w = read32(&buf, endian); | w = read32(&buf, endian); | ||||
h = read32(&buf, endian); | h = read32(&buf, endian); | ||||
if (av_image_check_size(w, h, 0, avctx)) | |||||
return AVERROR(EINVAL); | |||||
if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) | |||||
return ret; | |||||
if (w != avctx->width || h != avctx->height) | if (w != avctx->width || h != avctx->height) | ||||
avcodec_set_dimensions(avctx, w, h); | avcodec_set_dimensions(avctx, w, h); | ||||
@@ -141,7 +141,7 @@ static int decode_frame(AVCodecContext *avctx, | |||||
break; | break; | ||||
default: | default: | ||||
av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor); | av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
switch (bits_per_color) { | switch (bits_per_color) { | ||||
@@ -183,14 +183,14 @@ static int decode_frame(AVCodecContext *avctx, | |||||
break; | break; | ||||
default: | default: | ||||
av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color); | av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
if (s->picture.data[0]) | if (s->picture.data[0]) | ||||
avctx->release_buffer(avctx, &s->picture); | avctx->release_buffer(avctx, &s->picture); | ||||
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; | |||||
} | } | ||||
// Move pointer to offset from start of file | // Move pointer to offset from start of file | ||||
@@ -201,7 +201,7 @@ static int decode_frame(AVCodecContext *avctx, | |||||
if (total_size > avpkt->size) { | if (total_size > avpkt->size) { | ||||
av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); | av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
switch (bits_per_color) { | switch (bits_per_color) { | ||||
case 10: | case 10: | ||||
@@ -88,7 +88,7 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w, | |||||
int h, const uint8_t *src, int size, int Uoff, | int h, const uint8_t *src, int size, int Uoff, | ||||
const int step) | const int step) | ||||
{ | { | ||||
int i, j; | |||||
int i, j, ret; | |||||
GetBitContext gb; | GetBitContext gb; | ||||
VLC vlc; | VLC vlc; | ||||
Node nodes[512]; | Node nodes[512]; | ||||
@@ -96,9 +96,9 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w, | |||||
for(i = 0; i < 256; i++) | for(i = 0; i < 256; i++) | ||||
nodes[i].count = bytestream_get_le32(&src); | nodes[i].count = bytestream_get_le32(&src); | ||||
size -= 1024; | size -= 1024; | ||||
if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, | |||||
FF_HUFFMAN_FLAG_ZERO_COUNT) < 0) | |||||
return -1; | |||||
if ((ret = ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, | |||||
FF_HUFFMAN_FLAG_ZERO_COUNT)) < 0) | |||||
return ret; | |||||
/* we have built Huffman table and are ready to decode plane */ | /* we have built Huffman table and are ready to decode plane */ | ||||
/* convert bits so they may be used by standard bitreader */ | /* convert bits so they may be used by standard bitreader */ | ||||
@@ -139,11 +139,10 @@ static int decode_frame(AVCodecContext *avctx, | |||||
const uint32_t *buf32; | const uint32_t *buf32; | ||||
uint32_t *luma1,*luma2,*cb,*cr; | uint32_t *luma1,*luma2,*cb,*cr; | ||||
uint32_t offs[4]; | uint32_t offs[4]; | ||||
int i, j, is_chroma; | |||||
int i, j, ret, is_chroma; | |||||
const int planes = 3; | const int planes = 3; | ||||
uint8_t *out; | uint8_t *out; | ||||
enum AVPixelFormat pix_fmt; | enum AVPixelFormat pix_fmt; | ||||
int ret; | |||||
header = AV_RL32(buf); | header = AV_RL32(buf); | ||||
version = header & 0xff; | version = header & 0xff; | ||||
@@ -249,6 +248,7 @@ static int decode_frame(AVCodecContext *avctx, | |||||
memcpy(&f->data[0][ (avctx->height-y)*f->linesize[0] ], | memcpy(&f->data[0][ (avctx->height-y)*f->linesize[0] ], | ||||
&buf[y*avctx->width*3], | &buf[y*avctx->width*3], | ||||
3*avctx->width); | 3*avctx->width); | ||||
break; | break; | ||||
case 2: | case 2: | ||||
@@ -259,10 +259,13 @@ static int decode_frame(AVCodecContext *avctx, | |||||
*/ | */ | ||||
for(i = 0; i < planes; i++){ | for(i = 0; i < planes; i++){ | ||||
is_chroma = !!i; | is_chroma = !!i; | ||||
if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width >> is_chroma, | |||||
avctx->height >> is_chroma, buf + offs[i], offs[i + 1] - offs[i], is_chroma, 1) < 0) { | |||||
if ((ret = fraps2_decode_plane(s, f->data[i], f->linesize[i], | |||||
avctx->width >> is_chroma, | |||||
avctx->height >> is_chroma, | |||||
buf + offs[i], offs[i + 1] - offs[i], | |||||
is_chroma, 1)) < 0) { | |||||
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); | av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); | ||||
return AVERROR_INVALIDDATA; | |||||
return ret; | |||||
} | } | ||||
} | } | ||||
break; | break; | ||||
@@ -270,10 +273,11 @@ static int decode_frame(AVCodecContext *avctx, | |||||
case 5: | case 5: | ||||
/* Virtually the same as version 4, but is for RGB24 */ | /* Virtually the same as version 4, but is for RGB24 */ | ||||
for(i = 0; i < planes; i++){ | for(i = 0; i < planes; i++){ | ||||
if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0], | |||||
avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) { | |||||
if ((ret = fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), | |||||
-f->linesize[0], avctx->width, avctx->height, | |||||
buf + offs[i], offs[i + 1] - offs[i], 0, 3)) < 0) { | |||||
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); | av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); | ||||
return AVERROR_INVALIDDATA; | |||||
return ret; | |||||
} | } | ||||
} | } | ||||
out = f->data[0]; | out = f->data[0]; | ||||
@@ -55,14 +55,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, | |||||
int w, h, i, res; | int w, h, i, res; | ||||
if (avpkt->size < 2) | if (avpkt->size < 2) | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
w = (buf[0] + 1) * 8; | w = (buf[0] + 1) * 8; | ||||
h = (buf[1] + 1) * 8; | h = (buf[1] + 1) * 8; | ||||
buf += 2; | buf += 2; | ||||
if (av_image_check_size(w, h, 0, avctx)) | |||||
return -1; | |||||
if ((res = av_image_check_size(w, h, 0, avctx)) < 0) | |||||
return res; | |||||
if (w != avctx->width || h != avctx->height) { | if (w != avctx->width || h != avctx->height) { | ||||
if (c->prev.data[0]) | if (c->prev.data[0]) | ||||
@@ -264,11 +264,10 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame, | |||||
{ | { | ||||
KmvcContext *const ctx = avctx->priv_data; | KmvcContext *const ctx = avctx->priv_data; | ||||
uint8_t *out, *src; | uint8_t *out, *src; | ||||
int i; | |||||
int i, ret; | |||||
int header; | int header; | ||||
int blocksize; | int blocksize; | ||||
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); | ||||
int ret; | |||||
bytestream2_init(&ctx->g, avpkt->data, avpkt->size); | bytestream2_init(&ctx->g, avpkt->data, avpkt->size); | ||||
if (ctx->pic.data[0]) | if (ctx->pic.data[0]) | ||||
@@ -383,7 +382,7 @@ static av_cold int decode_init(AVCodecContext * avctx) | |||||
if (avctx->width > 320 || avctx->height > 200) { | if (avctx->width > 320 || avctx->height > 200) { | ||||
av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n"); | av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n"); | ||||
return AVERROR_INVALIDDATA; | |||||
return AVERROR(EINVAL); | |||||
} | } | ||||
c->frm0 = av_mallocz(320 * 200); | c->frm0 = av_mallocz(320 * 200); | ||||
@@ -65,7 +65,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) | |||||
pnm_get(s, buf1, sizeof(buf1)); | pnm_get(s, buf1, sizeof(buf1)); | ||||
s->type= buf1[1]-'0'; | s->type= buf1[1]-'0'; | ||||
if(buf1[0] != 'P') | if(buf1[0] != 'P') | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
if (s->type==1 || s->type==4) { | if (s->type==1 || s->type==4) { | ||||
avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; | avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; | ||||
@@ -103,12 +103,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) | |||||
} else if (!strcmp(buf1, "ENDHDR")) { | } else if (!strcmp(buf1, "ENDHDR")) { | ||||
break; | break; | ||||
} else { | } else { | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
} | } | ||||
/* check that all tags are present */ | /* check that all tags are present */ | ||||
if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) | if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
avctx->width = w; | avctx->width = w; | ||||
avctx->height = h; | avctx->height = h; | ||||
@@ -137,18 +137,18 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) | |||||
avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; | avctx->pix_fmt = AV_PIX_FMT_RGBA64BE; | ||||
} | } | ||||
} else { | } else { | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
return 0; | return 0; | ||||
} else { | } else { | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
pnm_get(s, buf1, sizeof(buf1)); | pnm_get(s, buf1, sizeof(buf1)); | ||||
w = atoi(buf1); | w = atoi(buf1); | ||||
pnm_get(s, buf1, sizeof(buf1)); | pnm_get(s, buf1, sizeof(buf1)); | ||||
h = atoi(buf1); | h = atoi(buf1); | ||||
if(w <= 0 || h <= 0 || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) | if(w <= 0 || h <= 0 || av_image_check_size(w, h, 0, avctx) || s->bytestream >= s->bytestream_end) | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
avctx->width = w; | avctx->width = w; | ||||
avctx->height = h; | avctx->height = h; | ||||
@@ -168,7 +168,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) | |||||
} else { | } else { | ||||
av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n"); | av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n"); | ||||
avctx->pix_fmt = AV_PIX_FMT_NONE; | avctx->pix_fmt = AV_PIX_FMT_NONE; | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
} | } | ||||
}else | }else | ||||
@@ -176,10 +176,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) | |||||
/* more check if YUV420 */ | /* more check if YUV420 */ | ||||
if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { | if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) { | ||||
if ((avctx->width & 1) != 0) | if ((avctx->width & 1) != 0) | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
h = (avctx->height * 2); | h = (avctx->height * 2); | ||||
if ((h % 3) != 0) | if ((h % 3) != 0) | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
h /= 3; | h /= 3; | ||||
avctx->height = h; | avctx->height = h; | ||||
} | } | ||||
@@ -41,8 +41,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, | |||||
s->bytestream = (uint8_t *)buf; | s->bytestream = (uint8_t *)buf; | ||||
s->bytestream_end = (uint8_t *)buf + buf_size; | s->bytestream_end = (uint8_t *)buf + buf_size; | ||||
if (ff_pnm_decode_header(avctx, s) < 0) | |||||
return AVERROR_INVALIDDATA; | |||||
if ((ret = ff_pnm_decode_header(avctx, s)) < 0) | |||||
return ret; | |||||
if (p->data[0]) | if (p->data[0]) | ||||
avctx->release_buffer(avctx, p); | avctx->release_buffer(avctx, p); | ||||
@@ -57,7 +57,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, | |||||
switch (avctx->pix_fmt) { | switch (avctx->pix_fmt) { | ||||
default: | default: | ||||
return AVERROR_INVALIDDATA; | |||||
return AVERROR(EINVAL); | |||||
case AV_PIX_FMT_RGBA64BE: | case AV_PIX_FMT_RGBA64BE: | ||||
n = avctx->width * 8; | n = avctx->width * 8; | ||||
components=4; | components=4; | ||||
@@ -308,7 +308,7 @@ static void gen_vector_table24(TrueMotion1Context *s, const uint8_t *sel_vector_ | |||||
* there was an error while decoding the header */ | * there was an error while decoding the header */ | ||||
static int truemotion1_decode_header(TrueMotion1Context *s) | static int truemotion1_decode_header(TrueMotion1Context *s) | ||||
{ | { | ||||
int i; | |||||
int i, ret; | |||||
int width_shift = 0; | int width_shift = 0; | ||||
int new_pix_fmt; | int new_pix_fmt; | ||||
struct frame_header header; | struct frame_header header; | ||||
@@ -319,7 +319,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) | |||||
if (s->buf[0] < 0x10 || header.header_size >= s->size) | if (s->buf[0] < 0x10 || header.header_size >= s->size) | ||||
{ | { | ||||
av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]); | av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
/* unscramble the header bytes with a XOR operation */ | /* unscramble the header bytes with a XOR operation */ | ||||
@@ -343,7 +343,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) | |||||
if (header.header_type > 3) | if (header.header_type > 3) | ||||
{ | { | ||||
av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type); | av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} else if ((header.header_type == 2) || (header.header_type == 3)) { | } else if ((header.header_type == 2) || (header.header_type == 3)) { | ||||
s->flags = header.flags; | s->flags = header.flags; | ||||
if (!(s->flags & FLAG_INTERFRAME)) | if (!(s->flags & FLAG_INTERFRAME)) | ||||
@@ -371,7 +371,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) | |||||
if (header.compression >= 17) { | if (header.compression >= 17) { | ||||
av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression); | av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
if ((header.deltaset != s->last_deltaset) || | if ((header.deltaset != s->last_deltaset) || | ||||
@@ -385,7 +385,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) | |||||
sel_vector_table = tables[header.vectable - 1]; | sel_vector_table = tables[header.vectable - 1]; | ||||
else { | else { | ||||
av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable); | av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable); | ||||
return -1; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
} | } | ||||
@@ -396,8 +396,8 @@ static int truemotion1_decode_header(TrueMotion1Context *s) | |||||
new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well | new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well | ||||
s->w >>= width_shift; | s->w >>= width_shift; | ||||
if (av_image_check_size(s->w, s->h, 0, s->avctx) < 0) | |||||
return -1; | |||||
if ((ret = av_image_check_size(s->w, s->h, 0, s->avctx)) < 0) | |||||
return ret; | |||||
if (s->w != s->avctx->width || s->h != s->avctx->height || | if (s->w != s->avctx->width || s->h != s->avctx->height || | ||||
new_pix_fmt != s->avctx->pix_fmt) { | new_pix_fmt != s->avctx->pix_fmt) { | ||||
@@ -860,21 +860,21 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, | |||||
AVPacket *avpkt) | AVPacket *avpkt) | ||||
{ | { | ||||
const uint8_t *buf = avpkt->data; | const uint8_t *buf = avpkt->data; | ||||
int buf_size = avpkt->size; | |||||
int ret, buf_size = avpkt->size; | |||||
TrueMotion1Context *s = avctx->priv_data; | TrueMotion1Context *s = avctx->priv_data; | ||||
s->buf = buf; | s->buf = buf; | ||||
s->size = buf_size; | s->size = buf_size; | ||||
if (truemotion1_decode_header(s) == -1) | |||||
return -1; | |||||
if ((ret = truemotion1_decode_header(s)) < 0) | |||||
return ret; | |||||
s->frame.reference = 3; | s->frame.reference = 3; | ||||
s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | | s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | | ||||
FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; | ||||
if (avctx->reget_buffer(avctx, &s->frame) < 0) { | |||||
if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { | |||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | ||||
return -1; | |||||
return ret; | |||||
} | } | ||||
if (compression_types[s->compression].algorithm == ALGO_RGB24H) { | if (compression_types[s->compression].algorithm == ALGO_RGB24H) { | ||||