Probable Context-Aware Warnings for Floating-Point Equality Comparisons

Offen
#15 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Dokumentation
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
security

Rechercherichtung

Read the issue’s linked Secure Coding Guide section for CWE-664/CWE-197 and review the floating-point equality examples it cites from NeMo and PyTorch. The issue asks whether warnings should be context-dependent, but gives no proposed change or acceptance criteria; done would require agreeing on guidance and updating the relevant guide section to reflect it.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I am working at OpenRefactory, a static analysis tool company. Our CEO, @openrefactorymunawar previously had some interactions with you and we have been improving our tool by adding the capability to detect some of the bugs that you are describing.

I have a question for one such bug pattern.

Recently, we introduced a fixer that flags warnings when floating-point values are used in equality comparisons. This practice is known to be problematic, as it can lead to unexpected outcomes due to the inherent imprecision of floating-point arithmetic.
The idea for this improvement was inspired by the guidance provided in the
Secure Coding Guide for Python (CWE-664/CWE-197)

Upon running this fixer on various projects, we found a significant number of instances where equality comparisons with floating-point values were being used. For example:

PyTorch 67 instances
NVIDIA Nemo 28 instances

Examples of such occurrences:

  1. Nemo
  2. NeMo
  3. pytorch

This raises a question: Could some of these cases be deliberate on the developers' part, where they knowingly use equality comparisons with floating-point values despite the risks, perhaps for a valid use case? If so, should we raise this warning universally, or should it be more context-dependent?

I'd love to hear your thoughts on this.

Vorherrschende Sprache
Python
Sterne
2
Forks
2
Ø Merge
11 Min.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ossf/python-secure-coding-guide

Alle Issues in ossf/python-secure-coding-guide

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.