Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-4339

XMLEventReader generates OutOfMemory Exception if XML file is not valid

    Details

      Description

      The XML-Pull parser does not handle invalid XML files very well.
      The attached file contains incomplete XML data. When running this file through the parser, a lot of 'char's are allocated and not freed anymore until there is no free memory left which leads to an OOM.
      The parser works very well with a complete, valid XML file of the same format and data.

      This might be related to ticket SI-3840

      You can easily reproduce the exception with the attached files:

      Welcome to Scala version 2.9.0.r24458-b20110315020117 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).
      Type in expressions to have them evaluated.
      Type :help for more information.
       
      scala> import scala.xml.pull.XMLEventReader
      import scala.xml.pull.XMLEventReader
       
      scala> import scala.io.Source
      import scala.io.Source
       
      scala> val parser = new XMLEventReader( Source.fromFile("intervals.SRER.xml.defect") )
      parser: scala.xml.pull.XMLEventReader = non-empty iterator
       
      scala> while (parser.hasNext) parser.next
      Exception in thread "XMLEventReader" java.lang.OutOfMemoryError: Java heap space
      	at java.util.Arrays.copyOf(Arrays.java:2882)
      	at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
      	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
      	at java.lang.StringBuilder.append(StringBuilder.java:203)
      	at scala.collection.mutable.StringBuilder.append(StringBuilder.scala:252)
      	at scala.xml.parsing.MarkupParserCommon$$class.xAttributeValue(MarkupParserCommon.scala:66)
      	at scala.xml.pull.XMLEventReader$$Parser.xAttributeValue(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParserCommon$$class.xAttributeValue(MarkupParserCommon.scala:74)
      	at scala.xml.pull.XMLEventReader$$Parser.xAttributeValue(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.xAttributes(MarkupParser.scala:294)
      	at scala.xml.pull.XMLEventReader$$Parser.xAttributes(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.mkAttributes(MarkupParser.scala:261)
      	at scala.xml.pull.XMLEventReader$$Parser.mkAttributes(XMLEventReader.scala:58)
      	at scala.xml.pull.XMLEventReader$$Parser.mkAttributes(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParserCommon$$class.xTag(MarkupParserCommon.scala:44)
      	at scala.xml.pull.XMLEventReader$$Parser.xTag(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.element1(MarkupParser.scala:528)
      	at scala.xml.pull.XMLEventReader$$Parser.element1(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.content1(MarkupParser.scala:396)
      	at scala.xml.pull.XMLEventReader$$Parser.content1(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.content(MarkupParser.scala:417)
      	at scala.xml.pull.XMLEventReader$$Parser.content(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.element1(MarkupParser.scala:542)
      	at scala.xml.pull.XMLEventReader$$Parser.element1(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.content1(MarkupParser.scala:396)
      	at scala.xml.pull.XMLEventReader$$Parser.content1(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.content(MarkupParser.scala:417)
      	at scala.xml.pull.XMLEventReader$$Parser.content(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.element1(MarkupParser.scala:542)
      	at scala.xml.pull.XMLEventReader$$Parser.element1(XMLEventReader.scala:58)
      	at scala.xml.parsing.MarkupParser$$class.content1(MarkupParser.scala:396)
      	at scala.xml.pull.XMLEventReader$$Parser.content1(XMLEventReader.scala:58)
      

      === Additional information ===
      Input file is attached to this ticket as bz2.

      === What versions of the following are you using? ===

      • Scala: 2.9.0.r24458-b20110315020117
      • Java: java version "1.6.0_24"
      • Operating system: Mac OS X 10.6

        Attachments

          Issue Links

            Activity

            Hide
            apm A. P. Marki added a comment -

            Coincidentally, just fixed by first commit in https://github.com/scala/scala-xml/pull/44

            Show
            apm A. P. Marki added a comment - Coincidentally, just fixed by first commit in https://github.com/scala/scala-xml/pull/44
            Hide
            apm A. P. Marki added a comment -

            This turned out not be very educational: https://github.com/scala/scala/pull/4221

            Show
            apm A. P. Marki added a comment - This turned out not be very educational: https://github.com/scala/scala/pull/4221

              People

              • Assignee:
                apm A. P. Marki
                Reporter:
                lukas.pustina Lukas Pustina
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: