about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-06-26 18:02:42 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-06-26 18:02:42 +0000
commitcd5163ed76bf0a04c2677149271095459bd1f4c8 (patch)
tree5ec561746e4dc3f22bccd96c1e0b67bf891c4f30
parentae38293b8fe84689fb9decc2c1b6e54f32057941 (diff)
downloadnetpbm-mirror-cd5163ed76bf0a04c2677149271095459bd1f4c8.tar.gz
netpbm-mirror-cd5163ed76bf0a04c2677149271095459bd1f4c8.tar.xz
netpbm-mirror-cd5163ed76bf0a04c2677149271095459bd1f4c8.zip
Release 10.47.62
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@2798 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY12
-rw-r--r--generator/pbmtextps.c101
-rw-r--r--other/pamarith.c10
-rw-r--r--version.mk2
4 files changed, 114 insertions, 11 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index bdc60af6..922f5584 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,18 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+16.06.26 BJH  Release 10.47.62
+
+              pamarith: fix incorrect output when maxvals differ, for
+              -add, -multiply, -mean, -min, -max.  Broken in Netpbm 10.41
+              (December 2007).
+
+              pbmtextps: Abort with error instead of generating single space
+              when user supplies no text.
+
+              pbmtextps: Fix bug: input text or font name with Postscript
+              control characters messes up the Postscript program.
+
 16.05.09 BJH  Release 10.47.61
 
               bmptopnm: fail properly with Version 4, 5 Windows BMP.
diff --git a/generator/pbmtextps.c b/generator/pbmtextps.c
index f879fa88..eab6780a 100644
--- a/generator/pbmtextps.c
+++ b/generator/pbmtextps.c
@@ -77,10 +77,73 @@ writeFileToStdout(const char * const fileName){
 
 
 static void
+validateFontName(const char * const name) {
+/*-----------------------------------------------------------------------------
+  Validate font name string.
+
+  Abort with error message if it contains anything other than the printable
+  characters in the ASCII 7-bit range, or any character with a special meaning
+  in PostScript.
+-----------------------------------------------------------------------------*/
+    unsigned int idx;
+
+    for (idx = 0; name[idx] != '\0'; ++idx) {
+        char const c = name[idx]; 
+
+        if (c < 32 || c > 125)
+            pm_error("Invalid character in font name");
+        else 
+            switch (c) {
+              case '[':   case ']':   case '(':   case ')':
+              case '{':   case '}':   case '/':   case '\\':
+              case '<':   case '>':   case '%':   case ' ':
+              case '@':
+                pm_error("Invalid character in font name");
+            }
+    }
+}
+
+
+
+static void
+asciiHexEncode(char *          const inbuff,
+               char *          const outbuff) {
+/*-----------------------------------------------------------------------------
+  Convert the input text string to ASCII-Hex encoding.
+
+  Examples: "ABC abc 123" -> <4142432061626320313233>
+            "FOO(BAR)FOO" -> <464f4f2842415229464f4f>
+-----------------------------------------------------------------------------*/
+    char const hexits[16] = "0123456789abcdef";
+
+    unsigned int idx;
+
+    for (idx = 0; inbuff[idx] != '\0'; ++idx) {
+        unsigned int const item = (unsigned char) inbuff[idx]; 
+
+        outbuff[idx*2]   = hexits[item >> 4];
+        outbuff[idx*2+1] = hexits[item & 0xF];
+    }
+
+    outbuff[idx * 2] = '\0';
+}
+
+
+
+static void
 buildTextFromArgs(int           const argc,
                   char **       const argv,
-                  const char ** const textP) {
-
+                  const char ** const asciiHexTextP) {
+/*----------------------------------------------------------------------------
+   Build the array of text to be included in the Postscript program to
+   be rendered, from the arguments of this program.
+
+   We encode it in ASCII-Hex notation as opposed to using the plain text from
+   the command line because 1) the command line might have Postscript control
+   characters in it; and 2) the command line might have text in 8-bit or
+   multibyte code, but a Postscript program is supposed to be entirely
+   printable ASCII characters.
+-----------------------------------------------------------------------------*/
     char * text;
     unsigned int totalTextSize;
     unsigned int i;
@@ -88,6 +151,9 @@ buildTextFromArgs(int           const argc,
     text = strdup("");
     totalTextSize = 1;
 
+    if (argc-1 < 1)
+        pm_error("No text");
+
     for (i = 1; i < argc; ++i) {
         if (i > 1) {
             totalTextSize += 1;
@@ -102,7 +168,20 @@ buildTextFromArgs(int           const argc,
             pm_error("out of memory");
         strcat(text, argv[i]);
     }
-    *textP = text;
+
+    { 
+        char * asciiHexText;
+
+        MALLOCARRAY(asciiHexText, totalTextSize * 2);
+
+        if (!asciiHexText)
+            pm_error("Unable to allocate memory for hex encoding of %u "
+                     "characters of text", totalTextSize);
+
+        asciiHexEncode(text, asciiHexText);
+        *asciiHexTextP = asciiHexText;
+    }
+    strfree(text);
 }
 
 
@@ -142,11 +221,21 @@ parseCommandLine(int argc, char ** argv,
 
     optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
 
+    validateFontName(cmdlineP->font);
+
     buildTextFromArgs(argc, argv, &cmdlineP->text);
 }
 
 
 
+static void
+termCmdline(struct cmdlineInfo const cmdline) {
+
+    strfree(cmdline.text);
+}
+
+
+
 static const char *
 construct_postscript(struct cmdlineInfo const cmdline) {
 
@@ -159,7 +248,7 @@ construct_postscript(struct cmdlineInfo const cmdline) {
             "%d scalefont\n"
             "setfont\n"
             "12 36 moveto\n"
-            "(%s) show\n"
+            "<%s> show\n"
             "showpage\n";
     else 
         template =
@@ -169,7 +258,7 @@ construct_postscript(struct cmdlineInfo const cmdline) {
             "12 36 moveto\n"
             "%f setlinewidth\n"
             "0 setgray\n"
-            "(%s) true charpath\n"
+            "<%s> true charpath\n"
             "stroke\n"
             "showpage\n";
 
@@ -445,5 +534,7 @@ main(int argc, char *argv[]) {
 
     createOutputFile(cmdline);
 
+    termCmdline(cmdline);
+
     return 0;
 }
diff --git a/other/pamarith.c b/other/pamarith.c
index 4374ee1c..3d29ac93 100644
--- a/other/pamarith.c
+++ b/other/pamarith.c
@@ -265,7 +265,7 @@ computeOutputType(struct pam *  const outpamP,
 
 
 
-static sample
+static samplen
 samplenSum(samplen      const operands[],
            unsigned int const operandCt) {
 
@@ -282,7 +282,7 @@ samplenSum(samplen      const operands[],
 
 
 
-static sample
+static samplen
 samplenMin(samplen      const operands[],
            unsigned int const operandCt) {
 
@@ -298,7 +298,7 @@ samplenMin(samplen      const operands[],
 
 
 
-static sample
+static samplen
 samplenMax(samplen      const operands[],
            unsigned int const operandCt) {
 
@@ -314,7 +314,7 @@ samplenMax(samplen      const operands[],
 
 
 
-static sample
+static samplen
 samplenMean(samplen      const operands[],
             unsigned int const operandCt) {
 
@@ -329,7 +329,7 @@ samplenMean(samplen      const operands[],
 
 
 
-static sample
+static samplen
 samplenProduct(samplen      const operands[],
                unsigned int const operandCt) {
 
diff --git a/version.mk b/version.mk
index 7b51e50e..3ce18f69 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 47
-NETPBM_POINT_RELEASE = 61
+NETPBM_POINT_RELEASE = 62