about summary refs log tree commit diff
path: root/lib/libppm1.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-28 02:40:42 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-28 02:40:42 +0000
commit34546ecb9b586f34e04f6e133a247ffe1f50046e (patch)
tree55c0c6c76c55bfe99a9f3c7dec416604a1c6dbd9 /lib/libppm1.c
parentd484f36f7c690d0a88476127afd9bdf90233699d (diff)
downloadnetpbm-mirror-34546ecb9b586f34e04f6e133a247ffe1f50046e.tar.gz
netpbm-mirror-34546ecb9b586f34e04f6e133a247ffe1f50046e.tar.xz
netpbm-mirror-34546ecb9b586f34e04f6e133a247ffe1f50046e.zip
Release 1.04.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4700 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libppm1.c')
-rw-r--r--lib/libppm1.c24
1 files changed, 24 insertions, 0 deletions
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);
 }