From bf85274a5c089c1c6295f0caf54ecf0c1c42e887 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 29 Sep 2023 17:52:10 +0000 Subject: Validate computable image size and maxval in libnetpbm write init functions git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4706 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpgm2.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/libpgm2.c') diff --git a/lib/libpgm2.c b/lib/libpgm2.c index 2e3aba90..ec3539a2 100644 --- a/lib/libpgm2.c +++ b/lib/libpgm2.c @@ -15,6 +15,7 @@ #include "netpbm/pm_c_util.h" #include "netpbm/mallocvar.h" +#include "libpgm.h" #include "pgm.h" @@ -28,6 +29,13 @@ pgm_writepgminit(FILE * const fileP, bool const plainFormat = forceplain || pm_plain_output; + /* For Caller's convenience, we include validating computability of the + image parameters, since Caller may be using them in arithmetic after + our return. + */ + pgm_validateComputableSize(cols, rows); + pgm_validateComputableMaxval(maxval); + if (maxval > PGM_OVERALLMAXVAL && !plainFormat) pm_error("too-large maxval passed to ppm_writepgminit(): %d.\n" "Maximum allowed by the PGM format is %d.", -- cgit 1.4.1