@@ -17,6 +17,8 @@ include("scope.jl")
1717include (" subtypes.jl" )
1818include (" methodmatching.jl" )
1919
20+ const LARGE_FILE_LIMIT = 2_000_000 # bytes
21+
2022mutable struct Meta
2123 binding:: Union{Nothing,Binding}
2224 scope:: Union{Nothing,Scope}
@@ -227,6 +229,20 @@ function traverse(x::EXPR, state)
227229 end
228230end
229231
232+ function check_filesize (x, path)
233+ nb = try
234+ filesize (path)
235+ catch
236+ seterror! (x, FileNotAvailable)
237+ return false
238+ end
239+
240+ toobig = nb > LARGE_FILE_LIMIT
241+ if toobig
242+ seterror! (x, FileTooBig)
243+ end
244+ return ! toobig
245+ end
230246
231247"""
232248 followinclude(x, state)
@@ -245,7 +261,11 @@ function followinclude(x, state::State)
245261 elseif isabspath (path)
246262 if hasfile (state. server, path)
247263 elseif canloadfile (state. server, path)
248- loadfile (state. server, path)
264+ if check_filesize (x, path)
265+ loadfile (state. server, path)
266+ else
267+ return
268+ end
249269 else
250270 path = " "
251271 end
@@ -255,7 +275,11 @@ function followinclude(x, state::State)
255275 path = joinpath (dirname (getpath (state. file)), path)
256276 elseif canloadfile (state. server, joinpath (dirname (getpath (state. file)), path))
257277 path = joinpath (dirname (getpath (state. file)), path)
258- loadfile (state. server, path)
278+ if check_filesize (x, path)
279+ loadfile (state. server, path)
280+ else
281+ return
282+ end
259283 else
260284 path = " "
261285 end
@@ -277,8 +301,14 @@ function followinclude(x, state::State)
277301 seterror! (x, IncludeLoop)
278302 return
279303 end
304+ f = getfile (state. server, path)
305+
306+ if f. cst. fullspan > LARGE_FILE_LIMIT
307+ seterror! (x, FileTooBig)
308+ return
309+ end
280310 oldfile = state. file
281- state. file = getfile (state . server, path)
311+ state. file = f
282312 push! (state. included_files, getpath (state. file))
283313 setroot (state. file, getroot (oldfile))
284314 setscope! (getcst (state. file), nothing )
0 commit comments