Fix crash when opening a large one-line file (500MB) on 32-bit, and improve loading time #329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
32-bit Notepad++ crashes when opening large one-line files.
Example issue: notepad-plus-plus/notepad-plus-plus#11427
Steps to reproduce problem:
Take the file from notepad-plus-plus/notepad-plus-plus#10407 (comment)
Duplicate it's contents on the same line until you have a 500 MB file.
Try to open it on 32-bit N++. It should crash.
Problem in code:
Calling get_mapped_wstring_range for the entire 500MB line, results in placing 500MB in one single buffer. With 32-bit, this crashes. With 64-bit, it's very slow.
Proposed fix:
Merged and modified get_visible_text and underline_misspelled_words
Doesn't get the entire line at once, instead it now works in blocks of 4096 characters
Takes into account visible lines, horizontal scroll, and the end of the visible text in a line
Changed is_word_under_cursor_correct to check prev token and next token from the current position instead of using the entire line
Also added a protection for when the document isn't loaded by N++
Result of fix:
No crash, and a loading time of around 30 seconds in Debug. N++ might not render the file, but at least it's not crashing.
Worked on this a month ago, and ended up leaving it on the side when I started looking at other functions that are taking too much into memory, and which also crash (or throw a "bad allocation" exception):
erase_all_misspellings
get_all_misspellings_as_string
mark_lines_with_misspelling
Don't think I'll have time to work on them, though.