github / github/codeql

False positive: Multiplication result converted to larger type

Đang mở
#11,556 4 bình luận 1 reaction 0 người được giao Xem trên GitHub
acknowledged false-positive
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

[Monocypher](https://github.com/LoupVaillant/Monocypher/) implements, among other things, the Poly1305 MAC. CodeQL takes issue with a carefully-constructed sequence of multiplications, tripping [cpp/integer-multiplication-cast-to-long](https://codeql.github.com/codeql-query-help/cpp/cpp-integer-multiplication-cast-to-long/).

I asked the author about it in LoupVaillant/Monocypher#245, and you should check there for an analysis. I understand the short version to be:

* CodeQL is correct
* The sequence is carefully constructed to never overflow, and the author has a proof
* There are additional invariants enforced earlier that stop the overflow from being possible, that can't be expressed in C's type system
* Adding an explicit cast silences the warnings, but results in a measurable drop in performance (it converts a 64x32b multiplication to a 64x64b)

Ideally if there was a suppression mechanism, I would use it. As it is, I will likely simply leave a comment.

**Code samples or links to source code**

https://github.com/LoupVaillant/Monocypher/blob/master/src/monocypher.c#L352

**URL to the alert on GitHub code scanning (optional)**

The Security tab appears to have no alerts in it; the reports appear in openzfs/zfs#14249.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.