Skip to content

Fix #35 OOM on malformed input #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/scala/xml/parsing/MarkupParserCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
*/
def xAttributeValue(endCh: Char): String = {
val buf = new StringBuilder
while (ch != endCh) {
while (ch != endCh && !eof) {
// well-formedness constraint
if (ch == '<') return errorAndResult("'<' not allowed in attrib value", "")
else if (ch == SU) truncatedError("")
Expand Down
6 changes: 6 additions & 0 deletions src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,12 @@ expected closing tag of foo
assertEquals("""<x:foo xmlns:x="gaga"/>""", pp.format(x))
}

@UnitTest( expected = classOf[scala.xml.SAXParseException] )
def issue35: Unit = {
val broken = "<broken attribute='is truncated"
XML.loadString(broken)
}

@UnitTest
def nodeSeqNs: Unit = {
val x = {
Expand Down
14 changes: 13 additions & 1 deletion src/test/scala/scala/xml/pull/XMLEventReaderTest.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package scala.xml.pull
package scala.xml
package pull

import org.junit.Test
import org.junit.Ignore
Expand Down Expand Up @@ -40,6 +41,17 @@ class XMLEventReaderTest {
er.stop // allow thread to be garbage-collected
}

@Test
def issue35: Unit = {
val broken = "<broken attribute='is truncated"
val x = new Source {
val iter = broken.iterator
override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) {}
}
val r = new XMLEventReader(x)
assertTrue(r.next.isInstanceOf[EvElemStart])
}

@Test(expected = classOf[Exception])
def missingTagTest: Unit = {
val data=
Expand Down