Details
Description
Serialization of a DOM tree containing unresolved XInclude elements with fallback causes an infinite loop when pretty printing is turned on. The output file written during the loop contains xml data followed by spaces (0x20). The infinite loop seems to occur in
xercesc_3_0::DOMLSSerializerImpl::printIndent (this=0x809fa30, level=4294967294)
at xercesc/dom/impl/DOMLSSerializerImpl.cpp:1625
1625 for(unsigned int i = 0; i < level; i++)
(gdb) print i
$1 = 10477649
unsigned int level seems to be initialized with "-1". The following program can be tried to reproduce the bug:
===example code===
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
XERCES_CPP_NAMESPACE_USE
int main()
{
XMLPlatformUtils::Initialize();
XMLCh utf_LS[] =
;
DOMImplementation * impl = DOMImplementationRegistry::getDOMImplementation(utf_LS);
DOMLSParser * parser = ((DOMImplementationLS*)impl)->createLSParser(
DOMImplementationLS::MODE_SYNCHRONOUS, 0
);
// otherwise the bug does not occur:
DOMConfiguration * config = parser->getDomConfig();
config->setParameter(XMLUni::fgXercesDoXInclude, true);
config->setParameter(XMLUni::fgDOMNamespaces, true);
DOMDocument * doc = parser->parseURI("mini.xml");
DOMLSSerializer * theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput * theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
// also a precondition for the bug:
config = theSerializer->getDomConfig();
config->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget * myFormatTarget = new LocalFileFormatTarget("out.xml");
theOutput->setByteStream(myFormatTarget);
theSerializer->write(doc, theOutput);
parser->release();
XMLPlatformUtils::Terminate();
return 0;
}
=================
Please use the following xml file for debugging. It's important that the included file does not exist so that the fallback elements are used:
===example data mini.xml===
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<mini>
<xi:include href="does-not-exist.xml" xmlns:xi="http://www.w3.org/2001/XInclude">
<!-- the bug requires a fallback element: -->
<xi:fallback xmlns:xi="http://www.w3.org/2001/XInclude">
<test/>
</xi:fallback>
</xi:include>
</mini>
================
Cheers, Michael