Skip to content

fix: regex panic on hunk headers without line count #159

Closed

Description

@ajianaz

Bug Description

cora review panics with no group at index '4' when parsing diff hunk headers that omit line counts (e.g., @@ -1 +1 @@).

Evidence

thread 'main' (517534) panicked at regex-1.12.3/src/regex/string.rs:2024:32:
no group at index '4'
zsh: abort      RUST_BACKTRACE=1 cora review --base origin/develop

Trigger: cora review --base origin/develop

Root Cause

src/engine/diff_parser.rs lines 128-130 — direct indexing caps[N] on optional capture groups.

static RE_HUNK_HEADER: LazyLock<Regex> =
    LazyLock::new(|| Regex::new(r"^@@\s-(\d+)(?:,(\d+))?\s\+(\d+)(?:,(\d+))?\s@@\s?(.*)").unwrap());

// PANICS when optional group 2 or 4 didn't participate in match
let old_count: u32 = caps[2].parse().unwrap_or(1);  // line 128
let new_count: u32 = caps[4].parse().unwrap_or(1);  // line 130

Groups (?:,(\d+))? are optional. When git outputs @@ -1 +1 @@ (no ,1), groups 2 and 4 don't participate. Direct caps[N] indexing on non-participating groups panics in the regex crate.

Fix

Use .get(N) for optional groups:

let old_count: u32 = caps.get(2).and_then(|m| m.as_str().parse().ok()).unwrap_or(1);
let new_count: u32 = caps.get(4).and_then(|m| m.as_str().parse().ok()).unwrap_or(1);

Impact

  • Blocks all PRs — Cora Review is a required CI check
  • Affects any diff with single-line hunks (very common)

Activity

  1. changed the title [-]fix: Cora Review CI crash (SIGABRT exit 134) on self-review[/-] [+]fix: regex panic on hunk headers without line count[/+] on Jun 5, 2026
  2. added a commit that references this issue on Jun 5, 2026
    e9ce3ac
  3. added 2 commits that reference this issue on Jun 6, 2026
    2b983d2
    c7d9e11
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions