BLI_mmap: open now checks for seek failing & exists early

Failure to seek would attempt to MMAP SIZE_T_MAX, while this would
likely fail, prefer an explicit error check instead of relying on
unreasonable requests to be rejected.
This commit is contained in:
Campbell Barton
2023-10-10 14:47:01 +11:00
parent ae6b1ead4c
commit 7a503d160e

View File

@@ -132,7 +132,10 @@ static void sigbus_handler_remove(BLI_mmap_file *file)
BLI_mmap_file *BLI_mmap_open(int fd)
{
void *memory, *handle = NULL;
size_t length = BLI_lseek(fd, 0, SEEK_END);
const size_t length = BLI_lseek(fd, 0, SEEK_END);
if (UNLIKELY(length == (size_t)-1)) {
return NULL;
}
#ifndef WIN32
/* Ensure that the SIGBUS handler is configured. */