Skip to content

Type-design: BlockBoundsKind comparator-direction unification #135

@r6e

Description

@r6e

Source

Adversarial Phase 1 type-design audit (H3).

Problem

BlockBoundsKind payload (observed: u64, limit: u64) is comparator-direction-blind, encoding a hidden bidirectional contract:

  • StartOverlapsHeader: emitted when abs_start < payload_startobserved=abs_start, limit=payload_start (limit is lower bound, not upper)
  • EndPastFileSize: emitted when abs_end > file_sizeobserved=abs_end, limit=file_size (limit is upper bound)

limit means opposite things in the two variants. A consumer writing if observed > limit { ... } is wrong half the time. OffsetPastFileSize's sibling at error.rs:644-660 got the same shape but with both subkinds being upper bounds (>= and >both upper), so it got away with it; this one didn't.

Fix

Either:

  • Rename to bound: BlockBoundsBound carrying Lower(u64) | Upper(u64), OR
  • Split the (observed, limit) into per-variant fields with directional names (block_start, payload_start_min, block_end, file_size_max).

Files

  • crates/paksmith-core/src/error.rs:665-676
  • crates/paksmith-core/src/container/pak/mod.rs:687-705, 1184-1203 (call sites)
  • crates/paksmith-core/src/error.rs:1000-1008 (Display impl)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtype-designType system improvements: invariants, encapsulation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions