Infinite loop during serialization when using xinclude with pretty printing and 
fallback elements
-------------------------------------------------------------------------------------------------

                 Key: XERCESC-1804
                 URL: https://issues.apache.org/jira/browse/XERCESC-1804
             Project: Xerces-C++
          Issue Type: Bug
          Components: XInclude
    Affects Versions: 3.0.0
         Environment: Debian GNU/Linux 4.0 (Etch), g++ (GCC) 4.1.2 20061115 
(prerelease) (Debian 4.1.1-21)
            Reporter: Michael Weitzel


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[] = { chLatin_L, chLatin_S, chNull };
        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


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to