about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-19 18:02:53 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-19 18:02:53 +0000
commit09d7f7fce3231513d5a970f6029f3335449e8be6 (patch)
treecb7d2378af64c18aa630c320136df4563c93886c /lib
parent9eb2c86ec808bbd675645c96f2337e51611b3463 (diff)
downloadnetpbm-mirror-09d7f7fce3231513d5a970f6029f3335449e8be6.tar.gz
netpbm-mirror-09d7f7fce3231513d5a970f6029f3335449e8be6.tar.xz
netpbm-mirror-09d7f7fce3231513d5a970f6029f3335449e8be6.zip
Add computable size check for maxval
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4602 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpam.c24
-rw-r--r--lib/libpgm1.c24
-rw-r--r--lib/libpnm1.c24
-rw-r--r--lib/libppm1.c24
4 files changed, 96 insertions, 0 deletions
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);
 }
 
 
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);
 }
 
 
diff --git a/lib/libpnm1.c b/lib/libpnm1.c
index db21b078..1e774df6 100644
--- a/lib/libpnm1.c
+++ b/lib/libpnm1.c
@@ -83,6 +83,28 @@ validateComputableSize(unsigned int const cols,
 
 
 
+static void
+validateComputableMaxval(pixval 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
 pnm_readpnminit(FILE *   const fileP,
                 int *    const colsP,
@@ -130,6 +152,8 @@ pnm_readpnminit(FILE *   const fileP,
                  realFormat);
     }
     validateComputableSize(*colsP, *rowsP);
+
+    validateComputableMaxval(*maxvalP);
 }
 
 
diff --git a/lib/libppm1.c b/lib/libppm1.c
index ccc8adb5..427adf4d 100644
--- a/lib/libppm1.c
+++ b/lib/libppm1.c
@@ -113,6 +113,28 @@ validateComputableSize(unsigned int const cols,
 
 
 
+static void
+validateComputableMaxval(pixval 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
 ppm_readppminit(FILE *   const fileP,
                 int *    const colsP,
@@ -151,6 +173,8 @@ ppm_readppminit(FILE *   const fileP,
                  realFormat);
     }
     validateComputableSize(*colsP, *rowsP);
+
+    validateComputableMaxval(*maxvalP);
 }