Integer arithmetic is unchecked: silent wrong results in release, panics in debug #22

Open
opened 2026-08-07 13:33:09 +02:00 by Hemera · 0 comments
Owner

NomoValue::try_add / try_sub / try_mul / try_div (src/value.rs:116-225) perform raw u64/i64 arithmetic with no checked semantics.

  • In debug builds this panics (e.g. attempt to subtract with overflow).
  • In release builds it silently wraps to a wrong value.

Verified:

  • {{= 1 - 2 }} → release: wraps to a huge u64 instead of erroring.
  • {{= 18446744073709551615 + 1 }} → release: wraps to 0.
  • {{= 1 / 0 }} → division by zero.

Since integer literals are u64 and signed values can arrive from context (serde_json i64), this is reachable with ordinary data. Consider returning an EvaluationError on overflow/division-by-zero (or using checked_*), so both debug and release behave the same.

`NomoValue::try_add` / `try_sub` / `try_mul` / `try_div` (`src/value.rs:116-225`) perform raw `u64`/`i64` arithmetic with no checked semantics. - In `debug` builds this panics (e.g. `attempt to subtract with overflow`). - In `release` builds it silently wraps to a wrong value. Verified: - `{{= 1 - 2 }}` → release: wraps to a huge `u64` instead of erroring. - `{{= 18446744073709551615 + 1 }}` → release: wraps to `0`. - `{{= 1 / 0 }}` → division by zero. Since integer literals are `u64` and signed values can arrive from context (`serde_json` i64), this is reachable with ordinary data. Consider returning an `EvaluationError` on overflow/division-by-zero (or using `checked_*`), so both debug and release behave the same.
Sign in to join this conversation.
No labels
automated-🤖
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Hemera/nomo#22
No description provided.