Skip to content

Replace expect() in shipped hot paths (parser.rs ×157, string.rs, measure_depth.rs) — CWE-754 #94

Closed

Description

@hyperpolymath

Hypatia code_safety/expect_in_hot_path (CWE-754) on PR #92 (pre-existing; advisory flag, non-blocking):

File Occurrences
crates/my-lang/src/parser.rs 157
crates/my-lang/examples/measure_depth.rs 2
crates/my-lang/lib/common/string.rs 1

expect() on a hot path panics on malformed input instead of returning a recoverable error. The parser is the worst offender (157) and is exactly where untrusted input lands.

Action

  • Convert hot-path expect() to Result-returning error handling (or document a genuine invariant where panicking is correct, and exempt that site in .hypatia-ignore with rationale).
  • Prioritise parser.rs.

Tracked in STATE.a2ml [blockers-and-issues] expect-hot-path.

https://claude.ai/code/session_01BwV2DWsjkBiNP3oscimMLV

Activity

  1. added
    tech-debt
    on Jun 5, 2026
  2. hyperpolymath commented on Jul 29, 2026

    @hyperpolymath
    OwnerAuthor

    Consolidated into #145 — closing as duplicate.

    #145 covers the same three sites (parser.rs ×157, string.rs ×1, measure_depth.rs ×2) plus the unwrap_without_check debt this issue didn't cover (my-fmt ×26, my-llvm ×3, my-mir ×5), and it is the issue referenced by all 7 entries of .hypatia-baseline.json (PR #146) — so the baseline's expiry (2026-10-27) and this debt now track in one place.

    One correction carried over from the triage: the parser.rs ×157 count is a scanner false positive by name collision. Those hits are the parser's own self.expect(TokenKind) -> Result<...> method, not Option/Result::expect panics — grep for \.expect(" returns nothing in that file. So the "worst offender / exactly where untrusted input lands" framing here does not hold; the parser already returns recoverable errors. An upstream hypatia rule fix (disambiguate method-call expect from the panicking one) is the real action.

    Genuine remaining debt is enumerated in #145.

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

    code-safetytech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions