File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments