Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry.getSleep 存在可能的 overflow 问题 #258

Closed
Mrs4s opened this issue Oct 22, 2020 · 2 comments
Closed

Retry.getSleep 存在可能的 overflow 问题 #258

Mrs4s opened this issue Oct 22, 2020 · 2 comments

Comments

@Mrs4s
Copy link

Mrs4s commented Oct 22, 2020

gout/filter/retry.go

Lines 92 to 100 in 5d2c07e

func (r *Retry) getSleep() time.Duration {
temp := r.waitTime * time.Duration(math.Exp2(float64(r.currAttempt)))
if temp <= 0 {
temp = r.waitTime
}
temp = r.min(r.maxWaitTime, temp)
temp /= 2
return temp + time.Duration(rand.Intn(int(temp)))
}

GOARCH=386 时, int 类型为 4 字节, 此时如果设置 MaxWaitTime > time.Second * 4 的话会造成
temp = r.min(r.maxWaitTime, temp)

temp 大于 int32 的最大值, 在转换后出现负数 直到 rand.Intn(int(temp)) 出现panic.

建议修改 rand.Intnrand.Int63n

相关问题 : Mrs4s/go-cqhttp#373

@Mrs4s Mrs4s changed the title Retry.getSleep 存在可能的 overflow 的问题 Retry.getSleep 存在可能的 overflow 问题 Oct 22, 2020
@guonaihong
Copy link
Owner

ok。我加些32位平台的测试用例。

@guonaihong
Copy link
Owner

guonaihong commented Oct 22, 2020

在v0.1.3版本已经修复。issue先关闭,如有问题,可重新打开。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants