about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--converter/other/pnmtopalm/palmtopnm.c11
-rw-r--r--doc/HISTORY4
2 files changed, 10 insertions, 5 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c
index 41fc50af..00aa35e4 100644
--- a/converter/other/pnmtopalm/palmtopnm.c
+++ b/converter/other/pnmtopalm/palmtopnm.c
@@ -820,15 +820,16 @@ readPackBitsRow16(FILE *          const ifP,
             unsigned int k;
             unsigned short inval;
             pm_readlittleshortu(ifP, &inval);
-            for (k = 0; (k < runlength) && (j + k + 1 < bytesPerRow); k += 2) {
-                memcpy(palmrow + j + k, &inval, 2);
+            if (j + runlength <= bytesPerRow) {
+                for (k = 0; k < runlength; k += 2)
+                    memcpy(palmrow + j + k, &inval, 2);
             }
             j += runlength;
         } else {
             /* We just read the stream of shorts as a stream of chars */
             unsigned int const nonrunlength = (incount + 1) * 2;
             unsigned int k;
-            for (k = 0; (k < nonrunlength) && (j + k < bytesPerRow); ++k) {
+            for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
                 palmrow[j + k] = inval;
@@ -860,13 +861,13 @@ readPackBitsRow(FILE *          const ifP,
             unsigned int const runlength = -incount + 1;
             unsigned char inval;
             pm_readcharu(ifP, &inval);
-            if (j + runlength < bytesPerRow) 
+            if (j + runlength <= bytesPerRow)
                 memset(palmrow + j, inval, runlength);
             j += runlength;
         } else {
             unsigned int const nonrunlength = incount + 1;
             unsigned int k;
-            for (k = 0; k < nonrunlength && j + k < bytesPerRow; ++k) {
+            for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
                 palmrow[j + k] = inval;
diff --git a/doc/HISTORY b/doc/HISTORY
index dbe4e1e0..1654c43c 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -16,6 +16,10 @@ not yet  BJH  Release 10.71.00
               image.  Introduced after Netpbm 10.26 (January 2005) but before
               Netpbm 10.35 (August 2006).
 
+              palmtopnm: Fix distorted output with PackBits compressed input.
+              Always broken (Ability to convert PackBits input was new in
+              Netpbm 10.27 (March 2005).
+
               pbmtoepson: fix -protocol option - never works and sometimes
               crashes program.  Always broken (-protocol was new in Netpbm
               10.23 (July 2004).