Skip to content

id(range-sync): Reader::varint accepts overlong encodings in all three positions — one flight has many wire spellings, the duplicate-spelling property tuple decoding already refuses #2596

Closed

Description

@dezren39

Problem

The range-sync decoder accepts non-canonical (overlong) varints in every varint position, so one message has many wire spellings — the exact duplicate-spelling property this codebase's tuple decoder already refuses for integers and floats.

Evidence (pkgs/id/src/event_store/range.rs, main 3a42555):

  • put_varint (lines ~400–408) always emits the minimal encoding: it stops as soon as the remaining value fits in one byte.
  • Reader::varint (lines ~497–508) accepts any encoding of up to 5 bytes whose final byte is under 0x80 — including overlong forms with leading zero groups (e.g. 0x81 0x00 for 1, or a 5-byte encoding of 5). It never checks that a multi-byte encoding was necessary.
  • The varint positions are: the frame entry count (decode_frame / frame_entry_count), the Fingerprint count, and the IDs count (Reader::entry).
  • Contrast in the same crate: tuple decoding rejects a second spelling on purpose — "The encoder emits the minimal byte count, so a leading zero payload byte … is an encoding no encoder produces. Reject it rather than accept a second spelling of the same key" (src/tuple.rs, positive-int branch; the negative-int and float branches do the same, and the float branch rejects the -0.0 stored form for the same reason — see id(tuple): decode admits the -0.0 stored form the encoder can never produce — phantom key sorts as negative, decodes equal to 0.0 #2421).

Verified this run (laptop probe, real crate, main 3a42555)

Probe: ~/git/fleet/probe-2026-10-30-laneA-rangeenc/ (id path dependency, default-features off):

  • Canonical frame [more=0, count=0x01, entry(len 0, mode 0 Skip)] → decode_frame Ok, 1 entry.
  • Same frame with the count overlong-encoded as 0x81 0x00 → decode_frame Ok, 1 entry. Identical message, second spelling.
  • A Fingerprint entry whose count 5 is overlong-encoded as the 5-byte 0x85 0x80 0x80 0x80 0x00 → decode_frame Ok, 1 entry.

Why it matters

/id-range-sync/1 flights are the reconciliation wire format between peers that may run different builds. A decoder that accepts spellings no encoder produces makes byte-equality useless for comparing flights (dedup, transcript logs, test vectors, any future flight hashing/signing), and hides peer encoder bugs behind silent acceptance — the same reasoning the tuple decoder already applies. It also leaves the 5-byte cap doing double duty: a 5-byte varint can carry 35 bits, so non-canonical forms smuggle values the field widths never intended (the Fingerprint count narrows to u32 afterwards; the IDs count and frame count are used as usize loop/allocation drivers first).

Acceptance criteria

  • Reader::varint rejects a non-minimal encoding (a multi-byte varint whose value fits in fewer bytes), in all three positions: frame entry count, Fingerprint count, IDs count.
  • Tests: minimal encodings at each width boundary (0x7F, 0x80, 0x3FFF, 0x4000) still decode; overlong forms of the same values are refused in each position.
  • Existing range.rs tests stay green.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/xsTrivial: expected under 30 minutes of work
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  5. 23 remaining items

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 1, 2026
  7. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

    • Agent: repo-worker-code (OpenChamber scheduled lane)
    • Session / ID: OpenCode scheduled lane 2026-11-01; queue task 5399
    • Reason: Added required 0x3fff / 0x4000 minimal and overlong cases at PR head 4ecb5513b. The previous run's range suite passed 18/18 at 98ab5efcc, but that does not cover the added assertions. The targeted rerun was canceled when the server restarted; its log /tmp/5399-lane-test-final.log contains compile output only, no test result.
    • Resume when: task is claimable after the park delay; revalidate PR id(range-sync): reject non-minimal varints in Reader::varint (#2596) #3470 and rerun the targeted range test on 4ecb5513b before merging. Existing worktree: ~/git/fleet/5399-2596-varint.
  8. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 1, 2026
  9. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up — resuming at implementation_complete

  10. added a commit that references this issue on Nov 1, 2026
  11. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — fixed and merged

    • Agent: queue worker (repo-worker-code), lane A
    • Session / ID: queue task 5399, lane A shift 2026-11-01 05:24 CST (resumed from a prior lane's implementation_complete checkpoint)
    • State: DONE (fixed_merged). PR id(range-sync): reject non-minimal varints in Reader::varint (#2596) #3470 merged as 628c06ac85501e28c28341d2ab517e6b6aa3998d; this issue auto-closed by the merge.
    • What changed: Reader::varint in pkgs/id/src/event_store/range.rs now refuses a multi-byte varint ending in a zero payload group — the only non-minimal base-128 spelling — so the frame entry count, Fingerprint count, and IDs count each have exactly one wire spelling, matching put_varint. (Implementation by the prior lane at 98ab5efcc; boundary coverage added at 4ecb5513b.)
    • Verification: cargo test --offline --lib event_store::range on the laptop at head 4ecb5513b: 18 passed / 0 failed, including test_varint_refuses_non_minimal_encodings with the 0x3fff (2-byte accept / 3-byte refuse) and 0x4000 (3-byte accept / 4-byte refuse) width-boundary assertions and overlong refusals at all three wire positions. Codex review completed at the implementation head with no findings; the final head is test-only (+4 assertions). PR was MERGEABLE/CLEAN at merge.
    • Links: PR id(range-sync): reject non-minimal varints in Reader::varint (#2596) #3470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions