Skip to content

Fix/i32 min rem overflow (minor) - #5501

Open
Jayesh-Dev21 wants to merge 1 commit into
boa-dev:mainfrom
Jayesh-Dev21:fix/i32-min-rem-overflow
Open

Fix/i32 min rem overflow (minor)#5501
Jayesh-Dev21 wants to merge 1 commit into
boa-dev:mainfrom
Jayesh-Dev21:fix/i32-min-rem-overflow

Conversation

@Jayesh-Dev21

Copy link
Copy Markdown

This Pull Request fixes/closes #5481.

It changes the following:

Fixes a panic when computing (-2147483648 | 0) % (-1 | 0). The fast-path integer remainder operations (rem and rem_fast) used bare x % y on i32 values, which panics on signed integer overflow when x = i32::MIN and y = -1.
Changes

  • core/engine/src/value/operations.rs: Replaced bare x % y with x.checked_rem(y) in both rem() and rem_fast(). On overflow (None), falls back to f64 arithmetic — the same pattern already used by add, sub, mul, and div in the same file.
  • core/engine/src/value/tests.rs: Added regression test rem_i32_min_by_neg_one asserting the result is -0.0.

Verification

  • (-2147483648 | 0) % (-1 | 0) now returns -0 instead of panicking (matches Node.js behaviour)
image
  • Existing rem_by_zero test still passes
  • Clippy clean (both --all-features and --no-default-features)

@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Aug 30, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Aug 30, 2026
@github-actions github-actions Bot added the C-Tests Issues and PRs related to the tests. label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,426 51,426 0
Ignored 1,648 1,648 0
Failed 504 504 0
Panics 0 0 0
Conformance 95.98% 95.98% 0.00%

Tested main commit: 665f03924a54e5162be227e7e909612e36f6e35a
Tested PR commit: b9ff062884403585e8bfcfac558269dbd3890524
Compare commits: 665f039...b9ff062

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.81%. Comparing base (6ddc2b4) to head (b9ff062).
⚠️ Report is 1050 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/value/operations.rs 62.50% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5501       +/-   ##
===========================================
+ Coverage   47.24%   62.81%   +15.57%     
===========================================
  Files         476      536       +60     
  Lines       46892    60288    +13396     
===========================================
+ Hits        22154    37871    +15717     
+ Misses      24738    22417     -2321     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jayesh-Dev21
Jayesh-Dev21 force-pushed the fix/i32-min-rem-overflow branch from e6e00dd to 8b233c4 Compare August 31, 2026 15:20
@nekevss

nekevss commented Sep 1, 2026

Copy link
Copy Markdown
Member

Feel free to mark this as ready for review whenever you're ready for a maintainer to take a look

@Jayesh-Dev21
Jayesh-Dev21 marked this pull request as ready for review September 1, 2026 13:26
@Jayesh-Dev21
Jayesh-Dev21 requested a review from a team as a code owner September 1, 2026 13:26
Copilot AI lite review requested due to automatic review settings September 1, 2026 13:26
@Jayesh-Dev21

Copy link
Copy Markdown
Author

@nekevss Marked this Pr as ready for review. Let me know if there's anything you'd like me to change.
Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new rem_i32_min_by_neg_one test uses assert_eq which treats +0 and -0 as equal, so it doesn’t actually validate the negative-zero behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes an i32 signed-overflow panic in the % fast paths by switching to checked remainder and falling back to f64 arithmetic on overflow, aligning behavior with JavaScript (e.g., producing -0 instead of panicking).

Changes:

  • Replace x % y with x.checked_rem(y) in rem() and rem_fast(), with f64 fallback on overflow.
  • Add regression tests covering i32::MIN % -1 behavior for both the interpreter path and rem_fast().
File summaries
File Description
core/engine/src/value/operations.rs Prevents % overflow panic for i32::MIN % -1 by using checked_rem with f64 fallback and correct -0 sign handling.
core/engine/src/value/tests.rs Adds regression tests for i32::MIN % -1, including a rem_fast() sign-of-zero assertion.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread core/engine/src/value/tests.rs
@jedel1043

Copy link
Copy Markdown
Member

Need to address Copilot's review first; either reject with a reasoning or include the review

@jedel1043 jedel1043 added Waiting On Author Waiting on PR changes from the author and removed Waiting On Review Waiting on reviews from the maintainers labels Sep 4, 2026
…ev#5481)

The fast-path integer remainder (`rem` and `rem_fast`) used bare
`x % y` which panics when `x = i32::MIN` and `y = -1` due to
signed integer overflow. Replaced with `checked_rem`, falling
back to `f64` arithmetic on overflow — the same pattern already
used by `add`, `sub`, `mul`, and `div` in the same file.

Closes boa-dev#5481
@Jayesh-Dev21
Jayesh-Dev21 force-pushed the fix/i32-min-rem-overflow branch from 8b233c4 to b9ff062 Compare September 4, 2026 19:11
@Jayesh-Dev21

Copy link
Copy Markdown
Author

@jedel1043 I have addressed the Copilot review and now switched rem_i32_min_by_neg_one to use assert_with_op with is_sign_negative(), so it properly validates the negative (-) zero sign bit, not just the value. Both rem_i32_min_by_neg_one and rem_fast_i32_min_by_neg_one now use the same approach.

Ready for another look.

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

Labels

C-Tests Issues and PRs related to the tests. Waiting On Author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: i32::MIN % -1 remainder overflow

4 participants