Skip to content
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

XML mode memory leak crash #3747

Open
featurecat opened this issue Aug 14, 2018 · 6 comments
Open

XML mode memory leak crash #3747

featurecat opened this issue Aug 14, 2018 · 6 comments

Comments

@featurecat
Copy link

featurecat commented Aug 14, 2018

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.

@featurecat
Copy link
Author

featurecat commented Aug 15, 2018

I've identified the issue as this line:

var end = source.indexOf(']]>',start+9);

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.

@nightwing
Copy link
Member

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 https://syssgx.github.io/xml.js/

@apb2006
Copy link

apb2006 commented Mar 8, 2019

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

@frankarensmeier
Copy link

frankarensmeier commented Mar 21, 2019

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.

@github-actions
Copy link

github-actions bot commented May 9, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@whazor
Copy link
Contributor

whazor commented Jul 29, 2024

This is a problem in ace/lib/ace/mode/xml, you can stop using this language mode, and switch to Ace-linters from @mkslanc for XML support. Ace-linters has a xml-service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants