From 5a562a597cb8d1b71c5e0c1247836fe21ebccc56 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Sat, 2 Jul 2022 21:58:23 +0200 Subject: Serialization spec: Fix number fuzzing (#12496) --- builtin/common/tests/serialize_spec.lua | 6 ++++-- 1 file 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() -- cgit v1.2.3