Commit 380242ca authored by Anton Khirnov's avatar Anton Khirnov

pnm: return meaningful error codes.

parent 84f2847d
...@@ -65,7 +65,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -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) ...@@ -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)) if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || av_image_check_size(w, h, 0, avctx))
return -1; return AVERROR_INVALIDDATA;
avctx->width = w; avctx->width = w;
avctx->height = h; avctx->height = h;
...@@ -123,25 +123,25 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -123,25 +123,25 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
} else { } else {
av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n"); av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
avctx->pix_fmt = AV_PIX_FMT_NONE; avctx->pix_fmt = AV_PIX_FMT_NONE;
return -1; return AVERROR_INVALIDDATA;
} }
} else if (depth == 4) { } else if (depth == 4) {
avctx->pix_fmt = AV_PIX_FMT_RGB32; avctx->pix_fmt = AV_PIX_FMT_RGB32;
} 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));
avctx->width = atoi(buf1); avctx->width = atoi(buf1);
if (avctx->width <= 0) if (avctx->width <= 0)
return -1; return AVERROR_INVALIDDATA;
pnm_get(s, buf1, sizeof(buf1)); pnm_get(s, buf1, sizeof(buf1));
avctx->height = atoi(buf1); avctx->height = atoi(buf1);
if(av_image_check_size(avctx->width, avctx->height, 0, avctx)) if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
return -1; return AVERROR_INVALIDDATA;
if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) { if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) {
pnm_get(s, buf1, sizeof(buf1)); pnm_get(s, buf1, sizeof(buf1));
s->maxval = atoi(buf1); s->maxval = atoi(buf1);
...@@ -160,7 +160,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -160,7 +160,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
...@@ -168,10 +168,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) ...@@ -168,10 +168,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;
} }
......
...@@ -36,29 +36,29 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -36,29 +36,29 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
AVFrame * const p = &s->picture; AVFrame * const p = &s->picture;
int i, j, n, linesize, h, upgrade = 0; int i, j, n, linesize, h, upgrade = 0;
unsigned char *ptr; unsigned char *ptr;
int components, sample_len; int components, sample_len, ret;
s->bytestream_start = s->bytestream_start =
s->bytestream = buf; s->bytestream = buf;
s->bytestream_end = buf + buf_size; s->bytestream_end = buf + buf_size;
if (ff_pnm_decode_header(avctx, s) < 0) if ((ret = ff_pnm_decode_header(avctx, s)) < 0)
return -1; return ret;
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;
switch (avctx->pix_fmt) { switch (avctx->pix_fmt) {
default: default:
return -1; return AVERROR(EINVAL);
case AV_PIX_FMT_RGB48BE: case AV_PIX_FMT_RGB48BE:
n = avctx->width * 6; n = avctx->width * 6;
components=3; components=3;
...@@ -93,7 +93,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -93,7 +93,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
ptr = p->data[0]; ptr = p->data[0];
linesize = p->linesize[0]; linesize = p->linesize[0];
if (s->bytestream + n * avctx->height > s->bytestream_end) if (s->bytestream + n * avctx->height > s->bytestream_end)
return -1; return AVERROR_INVALIDDATA;
if(s->type < 4){ if(s->type < 4){
for (i=0; i<avctx->height; i++) { for (i=0; i<avctx->height; i++) {
PutBitContext pb; PutBitContext pb;
...@@ -104,7 +104,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -104,7 +104,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' )) while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' ))
s->bytestream++; s->bytestream++;
if(s->bytestream >= s->bytestream_end) if(s->bytestream >= s->bytestream_end)
return -1; return AVERROR_INVALIDDATA;
do{ do{
v= 10*v + c; v= 10*v + c;
c= (*s->bytestream++) - '0'; c= (*s->bytestream++) - '0';
...@@ -142,7 +142,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -142,7 +142,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
ptr = p->data[0]; ptr = p->data[0];
linesize = p->linesize[0]; linesize = p->linesize[0];
if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end)
return -1; return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->height; i++) { for (i = 0; i < avctx->height; i++) {
memcpy(ptr, s->bytestream, n); memcpy(ptr, s->bytestream, n);
s->bytestream += n; s->bytestream += n;
...@@ -166,7 +166,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, ...@@ -166,7 +166,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
ptr = p->data[0]; ptr = p->data[0];
linesize = p->linesize[0]; linesize = p->linesize[0];
if (s->bytestream + avctx->width * avctx->height * 4 > s->bytestream_end) if (s->bytestream + avctx->width * avctx->height * 4 > s->bytestream_end)
return -1; return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->height; i++) { for (i = 0; i < avctx->height; i++) {
int j, r, g, b, a; int j, r, g, b, a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment