Skip to content

Bigint silent truncation#135

Merged
Ryang-21 merged 10 commits intomasterfrom
bigint-silent-truncation
Mar 5, 2026
Merged

Bigint silent truncation#135
Ryang-21 merged 10 commits intomasterfrom
bigint-silent-truncation

Conversation

@Ryang-21
Copy link
Contributor

@Ryang-21 Ryang-21 commented Mar 2, 2026

What

This fixes silent truncation that occurred when encoding LargeInt by checking that the bytes to be encoded are of the appropriate size. This is necessary as the BigInt.asUintN and BigInt.asintN methods truncate the higher bits when they exceed the provided size param given to the function.

Validation

Tests were added to check functionality at the max and min bounds of the sized integer. Values that are beyond the bounds were tested to throw.

@Ryang-21 Ryang-21 requested review from Shaptic and Copilot and removed request for Copilot March 2, 2026 20:02
@Ryang-21 Ryang-21 linked an issue Mar 2, 2026 that may be closed by this pull request
@Ryang-21 Ryang-21 requested a review from quietbits March 2, 2026 20:02
Copy link

@quietbits quietbits left a comment

Choose a reason for hiding this comment

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

I'm not super familiar with this repo, but the update looks OK to me.

Copilot AI review requested due to automatic review settings March 4, 2026 00:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses silent truncation when encoding/constructing LargeInt-backed integers by introducing explicit range checks (instead of relying on BigInt.asUintN/asIntN, which truncate) and expanding unit coverage around overflow/underflow behavior.

Changes:

  • Tighten LargeInt read/write + isValid to respect signedness and enforce [MIN_VALUE, MAX_VALUE].
  • Update bigint assembly logic to validate slice inputs (preventing per-slice truncation) and to fast-fail on single-value overflow/underflow.
  • Add unit tests for overflow/underflow for Hyper/UnsignedHyper, and add a new 128-bit LargeInt test suite.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/large-int.js Read/write paths updated to handle signed 64-bit reads correctly and to enforce range checks; isValid now validates range.
src/bigint-encoder.js Adds single-value bounds validation and slice-fit assertions to prevent silent truncation during assembly.
test/unit/bigint-encoder_test.js Adds tests for slice overflow/underflow and exact boundary acceptance.
test/unit/hyper_test.js Adds overflow/underflow construction tests for signed 64-bit Hyper.
test/unit/unsigned-hyper_test.js Adds overflow/underflow construction tests for unsigned 64-bit UnsignedHyper.
test/unit/large-int-128_test.js New coverage for >64-bit LargeInt paths including construction, read/write, and isValid.
CHANGELOG.md Documents the truncation fix in Unreleased notes (but see review comments re: accuracy/formatting).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +20



Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

There are multiple consecutive blank lines added after this bullet, which introduces unnecessary whitespace in the Unreleased section. Consider removing the extra empty lines to keep the changelog formatting consistent.

Copilot uses AI. Check for mistakes.
Ryang-21 and others added 3 commits March 5, 2026 14:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: George <Shaptic@users.noreply.github.com>
@Ryang-21 Ryang-21 merged commit 1ff2ba5 into master Mar 5, 2026
2 checks passed
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.

LargeInt silently truncates oversized integer inputs

4 participants