Skip to content

id(didit): entity aliases and expectation hours spans have no count cap — the encoder produces bodies the decoder's 8192-element limit refuses #5991

Closed

Description

@dezren39

Summary

pkgs/id/src/didit/body.rs can encode did-it bodies that its own decoder refuses: two collections have no count cap in check(), so they can exceed the CBOR decoder's per-array element limit. A body this code writes is then unreadable by itself and by every peer — the module's stated contract ("a body that decodes is a body that would re-encode to itself", and encoders/decoders applying the same shape rules) only holds in one direction.

Evidence (verified this run, laptop primary @ ec2ac0e8eb)

  • The decoder is configured with a declared-element limit: top_level() (body.rs:873-895) decodes with DecodeOptions … .length_limit(LENGTH_LIMIT) where const LENGTH_LIMIT: u64 = 8192 (body.rs:63, "Declared element limit for one array, map, or string").
  • The model checks cap the collections the authors remembered: check_subjects refuses more than MAX_SUBJECTS = 512 (body.rs:54, 839-858) and Record::check refuses more than MAX_DETAILS = 512 details (body.rs:57, 253-258). The sibling CBOR modules do the same: idset.rs caps MAX_ENTRIES = 4096 against the same 8192 decoder limit, and chain.rs caps MAX_AFTER = 32 against its 512 limit.
  • But Entity::check (body.rs:96-110) validates each alias's text and rejects duplicates — with no cap on the alias count — and ActiveWindow::check / HoursSpan::check (body.rs:399-430, 453-500) validates each span's minutes/days with no cap on the span count. Nothing else bounds these counts before check_size (which only caps total bytes at MAX_BODY_BYTES = 1 MiB, body.rs:816-821).
  • Probe (laptop, ~/git/fleet/probe-didit-aliases, real id crate @ ec2ac0e8eb, cargo run --release):
    • Entity with 8,193 distinct aliases (a0…a8192): encode_entity_body → Ok, 48,143 bytes (well under the 1 MiB cap); decode_entity_body on those exact bytes → Err DiditError::Cbor("the did-it body is not CBOR: length exceeds reasonable size") — the decoder's length limit refusing the array the encoder just wrote.
    • Control at the limit, 8,192 aliases: encodes (48,137 bytes) and decodes Ok — the failure is exactly the 8,192 element boundary, not size or content.
    • Expectation with 8,193 identical hours spans (420→1320, days None): encode_expectation_body → Ok, 65,689 bytes; decode_expectation_body → Err, same Cbor length error.
    • Normal control (entity with 1 alias): encodes and decodes Ok.

Why it matters

encode_entity_body / encode_expectation_body are the write path for did-it events (#2031 tracker, body persistence in #4837). An entity with many aliases (importers and household merges are the realistic source — an entity accumulates aliases over its life) or an expectation with many active-hours spans can be constructed, pass check(), encode, and be signed/published — and then no decoder in the fleet can read it back, including the writer's own store on the next load. That is a self-inflicted unreadable event in an append-only log: it cannot be repaired by editing, only by superseding events that themselves reference data peers cannot decode. The caps exist for exactly this reason on subjects/details; aliases and hours spans were simply missed.

The fix direction (for triage to confirm): add explicit count caps for entity aliases and hours spans in check() — sized like the sibling caps (well under the 8192 decoder limit, e.g. in line with MAX_SUBJECTS/MAX_DETAILS) — with tests pinning that a body at the cap round-trips and one over the cap is refused at encode time with a named DiditError::Invalid, rather than producing an undecodable body.

Acceptance criteria

  • Entity::check (and therefore both encode_entity_body and decode_entity_body) refuses an entity whose alias count exceeds a named maximum, with the error naming the count and the limit — mirroring check_subjects / the details cap.
  • ActiveWindow::Hours checking refuses an expectation whose hours-span count exceeds a named maximum, same error shape.
  • Pinning tests: an entity/expectation exactly at each new cap encodes and round-trips through its decoder; one over the cap is refused by encode_*_body (this is the regression test for this issue — pre-fix the over-cap bodies encode successfully and fail decode).
  • Existing didit tests stay green: cargo test -p id --lib didit on the laptop or in CI.
  • A sweep of the other didit body collections confirms no remaining uncapped Vec field can exceed the decoder's 8192 element limit under the 1 MiB body cap (subjects, details, about, days are already bounded — see the issue body).

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/normalOrdinary priority (the default)
    on Nov 5, 2026
  2. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  3. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B, slug new-issue-creator-code-b)
    • Session / ID: cron job new-issue-creator-code-b, run 2026-11-04 22:50 CST
    • Found via: filed this run
    • Task: Cap the two uncapped didit body collections (entity aliases, expectation hours spans) so encode_*_body can never produce a body the decoder's 8192-element limit refuses; pin the boundary with round-trip tests.
    • Expectation: effort s; done = a named count cap in Entity::check / ActiveWindow::check mirroring the subjects/details caps, at-cap bodies round-trip, over-cap bodies refused at encode with a named error, cargo test -p id --lib didit green.
    • Links: body/evidence in this issue; probe ~/git/fleet/probe-didit-aliases (laptop); queue packet enqueued this run to repo-health-code-pilot.
  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. 17 remaining items

  8. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 5, 2026
  9. added a commit that references this issue on Nov 5, 2026
  10. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions