Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions programs/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_
EXM_THROW(33, "Couldn't open dictionary %s: %s", fileName, strerror(errno));
}

// filesize could be garbage if UTIL_getFileSizeStat fails
fileSize = UTIL_getFileSizeStat(dictFileStat);
{
size_t const dictSizeMax = prefs->patchFromMode ? prefs->memLimit : DICTSIZE_MAX;
Expand All @@ -1049,6 +1050,11 @@ static size_t FIO_setDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_
}
}

if (fileSize == 0) return 0;
if (fileSize == (unsigned long long)-1) {
EXM_THROW(35, "Could not determine size of dictionary %s", fileName);
}
Comment on lines +1054 to +1056
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this check up to just after line 1044, because the flow should never reach here, due to the check on 1046.

And please also check against UTIL_FILESIZE_UNKNOWN rather than -1.


*bufferPtr = mmap(NULL, (size_t)fileSize, PROT_READ, MAP_PRIVATE, fileHandle, 0);
if (*bufferPtr==NULL) EXM_THROW(34, "%s", strerror(errno));

Expand Down