Skip to content

Carry integers past the JavaScript safe-integer ceiling - #27

Merged
bavulapati merged 1 commit into
mainfrom
remove-safe-integer-ceiling
Nov 20, 2026
Merged

bavulapati merged 1 commit into
mainfrom
remove-safe-integer-ceiling

Conversation

@bavulapati

Copy link
Copy Markdown
Contributor

MAX_SAFE_INTEGER mirrored a limit of JavaScript numbers rather than of the format. Python's integers have no such limit, so the corpus holds this port to the format's range, which uint, int and the sized codecs all fell short of.

Three guards go: _validate_safe_uint on both decode paths, _validate_int inside _zigzag, and the upper half of _validate_uint. In their place uint is bounded by its widest form, 2**64 - 1, so an out-of-range encode still raises ValueError; int needs no bound of its own, since zigzag has to fit that same form.

Conformance against compact-encoding-test goes from 166 matched / 8 diverged to 171 / 3, closing int-past-range, int-past-range-min, uint-uint64-top-byte, uint-decode-ceiling and uint56-decode-ceiling. The three left are #18 and #19.

Closes #20.

One deletion to flag. test_narrow_sized_uint_decode_cannot_overflow existed to stop this change - "Pin that reasoning so the guard is not tidied" - so removing it reverses a decision rather than tidying one. The reasoning it pinned was sound for a port whose numbers are doubles; this one's are not. Eight other tests move their bounds from the double ceiling to the width that actually binds.

The ceiling came from what a double holds, not from the wire format, and
Python's integers do not need it. uint is bounded by its widest form instead,
and int by what that form holds after zigzag.

Closes #20.
@bavulapati
bavulapati requested a review from a team November 20, 2026 13:47

@kasperisager kasperisager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

@bavulapati
bavulapati merged commit cbf16ca into main Nov 20, 2026
8 checks passed
@bavulapati
bavulapati deleted the remove-safe-integer-ceiling branch November 20, 2026 15:00
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.

uint and int refuse values past the JavaScript safe-integer ceiling

2 participants