shadow1ng/fscan · error

randomInt: range too large

Error message

randomInt: range too large

What it means

randomIntSpan rejects ranges whose span (max - min) would overflow int64. When min is negative and max exceeds maxInt64 + min, computing max-min overflows, so the function fails fast with "randomInt: range too large" instead of returning a wrapped-around value.

Source

Thrown at webscan/lib/eval_random.go:112

					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. Narrow the range so max - min fits in int64 (max <= maxInt64 + min).
  2. If a full-range random is needed, generate two values or use a dedicated full-range generator instead of randomInt.
  3. Clamp min/max to sane bounds before invoking the expression.

Example fix

// before
v, err := randomIntSpan(math.MinInt64, math.MaxInt64) // overflow

// after
v, err := randomIntSpan(-1<<62, 1<<62) // span fits in int64
Defensive patterns

Strategy: validation

Validate before calling

const maxInt64 = int64(^uint64(0) >> 1)
if min < 0 && max > maxInt64+min {
    return errors.New("range too large")
}

Try / catch

v, err := randomIntSpan(min, max)
if err != nil {
    min, max = clampRange(min, max) // shrink and retry
    v, err = randomIntSpan(min, max)
}

Prevention

When it happens

Trigger: Calling randomInt with min < 0 and max - min > math.MaxInt64, e.g. randomInt(math.MinInt64, math.MaxInt64).

Common situations: POC expressions using extremely wide integer ranges; generated templates that pass extreme sentinel values for min/max; users trying to get "any integer" via full int64 range.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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