Skip to content

fix(id/tuple): decode range-checks negative ints, rejects NaN and non-minimal ints (#1610) - #1746

Merged
dezren39 merged 1 commit into
mainfrom
queue/1851-1610-tuple-decode
Oct 28, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/1851-1610-tuple-decode

Conversation

@dezren39

@dezren39 dezren39 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #1610 (per triage task 1711, verdict CONFIRMED; implementation queue task 1851).

decode_one in pkgs/id/src/tuple.rs admitted three classes of encodings the encoder can never produce:

  1. Negative-int branch had no range check (the positive branch has one): magnitude 0 decoded to Int(0), and a magnitude above 2^63 wrapped through 0u64.wrapping_sub(abs) to a zero or positive value (u64::MAX → Int(1)).
  2. FLOAT64 branch admitted NaN: the encoder's float() refuses NaN, but a crafted payload reversing to NaN decoded happily.
  3. Non-minimal int encodings (redundant leading bytes) decoded as a second spelling of a key the encoder writes minimally.

Change (decode only — the encoder and all on-disk/document encodings are byte-identical):

  • Negative branch mirrors the positive branch's discipline: magnitude must be in 1..=2^63; 2^63 itself stays legal — it is i64::MIN, with a boundary test (crafted payload + encoder round-trip).
  • FLOAT64 branch refuses a value that is NaN after reversing the sort transform. Infinities stay decodable (they encode), with a test.
  • Non-minimal ints are rejected in both sign branches — the pinned behaviour triage asked for (reject, for symmetry with the range checks): a positive payload's first byte must be non-zero (this also refuses an int-tagged zero; zero has the ZERO tag), and a negative payload's first byte must not be 0xFF (magnitude's top byte non-zero). Documented in branch comments.

Tests: new unit tests for each refusal, the i64::MIN boundary, and infinity. Existing tuple tests unchanged. Verification: CI on this PR (cargo test for the id crate).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…-minimal ints (#1610)

decode_one admitted encodings the encoder can never produce: negative magnitudes of 0 (decoded to Int(0)) or above 2^63 (wrapped to zero/positive), FLOAT64 payloads reversing to NaN, and non-minimal int spellings with redundant leading bytes. Add the mirror range check (1..=2^63, so i64::MIN stays legal), a NaN refusal after the sort transform, and reject non-minimal ints in both sign branches. No encoder change; tests cover each refusal plus the i64::MIN boundary and infinity staying decodable.
@dezren39
dezren39 requested a review from a team as a code owner October 28, 2026 17:24
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 95312fe7-0fa4-4a55-b4ef-c4fcc0b6b118
Commits

Reviewing files that changed from the base of the PR and between f6760a6 and b85a58e.

Files selected for processing: 1
  • pkgs/id/src/tuple.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T17:26:00.693383Z b85a58e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

id(tuple): decode accepts negative ints that wrap to zero/positive and NaN floats — the negative branch has no range check, unlike the positive branch

1 participant