mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-12 11:29:36 +03:00
Fix int overflow on x32 processors causing panic (#3810)
During the roll, "duration" is converted to int, causing overflow on x32 processors. The value may be very small or negative, causing a panic in rand.Intn.
This commit is contained in:
@ -14,6 +14,14 @@ func Roll(n int) int {
|
||||
return rand.Intn(n)
|
||||
}
|
||||
|
||||
// RollInt63n returns a non-negative number between 0 (inclusive) and n (exclusive).
|
||||
func RollInt63n(n int64) int64 {
|
||||
if n == 1 {
|
||||
return 0
|
||||
}
|
||||
return rand.Int63n(n)
|
||||
}
|
||||
|
||||
// Roll returns a non-negative number between 0 (inclusive) and n (exclusive).
|
||||
func RollDeterministic(n int, seed int64) int {
|
||||
if n == 1 {
|
||||
|
Reference in New Issue
Block a user