Skip to content

Commit

Permalink
Add max size for advdupe2 dupes (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 authored Jun 1, 2024
1 parent 0c1d194 commit 238d02d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lua/advdupe2/sh_codec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

local REVISION = 5
AdvDupe2.CodecRevision = REVISION
AdvDupe2.MaxDupeSize = 32e6 -- 32 MB

include( "sh_codec_legacy.lua" )
AddCSLuaFile( "sh_codec_legacy.lua" )
Expand Down Expand Up @@ -411,12 +412,12 @@ end

versions[4] = function(encodedDupe)
local info, dupestring = getInfo(encodedDupe:sub(7))
return deserialize(decompress(dupestring), read4), info
return deserialize(decompress(dupestring, AdvDupe2.MaxDupeSize), read4), info
end

versions[5] = function(encodedDupe)
local info, dupestring = getInfo(encodedDupe:sub(7))
return deserialize(decompress(dupestring), read5), info
return deserialize(decompress(dupestring, AdvDupe2.MaxDupeSize), read5), info
end

function AdvDupe2.CheckValidDupe(dupe, info)
Expand Down Expand Up @@ -508,11 +509,8 @@ function AdvDupe2.Decode(encodedDupe)
if success then
success, tbl = AdvDupe2.CheckValidDupe(tbl, info)
end

if success then
info.revision = rev
else
ErrorNoHalt(tbl)
end

return success, tbl, info
Expand Down
5 changes: 5 additions & 0 deletions lua/advdupe2/sv_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ concommand.Add("AdvDupe2_SaveFile", SaveFile)

function AdvDupe2.SendToClient(ply, data, autosave)
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
AdvDupe2.InitProgressBar(ply,"Saving:")

Expand Down
4 changes: 4 additions & 0 deletions lua/weapons/gmod_tool/stools/advdupe2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ if(SERVER) then

Tab.Map = true
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
file.CreateDir("advdupe2_maps")
end
Expand Down

0 comments on commit 238d02d

Please sign in to comment.