Skip to content

fix(bigint): canonicalize from_octets with leading zero limbs#3835

Open
hyfdev wants to merge 1 commit into
moonbitlang:mainfrom
hyfdev:moonbit-core/3809-from-octets
Open

fix(bigint): canonicalize from_octets with leading zero limbs#3835
hyfdev wants to merge 1 commit into
moonbitlang:mainfrom
hyfdev:moonbit-core/3809-from-octets

Conversation

@hyfdev

@hyfdev hyfdev commented Jul 18, 2026

Copy link
Copy Markdown

Closes #3809.

Problem

BigInt::from_octets only 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 make to_string panic.

Fix

Use the existing normalize_len helper to compute the canonical logical length after constructing the limbs.

Tests

Extend the existing whitebox from_octets coverage 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 all
  • moon test --target all
  • moon test --release --target js,wasm,wasm-gc
  • moon test --target native --release
  • JS builtin string tests on wasm-gc in debug and release
  • moon info --target wasm,wasm-gc,js,native (no interface diff)
  • moon fmt --check
  • moon bundle --all

@hyfdev
hyfdev marked this pull request as ready for review July 18, 2026 19:38
@hyfdev
hyfdev marked this pull request as draft July 18, 2026 19:39
@hyfdev
hyfdev marked this pull request as ready for review July 18, 2026 19:46
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.

[BUG] BigInt::from_octets with leading zero limbs produces an incorrectly ordered value

1 participant