about summary refs log tree commit diff
path: root/lib/libpnm1.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpnm1.c')
-rw-r--r--lib/libpnm1.c24
1 files changed, 24 insertions, 0 deletions
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);
 }