Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVSS4 round_away_from_zero error #60

Closed
Zalutskii opened this issue Aug 28, 2024 · 3 comments
Closed

CVSS4 round_away_from_zero error #60

Zalutskii opened this issue Aug 28, 2024 · 3 comments

Comments

@Zalutskii
Copy link

Zalutskii commented Aug 28, 2024

def round_away_from_zero(x, dp):

The round_away_from_zero function is not working correctly.
For values round_away_from_zero(8.45, 1) should return 8.5, but it returns 8.4. https://python-fiddle.com/saved/IKHz08xWhe4LsUnxAAez
This error leads to incorrect calculation of score for some vectors. For example, for the vector
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:A/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N/E:P/CR:L/IR:L/AR:L/MAV:N/MAC:L/MAT:N/MPR:L/MUI:A/MVC:H/MVI:H/MVA:H/MSC:H/MSI:S/MSA:S/S:P/AU:Y/R:I/V:C/RE:H/U:Red score should be 8.5 and not 8.4.

@skontar
Copy link
Collaborator

skontar commented Aug 28, 2024

Hi! We are aware of rounding issues caused mostly by using floats instead of Decimals in CVSS v4 implementation.

In this specific case, it is because 8.45 cannot be represented correctly in float.

>>> print(8.45)
8.45
>>> print(f"{8.45:0.20f}")
8.44999999999999928946
>>> round(8.45, 1)
8.4

We are currently working on making sure both Javascript and Python implementations will return the same – and expected – values.

We will be likely using the following:

>>> from decimal import ROUND_HALF_UP
>>> float(D(8.45 * 10).quantize(D("1"), rounding=ROUND_HALF_UP) / 10)
8.5

@skontar
Copy link
Collaborator

skontar commented Aug 28, 2024

We are currently in phase of testing.
FYI, @superbuggy , you can check this specific vector.

@skontar
Copy link
Collaborator

skontar commented Sep 7, 2024

Resolved by #61

@skontar skontar closed this as completed Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@Zalutskii @skontar and others