Skip to content

[#1933] Validate impulse_request values#1934

Merged
daid merged 5 commits intodaid:masterfrom
oznogon:1933-validate-requests
Apr 4, 2024
Merged

[#1933] Validate impulse_request values#1934
daid merged 5 commits intodaid:masterfrom
oznogon:1933-validate-requests

Conversation

@oznogon
Copy link
Copy Markdown
Contributor

@oznogon oznogon commented Mar 4, 2023

#1933 shows that directly setting impulse_request on a SpaceShip can result in unusable or poorly defined values, such as infinity/-infinity from dividing by 0 impulse speed on Odins and Defense Platforms.

Add a setImpulseRequest() function that clamps the passed value and replace direct modifications of impulse_request with it.

Fixes #1933.

Comment thread src/ai/ai.cpp Outdated
@oznogon oznogon force-pushed the 1933-validate-requests branch from a7078c2 to 5a4d862 Compare March 19, 2023 22:32
@daid
Copy link
Copy Markdown
Owner

daid commented Apr 3, 2024

I see I totally forgot to reply to this.

While the idea is feels sound on the first glance. There is an issue with it. It's still dividing by zero, and assuming that it will produce "infinity". But as we are compiling with -funsafe-math-optimizations this does not have to be true, and division by zero is can be UB or an exception, so we should avoid it in the first place.

@oznogon
Copy link
Copy Markdown
Contributor Author

oznogon commented Apr 3, 2024

Added a check to confirm that impulse_max_speed is greater than 0 before attempting setImpulseRequest.

@daid daid merged commit e60b242 into daid:master Apr 4, 2024
Tsht pushed a commit to Tsht/EmptyEpsilon that referenced this pull request Oct 12, 2024
* [SpaceShip] Add setImpulseRequest() function

* [AI] Use setImpulseRequest() to ensure valid request values

* [AI] Avoid division by 0 by validating impulse_max_speed

* [AI] Make it make sense

* [AI] No really
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

Successfully merging this pull request may close these issues.

[AI] CpuShips with 0 max_impulse_speed can set infinite impulse_request values

2 participants