mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
check file size before mapping on linux
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -43,6 +44,13 @@ inline bool MapFile::open(const char *file_name, unsigned long file_size)
|
|||||||
// g_print("Open file %s failed!\n",fullfilename);
|
// g_print("Open file %s failed!\n",fullfilename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(mmap_fd, &st) == -1 || st.st_size < 0 || (st.st_size == 0 && S_ISREG(st.st_mode))
|
||||||
|
|| sizeof(st.st_size) > sizeof(file_size) || static_cast<unsigned long>(st.st_size) != file_size) {
|
||||||
|
close(mmap_fd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
data = (gchar *)mmap(nullptr, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
|
data = (gchar *)mmap(nullptr, file_size, PROT_READ, MAP_SHARED, mmap_fd, 0);
|
||||||
if ((void *)data == (void *)(-1)) {
|
if ((void *)data == (void *)(-1)) {
|
||||||
// g_print("mmap file %s failed!\n",idxfilename);
|
// g_print("mmap file %s failed!\n",idxfilename);
|
||||||
|
|||||||
Reference in New Issue
Block a user