Skip to content

OFFSET: huge offsets and sizes give #REF! instead of overflowing - #466

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
webdevtodayjason:fix/offset-fn-overflow
Oct 13, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
webdevtodayjason:fix/offset-fn-overflow

Conversation

@webdevtodayjason

Copy link
Copy Markdown
Contributor

=OFFSET(B2,1E300,0) and =OFFSET(B2,0,0,1E300,1) failed cell.set with Internal("cell.set", "attempt to add with overflow"). The row, column, height and width arguments are truncated to i64, which saturates for huge values, and the plain additions that place the result then overflow. Excel returns #REF! for these.

The additions now saturate, so any argument that would land outside the sheet returns #REF! like other out-of-range offsets. Normal offsets, negative heights and widths, fractional truncation and results at the last row or column are unchanged.

How it was tested

  • New tests: offset_extreme_arguments_return_ref (calc) and crates/engine/tests/offset_overflow.rs (cell.set) cover huge positive and negative rows, columns, heights and widths, combinations of them, and a full-height result at the sheet edge. They fail on current main with the overflow and pass with this change.
  • cargo test -p gridcraft-calc passes. cargo fmt --check and cargo clippy --workspace --all-targets -- -D warnings pass. cargo xtask assets, layers, wasm and parity --check pass.
  • cargo test --workspace has three failures that also happen on current main without this change (same as the main CI run): csv_save_keeps_the_separator_it_was_opened_with and saving_an_opened_semicolon_csv_keeps_semicolons (1.24412E+11 instead of 124412140710), and translations_are_unique_and_preserve_unknown_text (missing French for "Different First Page"). CSV/text export: General numbers without exponents (integers below 1e16 exact); & switches to scientific past 21 characters #449 addresses these.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 581a234 into storytold:main Oct 13, 2026
1 check failed
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Merged — thank you @webdevtodayjason for the contribution!

If you haven't already, come join us on Discord: https://discord.gg/artcraft

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.

3 participants