about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-03-28 18:38:54 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-03-28 18:38:54 +0000
commit15e39fc31e191cc020b21e3c6e682a2e2ae15f54 (patch)
treef97693986a6294a8ef291792a236e142fc4366b9
parent0003d7e73efc20c4b7b9e3de65954894368e8c2d (diff)
downloadnetpbm-mirror-15e39fc31e191cc020b21e3c6e682a2e2ae15f54.tar.gz
netpbm-mirror-15e39fc31e191cc020b21e3c6e682a2e2ae15f54.tar.xz
netpbm-mirror-15e39fc31e191cc020b21e3c6e682a2e2ae15f54.zip
Don't ignore garbage at the end of a color specifier
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4891 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY3
-rw-r--r--lib/libpamcolor.c51
-rw-r--r--lib/libppmcolor.c5
3 files changed, 40 insertions, 19 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index e1ff6a4f..f6602cc0 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -13,6 +13,9 @@ not yet  BJH  Release 11.06.00
               infotopam: Remove input file name from messages.  Add -verbose
               and issue informational message only if it is specified.
 
+              libnetpbm: Don't ignore garbage at the end of a color specifier
+              (e.g. rgbi:0/.5/1xyz).
+
               pamcut: fix incorrect output when rectangle to cut is entirely
               above the input image.  Invisible junk after image.  Always
               broken.  (The ability to cut outside the input image was new in
diff --git a/lib/libpamcolor.c b/lib/libpamcolor.c
index cc68fe1a..831057ab 100644
--- a/lib/libpamcolor.c
+++ b/lib/libpamcolor.c
@@ -130,21 +130,29 @@ isNormal(samplen const arg) {
 static void
 parseNewDecX11(const char * const colorname,
                tuplen       const color) {
-
+/*----------------------------------------------------------------------------
+   Return as *colorP the color specified by the new-style decimal specifier
+   colorname[] (e.g. "rgbi:0/.5/1").
+-----------------------------------------------------------------------------*/
+    char invalidExtra;
     int rc;
 
-    rc = sscanf(colorname, "rgbi:%f/%f/%f",
+    rc = sscanf(colorname, "rgbi:%f/%f/%f%c",
                 &color[PAM_RED_PLANE],
                 &color[PAM_GRN_PLANE],
-                &color[PAM_BLU_PLANE]);
+                &color[PAM_BLU_PLANE],
+                &invalidExtra);
 
     if (rc != 3)
-        pm_error("invalid color specifier '%s'", colorname);
+        pm_error("invalid rgbi: color specifier '%s' - "
+                 "does not have form rgbi:n/n/n "
+                 "(where n is floating point number)",
+                 colorname);
 
     if (!(isNormal(color[PAM_RED_PLANE]) &&
           isNormal(color[PAM_GRN_PLANE]) &&
           isNormal(color[PAM_BLU_PLANE]))) {
-        pm_error("invalid color specifier '%s' - "
+        pm_error("invalid rgbi: color specifier '%s' - "
                  "values must be between 0.0 and 1.0", colorname);
     }
 }
@@ -154,16 +162,21 @@ parseNewDecX11(const char * const colorname,
 static void
 parseInteger(const char * const colorname,
              tuplen       const color) {
-
+/*----------------------------------------------------------------------------
+   Return as *colorP the color specified by the integer specifier
+   colorname[] (e.g. "rgb-255/10/20/30").
+-----------------------------------------------------------------------------*/
     unsigned int maxval;
     unsigned int r, g, b;
+    char invalidExtra;
     int rc;
 
-    rc = sscanf(colorname, "rgb-%u:%u/%u/%u", &maxval, &r, &g, &b);
+    rc = sscanf(colorname, "rgb-%u:%u/%u/%u%c",
+                &maxval, &r, &g, &b, &invalidExtra);
 
     if (rc != 4)
-        pm_error("invalid color specifier '%s'.  "
-                 "If it starts with \"rgb-\", then it must have the format "
+        pm_error("invalid rgb- color specifier '%s' - "
+                 "Does not have form "
                  "rgb-<MAXVAL>:<RED>:<GRN>:<BLU>, "
                  "where <MAXVAL>, <RED>, <GRN>, and <BLU> are "
                  "unsigned integers",
@@ -200,7 +213,7 @@ parseOldX11(const char * const colorname,
             tuplen       const color) {
 /*----------------------------------------------------------------------------
    Return as *colorP the color specified by the old X11 style color
-   specififier colorname[] (e.g. #554055).
+   specifier colorname[] (e.g. #554055).
 -----------------------------------------------------------------------------*/
     if (!pm_strishex(&colorname[1]))
         pm_error("Non-hexadecimal characters in #-type color specification");
@@ -276,21 +289,29 @@ parseOldX11(const char * const colorname,
 static void
 parseOldX11Dec(const char* const colorname,
                tuplen      const color) {
-
+/*----------------------------------------------------------------------------
+   Return as *colorP the color specified by the old X11 style decimal color
+   specifier colorname[] (e.g. 0,.5,1).
+-----------------------------------------------------------------------------*/
+    char invalidExtra;
     int rc;
 
-    rc = sscanf(colorname, "%f,%f,%f",
+    rc = sscanf(colorname, "%f,%f,%f%c",
                 &color[PAM_RED_PLANE],
                 &color[PAM_GRN_PLANE],
-                &color[PAM_BLU_PLANE]);
+                &color[PAM_BLU_PLANE],
+                &invalidExtra);
 
     if (rc != 3)
-        pm_error("invalid color specifier '%s'", colorname);
+        pm_error("invalid old-style X11 decimal color specifier '%s' - "
+                 "does not have form n,n,n (where n is a floating point "
+                 "decimal number",
+                 colorname);
 
     if (!(isNormal(color[PAM_RED_PLANE]) &&
           isNormal(color[PAM_GRN_PLANE]) &&
           isNormal(color[PAM_BLU_PLANE]))) {
-        pm_error("invalid color specifier '%s' - "
+        pm_error("invalid old-style X11 decimal color specifier '%s' - "
                  "values must be between 0.0 and 1.0", colorname);
     }
 }
diff --git a/lib/libppmcolor.c b/lib/libppmcolor.c
index d6f00218..baa1d568 100644
--- a/lib/libppmcolor.c
+++ b/lib/libppmcolor.c
@@ -247,11 +247,8 @@ readOpenColorFile(FILE *          const colorFileP,
     unsigned int nColorsDone;
     bool done;
 
-    nColorsDone = 0;
-    done = false;
-    *errorP = NULL;
+    for (nColorsDone = 0, done = false, *errorP = NULL; !done && !*errorP; ) {
 
-    while (!done && !*errorP) {
         struct colorfile_entry const ce = pm_colorget(colorFileP);
 
         if (!ce.colorname)