changeset 7859:48d00b406a26 libavcodec

Return error when trying to decode non-grayscale 16-bit PNM images. Fixes issue 566.
author jbr
date Sun, 14 Sep 2008 15:50:59 +0000
parents f75806078d46
children c11e175fc544
files pnm.c
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pnm.c	Sat Sep 13 20:52:57 2008 +0000
+++ b/pnm.c	Sun Sep 14 15:50:59 2008 +0000
@@ -106,7 +106,13 @@
             else
                 avctx->pix_fmt = PIX_FMT_GRAY8;
         } else if (depth == 3) {
+            if (maxval < 256) {
             avctx->pix_fmt = PIX_FMT_RGB24;
+            } else {
+                av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
+                avctx->pix_fmt = PIX_FMT_NONE;
+                return -1;
+            }
         } else if (depth == 4) {
             avctx->pix_fmt = PIX_FMT_RGB32;
         } else {
@@ -127,10 +133,16 @@
     if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
         pnm_get(s, buf1, sizeof(buf1));
         s->maxval = atoi(buf1);
-        if(s->maxval >= 256 && avctx->pix_fmt == PIX_FMT_GRAY8) {
+        if (s->maxval >= 256) {
+            if (avctx->pix_fmt == PIX_FMT_GRAY8) {
             avctx->pix_fmt = PIX_FMT_GRAY16BE;
             if (s->maxval != 65535)
                 avctx->pix_fmt = PIX_FMT_GRAY16;
+            } else {
+                av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
+                avctx->pix_fmt = PIX_FMT_NONE;
+                return -1;
+            }
         }
     }
     /* more check if YUV420 */