1
0
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:
nnposter
2021-05-18 03:15:22 +00:00
parent 67a04de96a
commit c3d9d16744

View File

@@ -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);
}