From fc09e6e252087d2b6b1bec43f8bb1a94ce9cbb40 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 7 Feb 2018 13:43:57 -0800 Subject: [PATCH] PNM decoder: prevent unsupported depth=2 PAM case. Change-Id: I8476818908d71498dd80b07dc255aa008ffd16f5 --- imageio/pnmdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imageio/pnmdec.c b/imageio/pnmdec.c index 6c9a156a..8f5a4a00 100644 --- a/imageio/pnmdec.c +++ b/imageio/pnmdec.c @@ -117,7 +117,7 @@ static size_t ReadPAMFields(PNMInfo* const info, size_t off) { } } if (!(info->seen_flags & TUPLE_FLAG)) { - if (info->depth > 0 && info->depth <= 4) { + if (info->depth > 0 && info->depth <= 4 && info->depth != 2) { info->seen_flags |= TUPLE_FLAG; info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1); } else { @@ -165,7 +165,7 @@ static size_t ReadHeader(PNMInfo* const info) { // perform some basic numerical validation if (info->width <= 0 || info->height <= 0 || info->type <= 0 || info->type >= 9 || - info->depth <= 0 || info->depth > 4 || + info->depth <= 0 || info->depth == 2 || info->depth > 4 || info->bytes_per_px < info->depth || info->max_value <= 0 || info->max_value >= 65536) { return 0;