about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-05 23:07:45 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-05 23:07:45 +0000
commit3f183168c393a7d67ff8afc751496aa3079bf3e5 (patch)
treeee49dd4f5afd4bd8a9030dfe9b12d55b00c1963a
parent24123421ac90801b89e9a11df77e3b27440b0e60 (diff)
downloadnetpbm-mirror-3f183168c393a7d67ff8afc751496aa3079bf3e5.tar.gz
netpbm-mirror-3f183168c393a7d67ff8afc751496aa3079bf3e5.tar.xz
netpbm-mirror-3f183168c393a7d67ff8afc751496aa3079bf3e5.zip
Fix arithmetic overflow on total number of planes
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4575 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY4
-rw-r--r--other/pamstack.c5
2 files changed, 9 insertions, 0 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index a2aa6f47..8bd31abb 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -20,6 +20,10 @@ not yet  BJH  Release 11.04.00
               pamstack: Fix -lcmmaxval: chooses wrong maxval.  Always
               broken (-lcmmaxval was new in Netpbm 11.03 (June 2023)).
 
+              pamstack: Fail gracefully when total number of planes is too
+              large for unsigned integer.  Always broken (Pamstack was new in
+              Netpbm 10.0 (June 2002).
+
 23.06.28 BJH  Release 11.03.00
 
               pamstack: Add -firstmaxval, -lcmmaxval
diff --git a/other/pamstack.c b/other/pamstack.c
index 285e02c0..533795ca 100644
--- a/other/pamstack.c
+++ b/other/pamstack.c
@@ -242,6 +242,11 @@ processOneImageInAllStreams(unsigned int       const nInput,
         maxvalLcm = pm_lcm(maxvalLcm + 1, inpam[inputSeq].maxval + 1, 1,
                            PAM_OVERALL_MAXVAL + 1) - 1;
 
+        if (inpam[inputSeq].depth > UINT_MAX - outputDepth)
+            pm_error("Total number of planes is too large to compute "
+                     "(at least %u plus %u)",
+                     outputDepth, inpam[inputSeq].depth);
+
         outputDepth += inpam[inputSeq].depth;
     }