From db3308329bd23a073b7de6f4ded2a523b282fcc3 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 28 Jan 2022 04:17:45 +0100 Subject: [PATCH] Fix crash on opening file with wild card characters And redefining Sci_PositionCR to 64 bits on x64 build for managing 2GB+ files. (ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/11047#issuecomment-1021540298) Fix #11098 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 20 ++++++++++++------- scintilla/include/Sci_Position.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index f9c04a89e..a6da5caa8 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -643,16 +643,22 @@ void FileManager::closeBuffer(BufferID id, ScintillaEditView * identifier) BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding, const TCHAR* backupFileName, FILETIME fileNameTimestamp) { //Get file size + int64_t fileSize = -1; const TCHAR* pPath = filename; if (!::PathFileExists(pPath)) + { pPath = backupFileName; - FILE* fp = generic_fopen(pPath, TEXT("rb")); - if (!fp) - return BUFFER_INVALID; - - _fseeki64(fp, 0, SEEK_END); - int64_t fileSize = _ftelli64(fp); - fclose(fp); + } + if (pPath) + { + FILE* fp = generic_fopen(pPath, TEXT("rb")); + if (fp) + { + _fseeki64(fp, 0, SEEK_END); + fileSize = _ftelli64(fp); + fclose(fp); + } + } // * the auto-completion feature will be disabled for large files // * the session snapshotsand periodic backups feature will be disabled for large files diff --git a/scintilla/include/Sci_Position.h b/scintilla/include/Sci_Position.h index b979bd0be..bad91b449 100644 --- a/scintilla/include/Sci_Position.h +++ b/scintilla/include/Sci_Position.h @@ -20,7 +20,7 @@ typedef size_t Sci_PositionU; // For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE -typedef long Sci_PositionCR; +typedef intptr_t Sci_PositionCR; #ifdef _WIN32 #define SCI_METHOD __stdcall