From 09d7f7fce3231513d5a970f6029f3335449e8be6 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 19 Aug 2023 18:02:53 +0000 Subject: Add computable size check for maxval git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4602 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpgm1.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/libpgm1.c') diff --git a/lib/libpgm1.c b/lib/libpgm1.c index 9c089cc0..6feb1c8b 100644 --- a/lib/libpgm1.c +++ b/lib/libpgm1.c @@ -115,6 +115,28 @@ validateComputableSize(unsigned int const cols, +static void +validateComputableMaxval(gray const maxval) { +/*---------------------------------------------------------------------------- + This is similar to validateComputableSize, but for the maxval. +-----------------------------------------------------------------------------*/ + /* Code sometimes allocates an array indexed by sample values and + represents the size of that array as an INT. (UNSIGNED INT would be + more proper, but there's no need to be that permissive). + + Code also sometimes iterates through sample values and quits when the + value is greater than the maxval. + */ + + if (maxval == 0) + pm_error("Maxval is zero. Must be at least one."); + + if (maxval > INT_MAX-1) + pm_error("Maxval (%u) is too large to be processed", maxval); +} + + + void pgm_readpgminit(FILE * const fileP, int * const colsP, @@ -172,6 +194,8 @@ pgm_readpgminit(FILE * const fileP, realFormat); } validateComputableSize(*colsP, *rowsP); + + validateComputableMaxval(*maxvalP); } -- cgit 1.4.1