False positive - go/allocation-size-overflow
- 主要言語
- CodeQL
- スター
- 10.1k
- フォーク
- 2.1k
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 141
説明
**Description of the false positive**
This rule fires when you make a slice from the length of another slice and add a small constant size to it. It's literally impossible to overflow MaxInt on a 64 bit machine in today's world in this case.
**Code samples or links to source code**
```go
// simplified for this example
func extend(input []byte) []byte {
return make([]byte, len(input)+1)
}
```
** More Discussion **
In order for this to overflow, the input slice would need to be of size MaxInt. That's approximately 9 million terabytes if we're talking []byte on a 64 bit machine. The largest machine on azure right now has 12 TB of RAM. Even if we assume RAM size doubles every year, no machine will have 9 million terabytes of RAM for at least 20 years. So, you can't have a slice of anything except an empty struct that is anywhere near MaxInt length.
Until that time, it's literally impossible to have a slice of bytes with a length that is MaxInt-1 on a 64 bit machine. You'd run out of memory loooong before you had to worry about overflowing the int in the `make()` call.
Is there a way this check could be changed so that it won't trigger if you're getting the length off some other slice? Or are we worried about 32bit architectures, because that does not seem like something we should worry about at GitHub.
I don't really know much about how CodeQL works or what it can infer, but I'm open to other ways to avoid this check.
コントリビューションガイド
調査の方向性
まず go/allocation-size-overflow クエリを見つけ、報告された Go の例で len(input)+1 をどのように処理しているかを確認します。このケースを報告する前に、チェックでスライスの長さを考慮できるかどうかを判断しつつ、実際の overflow リスクに対するカバレッジを維持します。false positive が解消され、ルールの動作が関連するクエリ検証によってカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- go
- 領域
- devtools, security
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100