From 126505180f82557aacd4fc432ef4382abb18b473 Mon Sep 17 00:00:00 2001 From: xomx Date: Fri, 12 Apr 2024 00:24:49 +0200 Subject: [PATCH] Fix potential crash when crossing the 2GB file size threshold To be able to work with 2GB+ files, we have to use the Scintilla SC_DOCUMENTOPTION_TEXT_LARGE flag. Until now, this flag was only used if a file > 2GB was to be loaded. For files smaller than 2GB or newly created empty ones, it was not used. This left the room for a Notepad++ crash situation because of the user has been left the possibility to cross this threshold (e.g. by pasting a data which in sum with the already existing ones in the Notepad++ filebuffer exceeds that 2GB...) So one has two options: either a complex monitoring of the Notepad++ filebuffers size and reloading these with that large-flag when reaching the 2GB or simply using that large-flag as the default one from the start (which is what this patch does...). Fix #14981, close #14982 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 2b6d34740..7c7d5d058 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -728,8 +728,9 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding bool ownDoc = false; if (!doc) { - // If file exceeds 200MB, activate large file mode - doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT, 0, isLargeFile ? SC_DOCUMENTOPTION_STYLES_NONE | SC_DOCUMENTOPTION_TEXT_LARGE : 0); + // if file exceeds the _largeFileSizeDefInByte, disable the Scintilla styling (results in half memory consumption) + doc = static_cast(_pscratchTilla->execute(SCI_CREATEDOCUMENT, 0, + isLargeFile ? SC_DOCUMENTOPTION_STYLES_NONE | SC_DOCUMENTOPTION_TEXT_LARGE : SC_DOCUMENTOPTION_TEXT_LARGE)); ownDoc = true; } @@ -1354,7 +1355,7 @@ BufferID FileManager::newEmptyDocument() wsprintf(nb, TEXT("%d"), static_cast(nextUntitledNewNumber())); newTitle += nb; - Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager + Document doc = static_cast(_pscratchTilla->execute(SCI_CREATEDOCUMENT, 0, SC_DOCUMENTOPTION_TEXT_LARGE)); // this already sets a reference for filemanager Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle.c_str(), false); NppParameters& nppParamInst = NppParameters::getInstance();