Skip to content

fix(std): compute page counts without rounding overflow - #957

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
hiyouwhatsapp:fix/944-page-count-overflow
Oct 18, 2026
Merged

LunaStev merged 1 commit into
wavefnd:masterfrom
hiyouwhatsapp:fix/944-page-count-overflow

Conversation

@hiyouwhatsapp

Copy link
Copy Markdown
Contributor

Fixes #944.

mem_pages_for_size currently adds page_size - 1 before dividing. Near i64::MAX, that intermediate addition overflows even though the page count fits in i64.

This computes the quotient first and increments it when there's a remainder. The separate checked multiplication in mem_size_align_page is unchanged, so aligned byte counts that don't fit still return MEM_ERR_OVERFLOW.

The regression cases cover negative and zero sizes, either side of a page boundary, the largest representable byte count, the last fully aligned byte count, and aligned-byte overflow. I updated the existing Linux/amd64 expectation and extended both wasm32 and wasm64 memory cases. None of these new checks allocate large buffers.

Testing

  • Independent arithmetic reference (Python): 28 assertions passed with 4,096- and 65,536-byte pages.
  • Wave native and WebAssembly cases: not run locally. This environment has no wavec, Cargo, or LLVM toolchain and cannot clone GitHub repositories directly; these need CI verification.
  • Checked that the four modified files have no trailing whitespace.

This is a focused fix for the page-count helper; allocation limits and platform page-size selection stay as they were.

Avoid overflowing the temporary rounded byte count for representable page
counts. Cover boundaries and i64::MAX in Linux and WebAssembly cases while
keeping aligned-byte overflow checks.

Fixes wavefnd#944

Signed-off-by: hiyouwhatsapp <[email protected]>
@LunaStev
LunaStev merged commit 55fcf41 into wavefnd:master Oct 18, 2026
35 checks passed
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.

Compute representable page counts without overflowing the rounding intermediate

2 participants