Skip to content

LargeInt silently truncates oversized integer inputs #134

@Ryang-21

Description

@Ryang-21

Describe the bug
LargeInt implementation silently truncates oversized integer inputs instead of validating that the input fits the target bit-width. When a caller constructs an XDR integer backed by LargeInt (e.g., i64, u64, i128, u128, i256, u256) with a value that exceeds the allowed width (for example, a 300-bit bigint for an i256), LargeInt discards the high bits and keeps only the low bits. No error is thrown and the resulting XDR is valid—but it represents a different value than the one provided.

What version are you on?
v3.1.2

To Reproduce
Steps to reproduce the behavior:

  1. Create a Hyper which is sized at 64 bits and give it a number larger than i64/u64
  2. Call .toString() or toBigInt() on the instance created and observe that the returned value will be the input - i64/u64 max

Expected behavior
LargeInt should be responsible for enforcing correctness: when constructing/encoding a fixed-width XDR integer, it should validate the input’s magnitude/bit-width and throw (or otherwise fail loudly) if the value does not fit. Silent truncation should not occur by default for fixed-width integer types.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions