Commit 099dda6c2 for imagemagick.org
commit 099dda6c2eb032e5d80e4842648ba42b9709905c
Author: Cristy <urban-warrior@imagemagick.org>
Date: Sun Mar 29 07:35:23 2026 -0400
throw exception for utf-8 string length of 0
diff --git a/MagickCore/xml-tree.c b/MagickCore/xml-tree.c
index 4850f851b..d062073e6 100644
--- a/MagickCore/xml-tree.c
+++ b/MagickCore/xml-tree.c
@@ -1913,14 +1913,16 @@ MagickExport XMLTreeInfo *NewXMLTree(const char *xml,ExceptionInfo *exception)
root=(XMLTreeRoot *) NewXMLTreeTag((char *) NULL);
length=strlen(xml);
utf8=ConvertUTF16ToUTF8(xml,&length);
- if (utf8 == (char *) NULL)
+ if ((utf8 == (char *) NULL) || (length == 0))
{
+ if (utf8 != (char *) NULL)
+ utf8=DestroyString(utf8);
(void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
"ParseError","UTF16 to UTF8 failed");
return((XMLTreeInfo *) NULL);
}
- terminal=utf8[MagickMax(length-1,0)];
- utf8[MagickMax(length-1,0)]='\0';
+ terminal=utf8[length-1];
+ utf8[length-1]='\0';
p=utf8;
while ((*p != '\0') && (*p != '<'))
p++;