Skip to content

fix(params): guard against inf/nan from safe_evaluate reaching FC upload#1440

Merged
amilcarlucas merged 1 commit intoArduPilot:masterfrom
yashhzd:fix/guard-inf-nan-safe-evaluate
Mar 28, 2026
Merged

fix(params): guard against inf/nan from safe_evaluate reaching FC upload#1440
amilcarlucas merged 1 commit intoArduPilot:masterfrom
yashhzd:fix/guard-inf-nan-safe-evaluate

Conversation

@yashhzd
Copy link
Copy Markdown
Contributor

@yashhzd yashhzd commented Mar 27, 2026

Summary

safe_evaluate() can produce non-finite values (inf, nan) from expressions like exp(1000), log(0), or conditional branches. These values bypass the existing ZeroDivisionError/ValueError handlers and flow unchecked through set_forced_or_derived_value() to the flight controller.

Changes

Add an isfinite() check on the evaluated result in compute_parameters() before creating the Par object. Non-finite values are rejected with a descriptive error message, consistent with the existing validation pattern for forced vs derived parameters.

This closes a gap where isfinite() checks existed for file-loaded parameters and user-entered values, but not for expression-evaluated results.

Closes #1438

Signed-off-by: Yash Goel yashhzd@users.noreply.github.com

@yashhzd yashhzd requested a review from amilcarlucas as a code owner March 27, 2026 20:54
Copilot AI review requested due to automatic review settings March 27, 2026 20:54
@yashhzd yashhzd force-pushed the fix/guard-inf-nan-safe-evaluate branch from 94b59d2 to 906ae9f Compare March 27, 2026 21:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Guards compute_parameters() against non-finite (inf/nan) results coming from safe_evaluate() so invalid computed values don’t propagate into Par objects and ultimately to flight controller uploads.

Changes:

  • Import math.isfinite for numeric validation.
  • Reject non-finite evaluated results with an explicit error/warning path consistent with existing forced vs. derived handling.
  • Add Ruff inline ignores for complexity-related linting on compute_parameters().

safe_evaluate() can produce non-finite values (inf, nan) from
expressions like exp(1000), log(0), or conditional branches that
evaluate to infinity. These values bypass the existing ZeroDivisionError
and ValueError exception handlers and flow unchecked through
set_forced_or_derived_value() to the flight controller.

Add an isfinite() check on the evaluated result before creating the Par
object. Non-finite values are now rejected with a descriptive error
message, consistent with the existing validation pattern for forced vs
derived parameters.

Signed-off-by: Yash Goel <yashhzd@users.noreply.github.com>
@yashhzd yashhzd force-pushed the fix/guard-inf-nan-safe-evaluate branch from 906ae9f to d55cfdd Compare March 27, 2026 22:19
@amilcarlucas amilcarlucas merged commit d2802af into ArduPilot:master Mar 28, 2026
19 checks passed
@amilcarlucas
Copy link
Copy Markdown
Collaborator

Thanks for this, merged

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.

safe_evaluate can produce inf/nan values that reach the flight controller

3 participants