summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-07-02 21:58:23 +0200
committerGitHub <noreply@github.com>2022-07-02 20:58:23 +0100
commit5a562a597cb8d1b71c5e0c1247836fe21ebccc56 (patch)
treedce64e97c462c76905b5746c279d6991c3a872ee
parent3e308584a3608406bb5c20ce4503a4bfa1b1d608 (diff)
downloadminetest-5a562a597cb8d1b71c5e0c1247836fe21ebccc56.tar.gz
minetest-5a562a597cb8d1b71c5e0c1247836fe21ebccc56.tar.bz2
minetest-5a562a597cb8d1b71c5e0c1247836fe21ebccc56.zip
Serialization spec: Fix number fuzzing (#12496)
-rw-r--r--builtin/common/tests/serialize_spec.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/common/tests/serialize_spec.lua b/builtin/common/tests/serialize_spec.lua
index ea79680d7..340e226ee 100644
--- a/builtin/common/tests/serialize_spec.lua
+++ b/builtin/common/tests/serialize_spec.lua
@@ -133,7 +133,9 @@ describe("serialize", function()
end
local function num()
local sign = math.random() < 0.5 and -1 or 1
- local val = math.random(0, 2^52)
+ -- HACK math.random(a, b) requires a, b & b - a to fit within a 32-bit int
+ -- Use two random calls to generate a random number from 0 - 2^50 as lower & upper 25 bits
+ local val = math.random(0, 2^25) * 2^25 + math.random(0, 2^25 - 1)
local exp = math.random() < 0.5 and 1 or 2^(math.random(-120, 120))
return sign * val * exp
end
@@ -152,7 +154,7 @@ describe("serialize", function()
local root = {}
local tables = {root}
local function random_table()
- return tables[#tables == 1 and 1 or math.random(1, #tables)] -- luacheck: ignore
+ return tables[math.random(1, #tables)]
end
for _ = 1, math.random(1, max_actions) do
local tab = random_table()