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

参数导致BUG #109

Closed
zhuxianglong opened this issue Jan 31, 2023 · 2 comments
Closed

参数导致BUG #109

zhuxianglong opened this issue Jan 31, 2023 · 2 comments

Comments

@zhuxianglong
Copy link

zhuxianglong commented Jan 31, 2023

image
image
captcha.go,高度参数会导致异常,直接painc了并没有返回error,我觉得应该验证下或者返回error

@anyfig
Copy link

anyfig commented Apr 7, 2023

同样的问题,你怎么解决的?

@zuiwuchang
Copy link

這是 rand.Intn 因爲參數 <=0 而執行了 painc。我搜索了下 base64Captcha 中大量代碼都調用了 rand.Intn。所以會有很多不確定的情況導致 rand.Intn 執行 painc。(例如在創建 DriverString 是 Height 設置<16。或者在創建 DriverDigit 時 Height 設置 <7,...) 每種不同的 Driver 要求的屬性合法值都不一樣但創建 Driver 並沒有驗證有效屬性並爲錯誤屬性返回 error。這對正確調用 base64Captcha 造成了很大的負擔

鑑於 rand.Intn 被調用太頻繁,要去爲每個 Driver 驗證參數應該會相當繁瑣。本喵的建議是在源碼中寫一個 randIntn 函數

func randIntn(n int) int{
   if n <= 0 {
      return 0
   }
   return rand.Intn(n)
}

然後將源碼中的所有 rand.Intn( 替換爲 randIntn( 這樣當 Driver 某些參數不當時就不會引發 painc

當官方修復這一bug前恐怕只能自己 fork 一份來執行上述代碼替換。或者當你在創建任何 driver 前先自行確保屬性值是合法的

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

4 participants