Giter VIP home page Giter VIP logo

Comments (2)

anyfig avatar anyfig commented on July 17, 2024

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

from base64captcha.

zuiwuchang avatar zuiwuchang commented on July 17, 2024

這是 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 前先自行確保屬性值是合法的

from base64captcha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.