mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-10-21 22:02:37 +00:00
Windows: do not truncate files of 4 GiB or more in LoadFile
LoadFile read the file size with GetFileSize without its high-order part, so a file of 4 GiB or more was loaded as if it were only as large as its size modulo 4 GiB, without any error. Refuse such files with ERROR_FILE_TOO_LARGE instead.
This commit is contained in:
@@ -523,14 +523,18 @@ char *LoadFile (const wchar_t *fileName, DWORD *size)
|
||||
{
|
||||
char *buf;
|
||||
DWORD fileSize = INVALID_FILE_SIZE;
|
||||
DWORD fileSizeHigh = 0;
|
||||
HANDLE h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
*size = 0;
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
|
||||
if ((fileSize = GetFileSize (h, NULL)) == INVALID_FILE_SIZE)
|
||||
if ((fileSize = GetFileSize (h, &fileSizeHigh)) == INVALID_FILE_SIZE || fileSizeHigh != 0)
|
||||
{
|
||||
CloseHandle (h);
|
||||
// Refuse a file of 4 GiB or more, which would otherwise be truncated to its size modulo 4 GiB
|
||||
if (fileSizeHigh != 0)
|
||||
SetLastError (ERROR_FILE_TOO_LARGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user