about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2017-09-13 15:44:23 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2017-09-13 15:44:23 +0000
commit49278c23f0148f2fe0a3a93bd33b4af71bfafe53 (patch)
tree95abcd38fb37163561b16b9152469e12153c977b
parented5ec3e8c54828469310d3311dee741cac51b059 (diff)
downloadnetpbm-mirror-49278c23f0148f2fe0a3a93bd33b4af71bfafe53.tar.gz
netpbm-mirror-49278c23f0148f2fe0a3a93bd33b4af71bfafe53.tar.xz
netpbm-mirror-49278c23f0148f2fe0a3a93bd33b4af71bfafe53.zip
Release 10.73.15
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3059 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/ipdb.c2
-rw-r--r--converter/other/pnmtopalm/palmtopnm.c11
-rw-r--r--converter/other/pnmtopalm/pnmtopalm.c114
-rw-r--r--doc/HISTORY13
-rw-r--r--version.mk2
5 files changed, 52 insertions, 90 deletions
diff --git a/converter/other/ipdb.c b/converter/other/ipdb.c
index d6bd6ef5..7ee37872 100644
--- a/converter/other/ipdb.c
+++ b/converter/other/ipdb.c
@@ -283,7 +283,7 @@ ipdb_image_alloc(const char * const name,
                 MALLOCARRAY(imgP->data, w * h);
 
                 if (imgP->data) {
-                    MEMSZERO(imgP->data);
+                    memset(imgP->data, 0, sizeof(*(imgP->data)) * w * h);
                 } else
                     failed = true;
             }
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c
index 00aa35e4..0f76207d 100644
--- a/converter/other/pnmtopalm/palmtopnm.c
+++ b/converter/other/pnmtopalm/palmtopnm.c
@@ -688,6 +688,11 @@ doTransparent(FILE *                 const ofP,
                                                colormap->ncolors,
                                                sizeof(color), 
                                                palmcolor_compare_indices));
+            if (!actualColor)
+                pm_error("Invalid input; transparent index %u "
+                         "is not among the %u colors in the image's colormap",
+                         transparentIndex, colormap->ncolors);
+
             fprintf(ofP, "#%02x%02x%02x\n", 
                    (unsigned int) ((*actualColor >> 16) & 0xFF),
                    (unsigned int) ((*actualColor >>  8) & 0xFF), 
@@ -1020,6 +1025,12 @@ convertRowToPnmNotDirect(const unsigned char * const palmrow,
                                                   colormap->ncolors,
                                                   sizeof(color2), 
                                                   palmcolor_compare_indices));
+            if (!actualColor)
+                pm_error("Invalid input.  A color index in column %u "
+                         "is %u, which is not among the %u colors "
+                         "in the colormap",
+                         j, color, colormap->ncolors);
+
             PPM_ASSIGN(xelrow[j], 
                        (*actualColor >> 16) & 0xFF, 
                        (*actualColor >>  8) & 0xFF, 
diff --git a/converter/other/pnmtopalm/pnmtopalm.c b/converter/other/pnmtopalm/pnmtopalm.c
index 6e290777..a7d1fd46 100644
--- a/converter/other/pnmtopalm/pnmtopalm.c
+++ b/converter/other/pnmtopalm/pnmtopalm.c
@@ -13,7 +13,13 @@
  *
  * See LICENSE file for licensing information.
  *
- *  
+ * References for the Palm Bitmap format:
+ *
+ * https://web.archive.org/web/20030621112139/http://www.palmos.com:80/dev/support/docs/
+ * https://web.archive.org/web/20030413080018/http://www.palmos.com:80/dev/support/docs/palmos/ReferenceTOC.html
+ *
+ * http://www.trantor.de/kawt/doc/palmimages.html
+ * (above retrieved August 2017)
  */
 
 #include <string.h>
@@ -26,6 +32,7 @@
 #include "palm.h"
 #include "shhopt.h"
 #include "mallocvar.h"
+#include "runlength.h"
 
 enum compressionType {COMP_NONE, COMP_SCANLINE, COMP_RLE, COMP_PACKBITS};
 
@@ -835,79 +842,6 @@ rleCompressAndBufferRow(const unsigned char * const rowdata,
 
 
 
-/* FIXME Incorrect for images with pixelSize == 16 */
-static void
-computeNextPackbitsRun(const unsigned char * const rowdata,
-                       unsigned int          const rowbytes,
-                       unsigned int          const startPos,
-                       unsigned int *        const nextPosP,
-                       unsigned char *       const output,
-                       int *                 const countP) {
-
-    unsigned int pos;
-    int count;
-    
-    pos = startPos;
-    count = 0;
-    
-    if (rowdata[pos] == rowdata[pos + 1]) {
-        ++pos;
-        --count;
-        while ((count > -127) && (pos < (rowbytes - 1)) &&
-               (rowdata[pos] == rowdata[pos + 1])) {
-            ++pos;
-            --count;
-        }
-        ++pos;  /* push pos past end of this run */
-    } else {
-        output[count] = rowdata[pos];
-        ++pos;
-        while ((count < 127) && (pos < (rowbytes - 1)) && 
-               (rowdata[pos] != rowdata[pos + 1])) {
-            ++count;
-            output[count] = rowdata[pos];
-            ++pos;
-        }
-        /* trailing literal */
-        if ((count < 127) && (pos == (rowbytes - 1)) &&
-            (rowdata[pos - 1] != rowdata[pos])) {
-            ++count;
-            output[count] = rowdata[pos];
-            ++pos;
-        }
-    }
-    *nextPosP = pos;
-    *countP = count;
-}
-
-
-
-static void
-addPackbitsRunToBuffer(const unsigned char * const rowdata,
-                       unsigned int          const rowbytes,
-                       unsigned int          const pos,
-                       unsigned char *       const output,
-                       int                   const count,
-                       struct seqBuffer *    const rasterBufferP) {
-
-    addByteToBuffer(rasterBufferP, (unsigned char)(signed char)count);
-    if (count < 0) {
-        addByteToBuffer(rasterBufferP, rowdata[pos - 1]);
-    } else {
-        unsigned int j;
-        for (j = 0; j <= count; j++)
-            addByteToBuffer(rasterBufferP, output[j]);
-    }
-    
-    if (pos == (rowbytes - 1) && (rowdata[pos - 1] != rowdata[pos])) {
-        /* orphaned byte, treat as literal */
-        addByteToBuffer(rasterBufferP, 0);
-        addByteToBuffer(rasterBufferP, rowdata[pos]);
-    }
-}
-
-
-
 static void
 packbitsCompressAndBufferRow(const unsigned char * const rowdata,
                              unsigned int          const rowbytes,
@@ -917,21 +851,18 @@ packbitsCompressAndBufferRow(const unsigned char * const rowdata,
    add the packbits-compressed representation of it to the buffer 
    with handle 'rasterBufferP'.
 -----------------------------------------------------------------------------*/
-    unsigned int position;
-        /* byte position within the row */
-
-    position = 0;  /* Start at beginning of row */
+    unsigned char * compressedData;
+    size_t          compressedDataCt;
+    unsigned int    byteCt;
 
-    while (position < rowbytes - 1) {
-        unsigned char output[128];
-        int count;
+    pm_rlenc_allocoutbuf(&compressedData, rowbytes, PM_RLE_PACKBITS);
+    pm_rlenc_compressbyte(rowdata, compressedData, PM_RLE_PACKBITS,
+                          rowbytes, &compressedDataCt);
 
-        computeNextPackbitsRun(rowdata, rowbytes, position, 
-                               &position, output, &count);
+    for (byteCt = 0; byteCt < compressedDataCt; ++byteCt)
+        addByteToBuffer(rasterBufferP, compressedData[byteCt]);
 
-        addPackbitsRunToBuffer(rowdata, rowbytes, position, output, count,
-                               rasterBufferP);
-    }
+    free(compressedData);
 }
 
 
@@ -1028,7 +959,13 @@ bufferRaster(xel **               const xels,
     createBuffer(rasterBufferPP);
     
     MALLOCARRAY_NOFAIL(rowdata, rowbytes);
-    MALLOCARRAY_NOFAIL(lastrow, rowbytes);
+    if (compression == COMP_SCANLINE)
+        MALLOCARRAY_NOFAIL(lastrow, rowbytes);
+    else
+        lastrow = NULL;
+
+    /* clear pad bytes to suppress valgrind error */
+    rowdata[rowbytes - 1] = rowdata[rowbytes - 2] = 0x00;
 
     /* And write out the data. */
     for (row = 0; row < rows; ++row) {
@@ -1040,8 +977,9 @@ bufferRaster(xel **               const xels,
         if (compression == COMP_SCANLINE)
             memcpy(lastrow, rowdata, rowbytes);
     }
-    free(lastrow);
     free(rowdata);
+    if (compression == COMP_SCANLINE)
+        free(lastrow);
 }
 
 
diff --git a/doc/HISTORY b/doc/HISTORY
index bbf0ff26..35f67898 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,19 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+17.09.13 BJH  Release 10.73.15
+
+              palmtopnm: fix crash if invalid input contains color index that
+              is not in the palette.  Always broken (palmtopnm was new in
+              Netpbm 9.10 (October 2001)).
+
+              pnmtopalm: fix incorrect output with certain input files and
+              -packbits_compression.  Always broken.  -packbits_compression
+              was new in Netpbm 10.27 (March 2005).
+
+              pamtopdbimg: Fix incorrect output. Always broken (pamtopdbimg
+              was new in Netpbm 10.52.00 (October 2010)).
+
 17.08.11 BJH  Release 10.73.14
 
               libnetpbm: font facilities: fix invalid memory reference with
diff --git a/version.mk b/version.mk
index bb8a30b4..bf79c62b 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 73
-NETPBM_POINT_RELEASE = 14
+NETPBM_POINT_RELEASE = 15