fix(bigint): canonicalize from_octets with leading zero limbs#3835
Open
hyfdev wants to merge 1 commit into
Open
fix(bigint): canonicalize from_octets with leading zero limbs#3835hyfdev wants to merge 1 commit into
hyfdev wants to merge 1 commit into
Conversation
hyfdev
marked this pull request as ready for review
July 18, 2026 19:38
hyfdev
marked this pull request as draft
July 18, 2026 19:39
hyfdev
marked this pull request as ready for review
July 18, 2026 19:46
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.
Closes #3809.
Problem
BigInt::from_octetsonly removed one zero most-significant limb. Inputs with more than one zero limb retained an invalid logical length, so non-JS backends could compare equal values incorrectly. An all-zero multi-limb input could also form a negative zero and maketo_stringpanic.Fix
Use the existing
normalize_lenhelper to compute the canonical logical length after constructing the limbs.Tests
Extend the existing whitebox
from_octetscoverage with the issue input and multi-limb zero inputs for both default and negative signums. Each case checks the internal invariant plus string, equality, and comparison behavior.Validation
moon check --deny-warn --target allmoon test --target allmoon test --release --target js,wasm,wasm-gcmoon test --target native --releasemoon info --target wasm,wasm-gc,js,native(no interface diff)moon fmt --checkmoon bundle --all