@@ -108,9 +108,12 @@ function mmap_stream_settings(s::IO)
108
108
end
109
109
110
110
# Mmapped-array constructor
111
- function mmap_array {T,N} (:: Type{T} , dims:: NTuple{N,Int } , s:: IO , offset:: FileOffset )
111
+ function mmap_array {T,N,TInt<:Integer } (:: Type{T} , dims:: NTuple{N,TInt } , s:: IO , offset:: FileOffset )
112
112
prot, flags, iswrite = mmap_stream_settings (s)
113
113
len = prod (dims)* sizeof (T)
114
+ if len > typemax (Int)
115
+ error (" File is too large to memory-map on this platform" )
116
+ end
114
117
if iswrite
115
118
pmap, delta = mmap_grow (len, prot, flags, fd (s), offset)
116
119
else
@@ -122,13 +125,16 @@ function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IO, offset::FileOffs
122
125
end
123
126
124
127
# Mmapped-bitarray constructor
125
- function mmap_bitarray {N} (dims:: NTuple{N,Int } , s:: IOStream , offset:: FileOffset )
128
+ function mmap_bitarray {N,TInt<:Integer } (dims:: NTuple{N,TInt } , s:: IOStream , offset:: FileOffset )
126
129
prot, flags, iswrite = mmap_stream_settings (s)
127
130
if length (dims) == 0
128
131
dims = 0
129
132
end
130
133
n = prod (dims)
131
134
nc = num_bit_chunks (n)
135
+ if nc > typemax (Int)
136
+ error (" File is too large to memory-map on this platform" )
137
+ end
132
138
chunks = mmap_array (Uint64, (nc,), s, offset)
133
139
if iswrite
134
140
chunks[end ] &= @_msk_end n
@@ -152,11 +158,15 @@ end
152
158
# ## Windows implementation ###
153
159
@windows_only begin
154
160
# Mmapped-array constructor
155
- function mmap_array {T,N} (:: Type{T} , dims:: NTuple{N,Int } , s:: IO , offset:: FileOffset )
161
+ function mmap_array {T,N,TInt<:Integer } (:: Type{T} , dims:: NTuple{N,TInt } , s:: IO , offset:: FileOffset )
156
162
shandle = _get_osfhandle (RawFD (fd (s)))
157
163
ro = isreadonly (shandle)
158
164
flprotect = ro ? 0x02 : 0x04
159
- szarray = convert (Csize_t, prod (dims))* sizeof (T)
165
+ len = prod (dims)* sizeof (T)
166
+ if len > typemax (Int)
167
+ error (" File is too large to memory-map on this platform" )
168
+ end
169
+ szarray = convert (Csize_t, len)
160
170
szfile = szarray + convert (Csize_t, offset)
161
171
mmaphandle = ccall (:CreateFileMappingA , stdcall, Ptr{Void}, (Ptr{Void}, Ptr{Void}, Cint, Cint, Cint, Ptr{Void}), shandle. handle, C_NULL , flprotect, szfile>> 32 , szfile& 0xffffffff , C_NULL )
162
172
if mmaphandle == C_NULL
0 commit comments