-
-
Notifications
You must be signed in to change notification settings - Fork 968
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
Negating or taking absolute values of maximally-negative OverflowSafeInt may result in undefined behaviour #8284
Comments
techgeeknz
added a commit
to techgeeknz/OpenTTD
that referenced
this issue
Jul 30, 2020
Rewrite to avoid taking the absolute value of a maximally-negative integer. Fixes OpenTTD#8284
techgeeknz
added a commit
to techgeeknz/OpenTTD
that referenced
this issue
Jul 30, 2020
Rewrite to avoid taking the absolute value of a maximally-negative integer. Fixes OpenTTD#8284
This can also lead to the following exploit, which was used to produce test cases for #8253 and JGRennison/OpenTTD-patches#164:
|
techgeeknz
added a commit
to techgeeknz/OpenTTD
that referenced
this issue
Aug 23, 2020
Rewrite to avoid taking the absolute value of a maximally-negative integer. Fixes OpenTTD#8284
techgeeknz
added a commit
to techgeeknz/OpenTTD
that referenced
this issue
Aug 31, 2020
Rewrite to avoid taking the absolute value of a maximally-negative integer. Fixes OpenTTD#8284
JGRennison
added a commit
to JGRennison/OpenTTD-patches
that referenced
this issue
Oct 2, 2020
JGRennison
added a commit
to JGRennison/OpenTTD-patches
that referenced
this issue
Oct 2, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As mentioned in #7924,
OverflowSafeInt
can produce incorrect results when the value underflows. This appears to be the result of undefined behaviour caused by taking the inverse or absolute value of T_MIN; the magnitude of which cannot usually be represented as a positive value of the same integer type.I am not yet familiar with OpenTTD's continuous integration and regression testing system; however, I have an idea to work around the issue using typecasts to unsigned integers where appropriate.
The text was updated successfully, but these errors were encountered: