diff options
author | Marti Maria <marti.maria@littlecms.com> | 2022-08-29 17:57:20 +0300 |
---|---|---|
committer | Marti Maria <marti.maria@littlecms.com> | 2022-08-29 17:57:20 +0300 |
commit | 6e929aacd463fecda095fad7489fd1c0056de343 (patch) | |
tree | 68b6da004bb08f9ccbad323416a6547f95b61d65 | |
parent | 4a3cedac2f8b5b12caa42fac992baad7343883ae (diff) |
A better checker for ascii to int conversion
People keeps trying to break tools helper code, so let's put guards.
-rw-r--r-- | src/cmscgats.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/cmscgats.c b/src/cmscgats.c index 1b96456..0c986e9 100644 --- a/src/cmscgats.c +++ b/src/cmscgats.c @@ -1528,7 +1528,7 @@ void AllocateDataFormat(cmsIT8* it8) if (t -> DataFormat) return; // Already allocated - t -> nSamples = (int) cmsIT8GetPropertyDbl(it8, "NUMBER_OF_FIELDS"); + t -> nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS")); if (t -> nSamples <= 0) { @@ -1586,8 +1586,15 @@ cmsBool CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE h, int n, const char *Sample) static cmsInt32Number satoi(const char* b) { + int n; + if (b == NULL) return 0; - return atoi(b); + + n = atoi(b); + if (n > 0x7fffffffL) return 0x7fffffffL; + if (n < -0x7ffffffeL) return -0x7ffffffeL; + + return (cmsInt32Number)n; } // Convert to binary |