Skip to content

Commit ae61575

Browse files
committed
hacky mmap change
1 parent e44d74b commit ae61575

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

extension/data_loader/mmap_data_loader.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ Result<MmapDataLoader> MmapDataLoader::from(
9494
}
9595

9696
// Cache the file size.
97+
#if defined(_WIN32)
98+
struct _stat64 st;
99+
int err = ::_fstat64(fd, &st);
100+
#else
97101
struct stat st;
98102
int err = ::fstat(fd, &st);
103+
#endif
99104
if (err < 0) {
100105
ET_LOG(
101106
Error,
@@ -106,7 +111,15 @@ Result<MmapDataLoader> MmapDataLoader::from(
106111
::close(fd);
107112
return Error::AccessFailed;
108113
}
109-
size_t file_size = st.st_size;
114+
115+
uint64_t file_size_u64 = static_cast<uint64_t>(st.st_size);
116+
ET_CHECK_OR_RETURN_ERROR(
117+
file_size_u64 <= std::numeric_limits<size_t>::max(),
118+
NotSupported,
119+
"File %s is too large (%llu bytes) for current platform",
120+
file_name,
121+
static_cast<unsigned long long>(file_size_u64));
122+
size_t file_size = static_cast<size_t>(file_size_u64);
110123

111124
// Copy the filename so we can print better debug messages if reads fail.
112125
const char* file_name_copy = ::strdup(file_name);

0 commit comments

Comments
 (0)