Skip to content

Add billion laughs attack to test suite #197

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

Merged
merged 1 commit into from
Mar 19, 2018
Merged
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
36 changes: 36 additions & 0 deletions jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package scala.xml

import org.junit.Test

class BillionLaughsAttackTest {

/**
* org.xml.sax.SAXParseException: JAXP00010001: The parser has
* encountered more than "64000" entity expansions in this document;
* this is the limit imposed by the JDK.
*/
@Test(expected=classOf[org.xml.sax.SAXParseException])
def lolzTest: Unit = {
XML.loadString(lolz)
}

// Copied from https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
val lolz =
"""<?xml version="1.0"?>
|<!DOCTYPE lolz [
| <!ENTITY lol "lol">
| <!ELEMENT lolz (#PCDATA)>
| <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
| <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
| <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
| <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
| <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
| <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
| <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
| <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
| <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
|]>
|<lolz>&lol9;</lolz>
|""".stripMargin

}