From 7a384edeb08fe523bb2af8505c2fcd81c1bcf45c Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 26 Nov 2019 13:26:31 +0100 Subject: [PATCH] src: Check the filesize before calling `mmap()` --- src/file.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/file.cc b/src/file.cc index c1f5bb26..fb282a14 100644 --- a/src/file.cc +++ b/src/file.cc @@ -217,13 +217,12 @@ MappedFile::MappedFile(StringView filename) if (st.st_size == 0) return; + else if (st.st_size > std::numeric_limits::max()) + throw runtime_error("file is too big"); data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (data == MAP_FAILED) throw file_access_error{filename, strerror(errno)}; - - if (st.st_size > std::numeric_limits::max()) - throw runtime_error("file is too big"); } MappedFile::~MappedFile()