]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/targa.c
Merge commit 'bfe5454cd238b16e7977085f880205229103eccb'
[ffmpeg] / libavcodec / targa.c
index e1d83b9b12a57586c102b6958a7cc5b64cba398f..d761078cfefe710da51a91a5c9984095b3da16d5 100644 (file)
@@ -115,7 +115,7 @@ static int decode_frame(AVCodecContext *avctx,
     AVFrame * const p = &s->picture;
     uint8_t *dst;
     int stride;
-    int idlen, pal, compr, y, w, h, bpp, flags;
+    int idlen, pal, compr, y, w, h, bpp, flags, ret;
     int first_clr, colors, csize;
     int interleave;
 
@@ -166,19 +166,24 @@ static int decode_frame(AVCodecContext *avctx,
         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", bpp);
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (s->picture.data[0])
         avctx->release_buffer(avctx, &s->picture);
 
-    if (av_image_check_size(w, h, 0, avctx))
-        return -1;
+    if (colors && (colors + first_clr) > 256) {
+        av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr);
+        return AVERROR_INVALIDDATA;
+    }
+
+    if ((ret = av_image_check_size(w, h, 0, avctx)))
+        return ret;
     if (w != avctx->width || h != avctx->height)
         avcodec_set_dimensions(avctx, w, h);
-    if (avctx->get_buffer(avctx, p) < 0) {
+    if ((ret = avctx->get_buffer(avctx, p)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return ret;
     }
 
     if (flags & TGA_TOPTOBOTTOM) {
@@ -194,10 +199,6 @@ static int decode_frame(AVCodecContext *avctx,
 
     if (colors) {
         int pal_size, pal_sample_size;
-        if ((colors + first_clr) > 256) {
-            av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr);
-            return -1;
-        }
         switch (csize) {
         case 32: pal_sample_size = 4; break;
         case 24: pal_sample_size = 3; break;
@@ -205,7 +206,7 @@ static int decode_frame(AVCodecContext *avctx,
         case 15: pal_sample_size = 2; break;
         default:
             av_log(avctx, AV_LOG_ERROR, "Palette entry size %i bits is not supported\n", csize);
-            return -1;
+            return AVERROR_INVALIDDATA;
         }
         pal_size = colors * pal_sample_size;
         if (avctx->pix_fmt != AV_PIX_FMT_PAL8) //should not occur but skip palette anyway