Skip to content

Fix 64-bit safe integer boundary checks - #9074

Open
GtechGovind wants to merge 1 commit into
WebAssembly:mainfrom
GtechGovind:fix/safe-integer-64-boundaries
Open

Fix 64-bit safe integer boundary checks#9074
GtechGovind wants to merge 1 commit into
WebAssembly:mainfrom
GtechGovind:fix/safe-integer-64-boundaries

Conversation

@GtechGovind

Copy link
Copy Markdown

Summary

  • compare 64-bit integer inputs against exact, exclusive power-of-two boundaries
  • avoid rounding INT64_MAX and UINT64_MAX to out-of-range double values
  • cover the adjacent representable values on both sides of the signed and unsigned limits

Closes #2291.

Testing

  • ./out/build/bin/binaryen-unittests --gtest_filter=SafeInteger.* (2 passed)
  • ./out/build/bin/binaryen-unittests (422 passed)

EXPECT_TRUE(wasm::isSInteger64(-0x1p63));
EXPECT_TRUE(wasm::isSInteger64(std::nextafter(0x1p63, 0.0)));
EXPECT_FALSE(wasm::isSInteger64(0x1p63));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which of these tests fail before the fix?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Before the fix, these two assertions fail:

  • EXPECT_FALSE(wasm::isUInteger64(0x1p64))
  • EXPECT_FALSE(wasm::isSInteger64(0x1p63))
    The previous upper-bound conversions round UINT64_MAX and INT64_MAX to 2^64 and 2^63 respectively, so those out-of-range values were incorrectly accepted. The other boundary assertions pass before the fix.

@GtechGovind
GtechGovind marked this pull request as ready for review September 5, 2026 07:13
@GtechGovind
GtechGovind requested a review from a team as a code owner September 5, 2026 07:13
@GtechGovind
GtechGovind requested review from kripken and removed request for a team September 5, 2026 07:13
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.

wasm::is{U,S}Integer64() doesn't work well around INT64_MAX

2 participants