Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1804

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0
    • XInclude
    • None
    • Debian GNU/Linux 4.0 (Etch), g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

    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[] =

      { 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

      Attachments

        Activity

          People

            amassari Alberto Massari
            weitzel Michael Weitzel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified