about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-04-24 00:55:00 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-04-24 00:55:00 +0000
commit5991a720c260e171c145d035014609f18cb2eaf3 (patch)
tree9fbe30f92ff0c7073e7737d078a460d7869124e8
parent55816e3b53d149a249fff96f262072da61e493dc (diff)
downloadnetpbm-mirror-5991a720c260e171c145d035014609f18cb2eaf3.tar.gz
netpbm-mirror-5991a720c260e171c145d035014609f18cb2eaf3.tar.xz
netpbm-mirror-5991a720c260e171c145d035014609f18cb2eaf3.zip
Release 10.98.02
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4327 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/pnmtopalm/palmtopnm.c57
-rw-r--r--doc/HISTORY7
-rw-r--r--version.mk2
3 files changed, 50 insertions, 16 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c
index a2c644b7..a64ab01c 100644
--- a/converter/other/pnmtopalm/palmtopnm.c
+++ b/converter/other/pnmtopalm/palmtopnm.c
@@ -821,28 +821,46 @@ readPackBitsRow16(FILE *          const ifP,
 
         Although the [...] spec is byte-oriented, the 16-bit algorithm is
         identical [to the 8-bit algorithm]: just substitute "word" for "byte".
+
+        A note about the 0x80 control byte value: There are some sources that
+        suggest that 1) no Palm file ever uses that value; and 2) a Palm
+        decoder should treat it as a no-op and other decoders do.  We don't
+        treat it as a no-op because we believe it is far more likely that if
+        someone _does_ put that value in a file, he means "repeat the next
+        word 129 times" than "do nothing."  Plus, it's just simpler and
+        cleaner.  Because of the ambiguity, though, anyone creating a Palm
+        file should avoid 0x80.
     */
     unsigned int j;
 
     for (j = 0;  j < bytesPerRow; ) {
-        unsigned char incountByte;
-        pm_readcharu(ifP, &incountByte);
-        if (incountByte & 0x80) {
-            int const signedIncount = (signed char)incountByte;
-            /* How do we handle incount == -128 ? */
-            unsigned int const runlength = (-signedIncount + 1) * 2;
-            unsigned int k;
+        unsigned char controlByte;
+        unsigned int  controlNum;
+
+        pm_readcharu(ifP, &controlByte);
+        controlNum = (unsigned int)controlByte;
+
+        if (controlNum >= 128) {
+            /* It's a run - output multiple copies of the next input word */
+            unsigned int const runlength = (257 - controlNum) * 2;
+
             unsigned short inval;
+
             pm_readlittleshortu(ifP, &inval);
+
             if (j + runlength <= bytesPerRow) {
+                unsigned int k;
                 for (k = 0; k < runlength; k += 2)
                     memcpy(palmrow + j + k, &inval, 2);
             }
             j += runlength;
         } else {
+            /* It's a nonrun - output the next words literally */
             /* We just read the stream of shorts as a stream of chars */
-            unsigned int const nonrunlength = (incountByte + 1) * 2;
+            unsigned int const nonrunlength = (controlNum + 1) * 2;
+
             unsigned int k;
+
             for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
@@ -866,23 +884,32 @@ readPackBitsRow(FILE *          const ifP,
                 unsigned char * const palmrow,
                 unsigned int    const bytesPerRow) {
 
+    /* See comments in 'readPackbitsRow16.  Everything here is the same
+       except with 1-byte words instead of 2-byte words.
+    */
     unsigned int j;
 
     for (j = 0;  j < bytesPerRow; ) {
-        unsigned char incountByte;
-        pm_readcharu(ifP, &incountByte);
-        if (incountByte & 0x80) {
-            /* How do we handle incount == -128 ? */
-            int const signedIncount = (char)incountByte;
-            unsigned int const runlength = -signedIncount + 1;
+        unsigned char controlByte;
+        unsigned int  controlNum;
+
+        pm_readcharu(ifP, &controlByte);
+        controlNum = controlByte;
+
+        if (controlNum >= 128) {
+            unsigned int const runlength = 257 - controlNum;
+
             unsigned char inval;
+
             pm_readcharu(ifP, &inval);
             if (j + runlength <= bytesPerRow)
                 memset(palmrow + j, inval, runlength);
             j += runlength;
         } else {
-            unsigned int const nonrunlength = incountByte + 1;
+            unsigned int const nonrunlength = controlNum + 1;
+
             unsigned int k;
+
             for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) {
                 unsigned char inval;
                 pm_readcharu(ifP, &inval);
diff --git a/doc/HISTORY b/doc/HISTORY
index 8900bf3f..b962fdad 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,13 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+22.04.24 BJH  Release 10.98.02
+
+              palmtopnm: Fix failure with bogus claim of invalid input on
+              architectures that do not use two's complement negative numbers.
+              Always broken.  (Ability to convert PackBits input was new in
+              Netpbm 10.27 (March 2005).
+
 22.04.10 BJH  Release 10.98.01
 
               pnmgamma -srgbtobt709, -bt709tosrgb: fix bug; incorrect output.
diff --git a/version.mk b/version.mk
index f5f37e74..36054e93 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 98
-NETPBM_POINT_RELEASE = 1
+NETPBM_POINT_RELEASE = 2