Commit 715e6e23b for imagemagick.org

commit 715e6e23b1e116710e53127355b2e7822a44701a
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Thu Dec 3 20:11:35 2026 -0500

    StringToUnsignedLong() negative input now returns 0

diff --git a/MagickCore/string-private.h b/MagickCore/string-private.h
index b861e4611..5ab4e44af 100644
--- a/MagickCore/string-private.h
+++ b/MagickCore/string-private.h
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "MagickCore/locale_.h"
+#include "MagickCore/string_.h"

 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
@@ -46,6 +47,8 @@ static inline int MagickSscanf(const char *buffer,const char *format,...)
     Custom implementation so we can use sscanf without defining
     _CRT_SECURE_NO_WARNINGS.
   */
+  if ((buffer == (const char *) NULL) || (format == (const char *) NULL))
+    return(EOF);
   va_start(args,format);
 #if defined(_MSC_VER)
   #pragma warning(push)
@@ -68,8 +71,11 @@ static inline double SiPrefixToDoubleInterval(const char *string,
   double
     value;

+  if (string == (const char *) NULL)
+    return(0.0);
+  q=(char *) NULL;
   value=InterpretSiPrefixValue(string,&q);
-  if (*q == '%')
+  if ((q != (char *) NULL) && (*q == '%'))
     value*=interval/100.0;
   return(value);
 }
@@ -135,8 +141,11 @@ static inline double StringToDoubleInterval(const char *string,
   double
     value;

+  if (string == (const char *) NULL)
+    return(0.0);
+  q=(char *) NULL;
   value=InterpretLocaleValue(string,&q);
-  if (*q == '%')
+  if ((q != (char *) NULL) && (*q == '%'))
     value*=interval/100.0;
   return(value);
 }
@@ -219,6 +228,19 @@ static inline unsigned long StringToUnsignedLong(
 {
   if (value == (const char *) NULL)
     return(0);
+  {
+    const char
+      *p;
+
+    /*
+      strtoul() silently wraps negative input to a huge value; treat it as 0.
+    */
+    p=value;
+    while (isspace((int) ((unsigned char) *p)) != 0)
+      p++;
+    if (*p == '-')
+      return(0);
+  }
   return(strtoul(value,(char **) NULL,10));
 }