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/libpam.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/libpam.c') diff --git a/lib/libpam.c b/lib/libpam.c index ee99e6da..07241e9e 100644 --- a/lib/libpam.c +++ b/lib/libpam.c @@ -127,6 +127,28 @@ validateComputableSize(struct pam * const pamP) { +static void +validateComputableMaxval(const struct pam * const pamP) { +/*---------------------------------------------------------------------------- + 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 (pamP->maxval == 0) + pm_error("Maxval is zero. Must be at least one."); + + if (pamP->maxval > INT_MAX-1) + pm_error("Maxval (%lu) is too large to be processed", pamP->maxval); +} + + + tuple pnm_allocpamtuple(const struct pam * const pamP) { @@ -990,6 +1012,8 @@ pnm_readpaminit(FILE * const file, interpretTupleType(pamP); validateComputableSize(pamP); + + validateComputableMaxval(pamP); } -- cgit 1.4.1