Repository navigation
Conversation
The wasm-backed signed division short-circuits and returns the dividend unchanged whenever this.high === 0x80000000 and the divisor is -1. That guard is meant to catch only the true two's-complement overflow of MIN_VALUE / -1, but it omits the low-word check, so any negative dividend sharing that high word (for example -9223372036854775807) is wrongly returned unchanged instead of being negated. Add this.low === 0 so only the exact MIN_VALUE / -1 overflow is special cased; every other value falls through to wasm.div_s. This matches the non-wasm path, which guards on this.eq(MIN_VALUE).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resubmits the fix and regression tests from #138, which was automatically closed as stale without being merged. The original commit author is preserved.
The WASM signed division overflow guard currently checks only the high word of the dividend. Negative values near MIN_VALUE are therefore returned unchanged when divided by -1:
Require
this.low === 0as well, so only the exact MIN_VALUE / -1 overflow wraps. Other values proceed to WASM division, consistent with the JS path.The regression covers two affected negative values and verifies that the exact MIN_VALUE / -1 overflow still wraps to MIN_VALUE.
Validation (Node 22.13.0):
npm run buildnpm test(unit tests, Closure library tests and all four TypeScript configurations)npm run lint