shadow1ng/fscan · error
random string length must be between 0 and %d
Error message
random string length must be between 0 and %d
What it means
validateRandomStringLength bounds the requested length for the randomStr/random string expression function to [0, maxRandomStringLength]. Passing a negative or excessively large length returns this error naming the allowed maximum.
Source
Thrown at webscan/lib/eval_random.go:119
},
},
}
}
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
- Use a length between 0 and maxRandomStringLength (see the %d in the message).
- For larger payloads, build them by concatenating multiple randomStr calls.
- Clamp the computed length with a min/max helper before calling the function.
Example fix
// before
s, err := randomStr(1 << 30) // too large
// after
n := 1 << 30
if n > maxRandomStringLength { n = maxRandomStringLength }
s, err := randomStr(n) Defensive patterns
Strategy: validation
Validate before calling
func saneLen(n int) (int, error) {
if n < 0 || n > maxRandomStringLength {
return 0, fmt.Errorf("length %d out of [0,%d]", n, maxRandomStringLength)
}
return n, nil
} Try / catch
n, err := validateRandomStringLength(want)
if err != nil {
n = maxRandomStringLength // clamp instead of failing
} Prevention
- Clamp computed lengths before calling random string functions.
- Build large payloads by concatenating multiple bounded random strings.
- Keep POC template lengths within documented limits.
When it happens
Trigger: Calling the random-string function with n < 0 or n > maxRandomStringLength, typically via a POC expression like randomStr(999999999).
Common situations: POC templates with oversized random payloads for buffer-overflow style tests; negative lengths from computed expressions; copy-pasted templates written for libraries with larger limits.
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
- randomInt: max(%d) must be greater than min(%d)
- randomInt: range too large
- result cannot be nil
- result cannot be nil
- output file not specified
AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06).
Data as JSON: /api/errors/d9e0a7c55e605bd1.
Report an issue: GitHub.