src: Check the filesize before calling mmap()
This commit is contained in:
parent
fc9e0e8c6a
commit
7a384edeb0
|
@ -217,13 +217,12 @@ MappedFile::MappedFile(StringView filename)
|
||||||
|
|
||||||
if (st.st_size == 0)
|
if (st.st_size == 0)
|
||||||
return;
|
return;
|
||||||
|
else if (st.st_size > std::numeric_limits<int>::max())
|
||||||
|
throw runtime_error("file is too big");
|
||||||
|
|
||||||
data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (data == MAP_FAILED)
|
if (data == MAP_FAILED)
|
||||||
throw file_access_error{filename, strerror(errno)};
|
throw file_access_error{filename, strerror(errno)};
|
||||||
|
|
||||||
if (st.st_size > std::numeric_limits<int>::max())
|
|
||||||
throw runtime_error("file is too big");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MappedFile::~MappedFile()
|
MappedFile::~MappedFile()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user