Skip to content

Commit db0cba7

Browse files
author
Sparky
authored
Add valid checking to codec. Fixes: #254 (#270)
* Add valid checking to codec. Fixes: #254 * Loosen requirement and make sure nil get empty string
1 parent 7bf9bbd commit db0cba7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lua/advdupe2/cl_ghost.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ function AdvDupe2.LoadGhosts(dupe, info, moreinfo, name, preview)
5757
AdvDupe2.HeadAngle = AdvDupe2.GhostToSpawn[AdvDupe2.HeadEnt].PhysicsObjects[0].Angle
5858

5959
else
60-
time = info["time"]
61-
desc = dupe["Description"]
62-
date = info["date"]
63-
creator = info["name"]
60+
time = info["time"] or ""
61+
desc = dupe["Description"] or ""
62+
date = info["date"] or ""
63+
creator = info["name"] or ""
6464

6565
AdvDupe2.HeadEnt = dupe["HeadEnt"].Index
6666
AdvDupe2.HeadZPos = dupe["HeadEnt"].Z

lua/advdupe2/sh_codec.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,21 @@ versions[5] = function(encodedDupe)
417417
return deserialize(decompress(dupestring), read5), info
418418
end
419419

420+
421+
function AdvDupe2.CheckValidDupe(dupe, info)
422+
if not dupe.HeadEnt then return false, "Missing HeadEnt table" end
423+
if not dupe.HeadEnt.Index then return false, "Missing HeadEnt.Index" end
424+
if not dupe.HeadEnt.Z then return false, "Missing HeadEnt.Z" end
425+
if not dupe.HeadEnt.Pos then return false, "Missing HeadEnt.Pos" end
426+
if not dupe.Entities then return false, "Missing Entities table" end
427+
if not dupe.Entities[dupe.HeadEnt.Index] then return false, "Missing HeadEnt index from Entities table" end
428+
if not dupe.Entities[dupe.HeadEnt.Index].PhysicsObjects then return false, "Missing PhysicsObject table from HeadEnt Entity table" end
429+
if not dupe.Entities[dupe.HeadEnt.Index].PhysicsObjects[0] then return false, "Missing PhysicsObject[0] table from HeadEnt Entity table" end
430+
if not dupe.Entities[dupe.HeadEnt.Index].PhysicsObjects[0].Pos then return false, "Missing PhysicsObject[0].Pos from HeadEnt Entity table" end
431+
if not dupe.Entities[dupe.HeadEnt.Index].PhysicsObjects[0].Angle then return false, "Missing PhysicsObject[0].Angle from HeadEnt Entity table" end
432+
return true, dupe
433+
end
434+
420435
--[[
421436
Name: Decode
422437
Desc: Generates the table for a dupe from the given string. Inverse of Encode
@@ -437,6 +452,8 @@ function AdvDupe2.Decode(encodedDupe)
437452
if sig == "[Inf" then --legacy support, ENGAGE (AD1 dupe detected)
438453
local success, tbl, info, moreinfo = pcall(AdvDupe2.LegacyDecoders[0], encodedDupe)
439454

455+
success, tbl = AdvDupe2.CheckValidDupe(tbl, info)
456+
440457
if success then
441458
info.size = #encodedDupe
442459
info.revision = 0
@@ -455,13 +472,15 @@ function AdvDupe2.Decode(encodedDupe)
455472
return false, format("attempt to use an invalid format revision (rev %d)", rev)
456473
else
457474
local success, tbl, info = pcall(versions[rev], encodedDupe)
475+
476+
success, tbl = AdvDupe2.CheckValidDupe(tbl, info)
458477

459478
if success then
460479
info.revision = rev
461480
else
462481
ErrorNoHalt(tbl)
463482
end
464-
483+
465484
return success, tbl, info
466485
end
467486
end

0 commit comments

Comments
 (0)