shadow1ng/fscan · error

randomInt: max(%d) must be greater than min(%d)

Error message

randomInt: max(%d) must be greater than min(%d)

What it means

randomIntSpan validates the min/max arguments for the randomInt expression function. It requires max to be strictly greater than min; otherwise it returns this descriptive error. This guards against nonsensical ranges where no integer can be produced.

Source

Thrown at webscan/lib/eval_random.go:108

			Operator: "randomString_int",
			Unary: func(value ref.Val) ref.Val {
				n, ok := value.(types.Int)
				if !ok {
					return types.ValOrErr(value, "unexpected type '%v' passed to randomString", value.Type())
				}
				length, err := validateRandomStringLength(n)
				if err != nil {
					return types.NewErr("%v", err)
				}
				return types.String(randomString(length))
			},
		},
	}
}

func randomIntSpan(min, max int64) (int64, error) {
	if max <= min {
		return 0, fmt.Errorf("randomInt: max(%d) must be greater than min(%d)", max, min)
	}
	const maxInt64 = int64(^uint64(0) >> 1)
	if min < 0 && max > maxInt64+min {
		return 0, fmt.Errorf("randomInt: range too large")
	}
	return max - min, nil
}

func validateRandomStringLength(n types.Int) (int, error) {
	if n < 0 || n > maxRandomStringLength {
		return 0, fmt.Errorf("random string length must be between 0 and %d", maxRandomStringLength)
	}
	return int(n), nil
}

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Ensure max is strictly greater than min before calling randomInt.
  2. If min and max are equal by design, decide the value yourself instead of calling randomInt.
  3. Swap the arguments if they were accidentally reversed.

Example fix

// before
v, err := randomIntSpan(max, min)

// after
if min >= max { min, max = max, min }
v, err := randomIntSpan(min, max)
Defensive patterns

Strategy: validation

Validate before calling

if min >= max {
    return errors.New("randomInt: max must be greater than min")
}

Try / catch

v, err := randomIntSpan(min, max)
if err != nil {
    return fmt.Errorf("bad range [%d,%d): %w", min, max, err)
}

Prevention

When it happens

Trigger: Calling randomInt(min, max) (or expression randomInt(...) in a POC) with max <= min, e.g. randomInt(10, 10) or randomInt(5, 3).

Common situations: POC templates where min/max are computed from variables that end up equal or inverted; typos swapping the arguments; dynamically generated ranges that degenerate to a single value.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06). Data as JSON: /api/errors/077ed95215545d5c. Report an issue: GitHub.