Index: ImageMagick-6.8.8-1/magick/xml-tree.c
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/xml-tree.c
+++ ImageMagick-6.8.8-1/magick/xml-tree.c
@@ -516,16 +516,19 @@ static void DestroyXMLTreeRoot(XMLTreeIn
     }
 }
 
-MagickExport XMLTreeInfo *DestroyXMLTree(XMLTreeInfo *xml_info)
+MagickExport XMLTreeInfo *DestroyXMLTree_(XMLTreeInfo *xml_info, const size_t depth)
 {
   assert(xml_info != (XMLTreeInfo *) NULL);
   assert((xml_info->signature == MagickSignature) ||
          (((XMLTreeRoot *) xml_info)->signature == MagickSignature));
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (xml_info->child != (XMLTreeInfo *) NULL)
-    xml_info->child=DestroyXMLTree(xml_info->child);
+    xml_info->child=DestroyXMLTree_(xml_info->child, depth+1);
   if (xml_info->ordered != (XMLTreeInfo *) NULL)
-    xml_info->ordered=DestroyXMLTree(xml_info->ordered);
+    xml_info->ordered=DestroyXMLTree_(xml_info->ordered, depth+1);
+  if (depth > MagickMaxRecursionDepth)
+    ThrowFatalException(ResourceLimitFatalError,
+      "MemoryAllocationFailed");
   DestroyXMLTreeRoot(xml_info);
   xml_info->attributes=DestroyXMLTreeAttributes(xml_info->attributes);
   xml_info->content=DestroyString(xml_info->content);
@@ -533,6 +536,12 @@ MagickExport XMLTreeInfo *DestroyXMLTree
   xml_info=(XMLTreeInfo *) RelinquishMagickMemory(xml_info);
   return((XMLTreeInfo *) NULL);
 }
+
+MagickExport XMLTreeInfo *DestroyXMLTree(XMLTreeInfo *xml_info)
+{
+  return(DestroyXMLTree_(xml_info,0));
+}
+
 
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
