Commit 0fbd8215f for imagemagick.org
commit 0fbd8215fe5890e8b8396dad4df61074ebd0f227
Author: Cristy <urban-warrior@imagemagick.org>
Date: Sat Mar 14 12:06:35 2026 -0400
https://github.com/ImageMagick/ImageMagick/discussions/5807
diff --git a/MagickCore/property.c b/MagickCore/property.c
index 47f44a3e3..90046aded 100644
--- a/MagickCore/property.c
+++ b/MagickCore/property.c
@@ -596,8 +596,9 @@ static void Get8BIMProperty(const Image *image,const char *key,
char
*attribute,
format[MagickPathExtent],
+ *macroman_resource = (char *) NULL,
name[MagickPathExtent],
- *resource;
+ *resource = (char *) NULL;
const StringInfo
*profile;
@@ -639,7 +640,6 @@ static void Get8BIMProperty(const Image *image,const char *key,
if (*name == '#')
sub_number=(ssize_t) StringToLong(&name[1]);
sub_number=MagickMax(sub_number,1L);
- resource=(char *) NULL;
status=MagickFalse;
length=GetStringInfoLength(profile);
info=GetStringInfoDatum(profile);
@@ -658,6 +658,8 @@ static void Get8BIMProperty(const Image *image,const char *key,
continue;
if (id > (ssize_t) stop)
continue;
+ if (macroman_resource != (char *) NULL)
+ macroman_resource=DestroyString(macroman_resource);
if (resource != (char *) NULL)
resource=DestroyString(resource);
count=(ssize_t) ReadPropertyByte(&info,&length);
@@ -682,8 +684,12 @@ static void Get8BIMProperty(const Image *image,const char *key,
length=0;
continue;
}
+ macroman_resource=(char *) ConvertMacRomanToUTF8((unsigned char *)
+ resource);
if ((*name != '\0') && (*name != '#'))
- if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
+ if ((resource == (char *) NULL) || (macroman_resource == (char *) NULL) ||
+ ((LocaleCompare(name,resource) != 0) &&
+ (LocaleCompare(name,macroman_resource) != 0)))
{
/*
No name match, scroll forward and try next.
@@ -736,6 +742,8 @@ static void Get8BIMProperty(const Image *image,const char *key,
status=MagickTrue;
}
}
+ if (macroman_resource != (char *) NULL)
+ macroman_resource=DestroyString(macroman_resource);
if (resource != (char *) NULL)
resource=DestroyString(resource);
}
diff --git a/MagickCore/token-private.h b/MagickCore/token-private.h
index 3ab1d7ecb..ebf851aa3 100644
--- a/MagickCore/token-private.h
+++ b/MagickCore/token-private.h
@@ -60,13 +60,11 @@ static inline unsigned char *ConvertLatin1ToUTF8(
const unsigned char
*magick_restrict p;
- unsigned char
- *magick_restrict q;
-
size_t
length;
unsigned char
+ *magick_restrict q,
*utf8;
length=0;
@@ -93,6 +91,82 @@ static inline unsigned char *ConvertLatin1ToUTF8(
return(utf8);
}
+static inline unsigned char *ConvertMacRomanToUTF8(
+ const unsigned char *magick_restrict content)
+{
+ static const uint16_t macroman_unicode[128] = {
+ 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
+ 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
+ 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
+ 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
+ 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
+ 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
+ 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
+ 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
+ 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
+ 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
+ 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
+ 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
+ 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
+ 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
+ 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
+ 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7
+ };
+
+ int
+ c;
+
+ const unsigned char
+ *magick_restrict p;
+
+ size_t
+ length;
+
+ unsigned char
+ *magick_restrict q,
+ *utf8;
+
+ length=0;
+ for (p=content; *p != '\0'; p++)
+ length+=(*p & 0x80) != 0 ? 4 : 1;
+ utf8=(unsigned char *) NULL;
+ if (~length >= 1)
+ utf8=(unsigned char *) AcquireQuantumMemory(length+1UL,sizeof(*utf8));
+ if (utf8 == (unsigned char *) NULL)
+ return((unsigned char *) NULL);
+ q=utf8;
+ for (p=content; *p != '\0'; p++)
+ {
+ c=(*p);
+ if (c > 128)
+ c=macroman_unicode[c-128];
+ if ((c & 0x80) == 0)
+ *q++=(unsigned char) c;
+ else
+ if (c <= 0x7ff)
+ {
+ *q++=(unsigned char) (0xc0 | ((c >> 6) & 0x3f));
+ *q++=(unsigned char) (0x80 | (c & 0x3f));
+ }
+ else
+ if (c <= 0xffff)
+ {
+ *q++=(unsigned char) (0xe0 | (c >> 12));
+ *q++=(unsigned char) (0x80 | ((c >> 6) & 0x3f));
+ *q++=(unsigned char) (0x80 | (c & 0x3f));
+ }
+ else
+ {
+ *q++=(unsigned char) (0xf0 | (c >> 18));
+ *q++=(unsigned char) (0x80 | ((c >> 12) & 0x3f));
+ *q++=(unsigned char) (0x80 | ((c >> 6) & 0x3f));
+ *q++=(unsigned char) (0x80 | (c & 0x3f));
+ }
+ }
+ *q='\0';
+ return(utf8);
+}
+
static inline int GetNextUTFCode(const char *magick_restrict text,
unsigned int *magick_restrict octets)
{