The vulnerability lies in the GetXMPProperty function in MagickCore/property.c. The function parses XMP metadata from an image file. During this process, it extracts property tags and stores them in a splay tree data structure associated with the image. The vulnerability occurs because the function would store a pointer to the property tag string in the splay tree, but the memory for this string was not correctly managed. The string could be freed or modified, leaving a dangling pointer in the splay tree. When this dangling pointer was later accessed (e.g., when printing properties), it would lead to a heap-use-after-free, causing a crash and creating a denial-of-service vulnerability, with a potential for arbitrary code execution.
The patch addresses this by changing how the property is stored. Instead of passing a potentially transient pointer to AddValueToSplayTree, the patched code now passes ConstantString(property), which creates a new, persistent copy of the string for the splay tree. Immediately after, property=DestroyString(property) is called to free the temporary local property string. This ensures that the splay tree has its own managed copy of the string, eliminating the use-after-free condition.