AvalonEdit TextDocument crash reading large files

200 views Asked by At

I have an editor implemented using AvalonEdit, and when I open a new file I populate the Document with a new TextDocument, and populate that TextDocument with an IEnumerable<char>. That IEnumerable is just reading the file, char-by-char, from a stream.

We recently had it crash when opening a large file. Large meaning 600MB of plaintext. Don't ask, I think it's ridiculous, but it's necessary to be able to view files that big for our application. After a bunch of debugging, I found that the TextDocument constructor is crashing with an OutOfMemoryException, specicifically something where "Array dimensions exceeded supported range." Here's the relavent part of the stack trace:

System.OutOfMemoryException: Array dimensions exceeded supported range.
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at ICSharpCode.AvalonEdit.Utils.Rope`1.ToArray(IEnumerable`1 input)
   at ICSharpCode.AvalonEdit.Utils.Rope`1..ctor(IEnumerable`1 input)
   at ICSharpCode.AvalonEdit.Document.TextDocument..ctor(IEnumerable`1 initialText)
   ...

In my debugging I found that it happened consistently on the 134217728th character (2^27). That seems like an arbitrary limit, is there any reason that this would be a restriction? I'd expect the restriction of an array length to be int.MaxValue. It looks like it's something to do with the Rope creation, but I haven't been able to go into the Rope<T> source code yet.

0

There are 0 answers