fix(utilities): lossless guard + unsigned BigInt parser - #58
Open
klodr wants to merge 1 commit into
Open
Conversation
`toCppIntegerB` called `BigInt::Int64Value(&lossless)` but never checked the `lossless` flag. A BigInt outside the int64_t range (e.g. bit 63 of a uint64 accidentally set on the JS side) silently wrapped — the helper documented as a parser was acting as a truncating cast. Throw on `!lossless`. `toCppIntegerB` is also the wrong parser for fields the C++ side stores as uint64 (bitsets, profile flags): a NEGATIVE BigInt (-1n) is lossless as int64 and wraps to 0xFFFFFFFFFFFFFFFF when assigned to a uint64 destination — the same high-bit injection the lossless check was supposed to block. Add a dedicated `toCppUnsignedIntegerB` (and matching optional wrapper `maybeNonemptyUintB`) that rejects negative BigInts via `BigInt::ToWords()` sign-bit inspection BEFORE the `Uint64Value` conversion. Callers that need to store into uint64 should migrate to the unsigned variant in a follow-up commit; this change only adds the helpers + tightens the existing int64 helper. No behaviour change on the existing call sites unless they pass a BigInt outside int64 range, in which case they were already storing the wrong value. Signed-off-by: Claude Perrin <klodr@users.noreply.github.com>
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.
Adds a
losslessguard ontoCppIntegerB(rejects silent truncation past int64 range) and a newtoCppUnsignedIntegerB/maybeNonemptyUintBpair that uses BigInt::ToWords to detect the sign bit (so a JS-1ndoesn't silently wrap to0xFFFFFFFFFFFFFFFFwhen assigned to a uint64 field like a bitset).Test plan
toCppUnsignedIntegerBthrows on negative BigInttoCppIntegerBthrows on values outside int64 range