From 7a503d160e779258c008106686d9a05175d8a75e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 10 Oct 2023 14:47:01 +1100 Subject: [PATCH] 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. --- source/blender/blenlib/intern/BLI_mmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/BLI_mmap.c b/source/blender/blenlib/intern/BLI_mmap.c index 42b04109e5b..fef40f9ee90 100644 --- a/source/blender/blenlib/intern/BLI_mmap.c +++ b/source/blender/blenlib/intern/BLI_mmap.c @@ -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. */