Ace: XML mode memory leak crash

Created on 14 Aug 2018  路  4Comments  路  Source: ajaxorg/ace

Typing a certain sequence of characters in XML mode results in a memory leak/infinite loop which eventually crashes the page. To reproduce:

  1. Go to https://ace.c9.io/build/kitchen-sink.html
  2. Set the mode to XML
  3. Delete the document's contents
  4. Paste the following: <A><![CDATA[</A>
  5. Watch the memory tab of Chrome Debugger to see the memory leak. The page will soon crash (it takes me about 45 seconds).

This bug is present in the current version of Ace, and at least as far back as Ace 1.2.3.
Crashes on Windows 7 and 10, in Chrome.

Most helpful comment

Just for the record, there is other content that triggers the same memory leak. Go to https://ace.c9.io/build/kitchen-sink.html and switch to XML mode. Somewhere in the middle, type <?p. After a couple of seconds, the browser crashes. Safari, Chrome, FF - all the same.

All 4 comments

I've identified the issue as this line: https://github.com/ajaxorg/ace/blob/dbdf8aaad697e2ded8fd69249b72a7e898583afa/lib/ace/mode/xml/sax.js#L479

end is equal to -1 because the string "]]>" doesn't exist. This causes the return value to be 2, causing an infinite loop. I am relatively unfamiliar with Ace editor. I found a simple solution:

var end = source.indexOf(']]>',start+9);
if (end < 0) {
  return -1;
}

A small problem is that the document will stop tokenizing after the broken CDATA[ string so we lose syntax highlighting. It would be nice if we could somehow keep the syntax highlighting.

the sax.js is a third party library that is used for linting, it should not affect syntax highlighting.
Considering the amount of bugs you found in it, i wonder if we should switch to something else, e.g. https://www.npmjs.com/package/xmlchecker or http://syssgx.github.io/xml.js/

Another alternative might be https://github.com/lddubeau/saxes
Looks like it might address a number of the open xml bugs

An issue for me is the current xml mode linting is validating for an xml fragment not a xml document.
E.g.
just some text
and
<foo/><foo/>
are considered valid xml. Is this by design?

I put together a repl page to show saxes in action
https://repl.it/@apb2006/xml-parser-saxes-test

Just for the record, there is other content that triggers the same memory leak. Go to https://ace.c9.io/build/kitchen-sink.html and switch to XML mode. Somewhere in the middle, type <?p. After a couple of seconds, the browser crashes. Safari, Chrome, FF - all the same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christianbs picture christianbs  路  3Comments

xfix picture xfix  路  5Comments

vbguyny picture vbguyny  路  5Comments

SuperSajuuk picture SuperSajuuk  路  4Comments

mafar picture mafar  路  4Comments