mirror of
https://github.com/nmap/nmap.git
synced 2026-01-01 12:29:03 +00:00
Fix file size arithmetic on Win32. Closes #2306
The old code was incorrectly calculating sizes of files exceeding 4 GB. The new code skips the arithmetic altogether by using a different API.
This commit is contained in:
9
utils.cc
9
utils.cc
@@ -595,7 +595,7 @@ static HANDLE gmap = NULL;
|
||||
char *mmapfile(char *fname, s64 *length, int openflags) {
|
||||
HANDLE fd;
|
||||
DWORD mflags, oflags;
|
||||
DWORD lowsize, highsize;
|
||||
LARGE_INTEGER filesize;
|
||||
char *fileptr;
|
||||
|
||||
if (!length || !fname) {
|
||||
@@ -622,11 +622,10 @@ char *mmapfile(char *fname, s64 *length, int openflags) {
|
||||
if (!fd)
|
||||
pfatal ("%s(%u): CreateFile()", __FILE__, __LINE__);
|
||||
|
||||
lowsize = GetFileSize (fd, &highsize);
|
||||
if (lowsize == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) {
|
||||
pfatal("%s(%u): GetFileSize(), file '%s'", __FILE__, __LINE__, fname);
|
||||
if (!GetFileSizeEx(fd, &filesize)) {
|
||||
pfatal("%s(%u): GetFileSizeEx(), file '%s'", __FILE__, __LINE__, fname);
|
||||
}
|
||||
*length = lowsize + highsize << sizeof(DWORD);
|
||||
*length = (s64)filesize.QuadPart;
|
||||
if (*length < 0) {
|
||||
fatal("%s(%u): size too large, file '%s'", __FILE__, __LINE__, fname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user