Skip to content

Commit 8998e4f

Browse files
authored
Merge pull request #197 from ashawley/1e9lulz
Add billion laughs attack to test suite
2 parents bfc8957 + f78f8f6 commit 8998e4f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
5+
class BillionLaughsAttackTest {
6+
7+
/**
8+
* org.xml.sax.SAXParseException: JAXP00010001: The parser has
9+
* encountered more than "64000" entity expansions in this document;
10+
* this is the limit imposed by the JDK.
11+
*/
12+
@Test(expected=classOf[org.xml.sax.SAXParseException])
13+
def lolzTest: Unit = {
14+
XML.loadString(lolz)
15+
}
16+
17+
// Copied from https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
18+
val lolz =
19+
"""<?xml version="1.0"?>
20+
|<!DOCTYPE lolz [
21+
| <!ENTITY lol "lol">
22+
| <!ELEMENT lolz (#PCDATA)>
23+
| <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
24+
| <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
25+
| <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
26+
| <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
27+
| <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
28+
| <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
29+
| <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
30+
| <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
31+
| <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
32+
|]>
33+
|<lolz>&lol9;</lolz>
34+
|""".stripMargin
35+
36+
}

0 commit comments

Comments
 (0)