From 0dbb2b025a1a71fe3f2559ff442b60455db828b5 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:25:48 +0100 Subject: re-add MAX_STEPS --- rtt-module.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'rtt-module.js') diff --git a/rtt-module.js b/rtt-module.js index b1df281..b7e727d 100755 --- a/rtt-module.js +++ b/rtt-module.js @@ -8,6 +8,7 @@ const { FuzzedDataProvider } = require("@jazzer.js/core") const RULES_JS_FILE = process.env.RTT_RULES || "rules.js" const NO_UNDO = process.env.NO_UNDO === 'true' const NO_SCHEMA = process.env.NO_SCHEMA === 'true' +const MAX_STEPS = parseInt(process.env.MAX_STEPS || 0) console.log(`Loading rtt-fuzzer RTT_RULES='${RULES_JS_FILE}'`) if (!fs.existsSync(RULES_JS_FILE)) { @@ -48,6 +49,12 @@ module.exports.fuzz = function(fuzzerInputData) { // insufficient bytes to continue return } + + if (MAX_STEPS < 0 && step > -MAX_STEPS) { + // Skip & ignore if we reach the limit + return + } + let active = state.active if (active === 'Both' || active === 'All') { // If multiple players can act, we'll pick a random player to go first. @@ -62,6 +69,11 @@ module.exports.fuzz = function(fuzzerInputData) { throw new RulesCrashError(e, e.stack) } + if (MAX_STEPS > 0 && step > MAX_STEPS) { + log_crash(game_setup, state, view, step, active) + throw new MaxStepError("MAX_STEPS reached") + } + if (rules_view_schema && !rules_view_schema(view)) { log_crash(game_setup, state, view, step, active) console.log(rules_view_schema.errors) @@ -100,6 +112,7 @@ module.exports.fuzz = function(fuzzerInputData) { log_crash(game_setup, state, view, step, active) throw new NoMoreActionsError("No more actions to take (besides undo)") } + let action = data.pickValue(Object.keys(actions)) let args = actions[action] @@ -147,6 +160,13 @@ class UnknownStateError extends Error { } } +class MaxStepError extends Error { + constructor(message) { + super(message) + this.name = "MaxStepError" + } +} + class NoMoreActionsError extends Error { constructor(message) { super(message) -- cgit v1.2.3