# Integer Overflow or Wraparound (CWE-190) The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. **Stack:** Go - Prevalence: 中 3 言語をカバー - Impact: ミディアム レビュー推奨 - Prevention: 文書化済み 3 件の修正例 **OWASP:** Security Misconfiguration (A05:2021-Security Misconfiguration) - #5 ## Description An integer overflow occurs when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of bits. This can lead to buffer overflows, incorrect financial calculations, or security bypasses. ## Prevention 1 件の Shoulder 検出ルールに基づく Integer Overflow の予防策。 ### Go Validate bounds before arithmetic operations with user-controlled integers ## Consequences - DoS - 未承認コードの実行 - アプリケーションデータの変更 ## Mitigations - 整数オーバーフローを検出する言語またはライブラリを使用する - 入力が期待される範囲内にあることを検証する - オーバーフローを検出する安全な算術関数を使用する ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Integer Overflow via Unchecked Arithmetic** [MEDIUM]: User-controlled integer used in arithmetic or allocation without bounds checking. - Remediation: Validate bounds before arithmetic operations with user input. ```go count, err := strconv.Atoi(r.URL.Query().Get("count")) if err != nil || count < 0 || count > 10000 { return errors.New("invalid count") } buffer := make([]byte, count*1024) ``` Learn more: https://shoulder.dev/learn/go/cwe-190/integer-overflow