Skip to content

fix: Avoid overflow in event check#4048

Open
dkachuma wants to merge 2 commits intodevelopfrom
dkachuma/fix-overflow-event-base
Open

fix: Avoid overflow in event check#4048
dkachuma wants to merge 2 commits intodevelopfrom
dkachuma/fix-overflow-event-base

Conversation

@dkachuma
Copy link
Copy Markdown
Contributor

@dkachuma dkachuma commented May 5, 2026

This is a fix for the forecast set in EventBase. Depending on m_beginTime, time and if dt is too small, the value of (m_beginTime - time)/dt might be too large to be cast into an integer. On some systems this throws a floating point exception. This PR puts some checks so that we never overflow the integer.

@dkachuma dkachuma self-assigned this May 5, 2026
@dkachuma dkachuma added type: bug Something isn't working ci: run CUDA builds Allows to triggers (costly) CUDA jobs flag: ready for review ci: run integrated tests Allows to run the integrated tests in GEOS CI flag: no rebaseline Does not require rebaseline ci: run code coverage enables running of the code coverage CI jobs labels May 5, 2026
@dkachuma dkachuma marked this pull request as ready for review May 5, 2026 18:38
@dkachuma dkachuma requested a review from Copilot May 5, 2026 19:48
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

This PR hardens EventBase::checkEvents against undefined behavior / SIGFPE when converting a potentially huge floating-point forecast value to an integer, by clamping the computed ratio to the representable range of integer before casting.

Changes:

  • Compute the pre-start forecast as a floating-point ratio (m_beginTime - time) / dt.
  • Clamp that ratio to [NumericLimits<integer>::min, NumericLimits<integer>::max] before casting to integer.
  • Use the clamped forecast value when calling setForecast() to avoid overflow on conversion.

@rrsettgast
Copy link
Copy Markdown
Member

@dkachuma Why is this an integer?

@dkachuma
Copy link
Copy Markdown
Contributor Author

dkachuma commented May 5, 2026

@dkachuma Why is this an integer?

I can't say I fully understand this. From the use it appears that we are 'forecasting' if the event will be active at the next step (forecast == 1). Otherwise the event is already active (forecast <= 0) or it's still idle (forecast > 1). So it's is the "expected number of code cycles before they are executed".

@cssherman Maybe you know better how this value is used.

@rrsettgast
Copy link
Copy Markdown
Member

@dkachuma it sounds like it can be a floating point value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: run code coverage enables running of the code coverage CI jobs ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI flag: no rebaseline Does not require rebaseline flag: ready for review type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants