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/libpam.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'lib/libpam.c') diff --git a/lib/libpam.c b/lib/libpam.c index 07241e9e..206e850f 100644 --- a/lib/libpam.c +++ b/lib/libpam.c @@ -132,19 +132,7 @@ 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); + pgm_validateComputableMaxval(pamP->maxval); } @@ -1121,6 +1109,8 @@ pnm_writepaminit(struct pam * const pamP) { switch (PAM_FORMAT_TYPE(pamP->format)) { case PAM_TYPE: + validateComputableSize(pamP); + validateComputableMaxval(pamP); /* See explanation below of why we ignore 'pm_plain_output' here. */ fprintf(pamP->file, "P7\n"); writeComments(pamP); -- cgit 1.4.1