Add max size for advdupe2 dupes (#470)

This commit is contained in:
thegrb93 2024-05-31 22:06:15 -04:00 committed by GitHub
parent 0c1d194c52
commit 238d02d289
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View File

@ -10,6 +10,7 @@
local REVISION = 5 local REVISION = 5
AdvDupe2.CodecRevision = REVISION AdvDupe2.CodecRevision = REVISION
AdvDupe2.MaxDupeSize = 32e6 -- 32 MB
include( "sh_codec_legacy.lua" ) include( "sh_codec_legacy.lua" )
AddCSLuaFile( "sh_codec_legacy.lua" ) AddCSLuaFile( "sh_codec_legacy.lua" )
@ -411,12 +412,12 @@ end
versions[4] = function(encodedDupe) versions[4] = function(encodedDupe)
local info, dupestring = getInfo(encodedDupe:sub(7)) local info, dupestring = getInfo(encodedDupe:sub(7))
return deserialize(decompress(dupestring), read4), info return deserialize(decompress(dupestring, AdvDupe2.MaxDupeSize), read4), info
end end
versions[5] = function(encodedDupe) versions[5] = function(encodedDupe)
local info, dupestring = getInfo(encodedDupe:sub(7)) local info, dupestring = getInfo(encodedDupe:sub(7))
return deserialize(decompress(dupestring), read5), info return deserialize(decompress(dupestring, AdvDupe2.MaxDupeSize), read5), info
end end
function AdvDupe2.CheckValidDupe(dupe, info) function AdvDupe2.CheckValidDupe(dupe, info)
@ -508,11 +509,8 @@ function AdvDupe2.Decode(encodedDupe)
if success then if success then
success, tbl = AdvDupe2.CheckValidDupe(tbl, info) success, tbl = AdvDupe2.CheckValidDupe(tbl, info)
end end
if success then if success then
info.revision = rev info.revision = rev
else
ErrorNoHalt(tbl)
end end
return success, tbl, info return success, tbl, info

View File

@ -37,6 +37,11 @@ concommand.Add("AdvDupe2_SaveFile", SaveFile)
function AdvDupe2.SendToClient(ply, data, autosave) function AdvDupe2.SendToClient(ply, data, autosave)
if(not IsValid(ply))then return end if(not IsValid(ply))then return end
if #data > AdvDupe2.MaxDupeSize then
AdvDupe2.Notify(ply,"Copied duplicator filesize is too big!",NOTIFY_ERROR)
return
end
ply.AdvDupe2.Downloading = true ply.AdvDupe2.Downloading = true
AdvDupe2.InitProgressBar(ply,"Saving:") AdvDupe2.InitProgressBar(ply,"Saving:")

View File

@ -835,6 +835,10 @@ if(SERVER) then
Tab.Map = true Tab.Map = true
AdvDupe2.Encode( Tab, AdvDupe2.GenerateDupeStamp(ply), function(data) AdvDupe2.Encode( Tab, AdvDupe2.GenerateDupeStamp(ply), function(data)
if #data > AdvDupe2.MaxDupeSize then
AdvDupe2.Notify(ply, "Copied duplicator filesize is too big!",NOTIFY_ERROR)
return
end
if(not file.IsDir("advdupe2_maps", "DATA")) then if(not file.IsDir("advdupe2_maps", "DATA")) then
file.CreateDir("advdupe2_maps") file.CreateDir("advdupe2_maps")
end end