about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-10-23 16:18:38 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-10-23 16:18:38 +0000
commitb4c52e13c41dcf93022ce356f7a33cac096dad15 (patch)
tree3e9454c29f6c51fb3fc583e8a221f68959f2b286
parent763d2fb3f0f49e59c6aaeae20ae5b76591826989 (diff)
downloadnetpbm-mirror-b4c52e13c41dcf93022ce356f7a33cac096dad15.tar.gz
netpbm-mirror-b4c52e13c41dcf93022ce356f7a33cac096dad15.tar.xz
netpbm-mirror-b4c52e13c41dcf93022ce356f7a33cac096dad15.zip
Fix array bounds violation with PBM,PGM pnm_createBlackTuple
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@761 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY3
-rw-r--r--lib/libpam.c19
2 files changed, 8 insertions, 14 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 4d721d37..b6d2b8d7 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,9 @@ CHANGE HISTORY
 
 not yet  BJH  Release 10.45.00
 
+              pnm_createBlackTuple(): fix array bounds violation with
+              PBM, PGM.
+
               pnmtoddif: fix crash with any PGM input.
 
               pgmnoise: fix bug: never generates full white pixel.
diff --git a/lib/libpam.c b/lib/libpam.c
index 9e96029a..ab75fab6 100644
--- a/lib/libpam.c
+++ b/lib/libpam.c
@@ -195,21 +195,12 @@ pnm_createBlackTuple(const struct pam * const pamP,
    Create a "black" tuple.  By that we mean a tuple all of whose elements
    are zero.  If it's an RGB, grayscale, or b&w pixel, that means it's black.
 -----------------------------------------------------------------------------*/
+    unsigned int i;
+
     *blackTupleP = pnm_allocpamtuple(pamP);
-    if (pamP->format == PAM_FORMAT) {
-        /* In this format, we don't know the meaning of "black", so we
-           just punt.
-           */
-        int i;
-        for (i = 0; i < pamP->depth; i++) 
-            (*blackTupleP)[i] = 0;
-    } else {
-        xel black_xel;
-        black_xel = pnm_blackxel(pamP->maxval, pamP->format);
-        (*blackTupleP)[0] = PPM_GETR(black_xel);
-        (*blackTupleP)[1] = PPM_GETG(black_xel);
-        (*blackTupleP)[2] = PPM_GETB(black_xel);
-    }
+
+    for (i = 0; i < pamP->depth; ++i) 
+        (*blackTupleP)[i] = 0;
 }