From 6b7a1ddc5d4573b25a61ad232c38b92d4980c03d Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 8 Jul 2017 22:12:06 +0000 Subject: Fix parsing of rgb:hh/hh/hh color specification git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3028 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpamcolor.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/libpamcolor.c') diff --git a/lib/libpamcolor.c b/lib/libpamcolor.c index 120a82cf..336dcd6b 100644 --- a/lib/libpamcolor.c +++ b/lib/libpamcolor.c @@ -68,23 +68,28 @@ parseHexDigits(const char * const string, unsigned int digitCt; unsigned long n; - unsigned long maxval; + unsigned long range; + /* 16 for one hex digit, 256 for two hex digits, etc. */ - for (digitCt = 0, n = 0, maxval = 1; string[digitCt] != delim; ) { + for (digitCt = 0, n = 0, range = 1; string[digitCt] != delim; ) { char const digit = string[digitCt]; if (digit == '\0') - pm_error("rgb: color spec ends prematurely"); + pm_error("rgb: color spec '%s' ends prematurely", string); else { int const hexval = hexit[(unsigned int)digit]; if (hexval == -1) pm_error("Invalid hex digit in rgb: color spec: 0x%02x", digit); n = n * 16 + hexval; - maxval *= 16; + range *= 16; ++digitCt; } } - *nP = (samplen) n / maxval; + if (range <= 1) + pm_error("No digits where hexadecimal number expected in rgb: " + "color spec '%s'", string); + + *nP = (samplen) n / (range-1); *digitCtP = digitCt; } -- cgit 1.4.1