Green Tests, Open Bug: Why Patch Benchmarks Overfit

An automated security patch can stop the proof of concept, turn the repository test suite green, and still leave the vulnerability class wide open. A paired Python lab proving why.

Triggering a crash locally is binary: the sanitizer fires or it stays quiet. Fixing the underlying invariant without breaking callers is harder, and the reward signal in most automated repair benchmarks is an incomplete regression suite.

Grade a coding agent strictly on whether the reported proof of concept (PoC) stops crashing and existing unit tests stay green, and it will write the narrowest guard that clears both bars. The PoC fails. The bug class stays open.

Test-Suite Overfitting Lab puts two overfit patches next to real invariant fixes in zero-dependency Python (github.com/ghostintheprompt/test_suite_overfitting_lab).

Two patches that pass the suite and keep the bug

Take a 64-byte frame copy hit with length = 4_000_000_000 (CWE-190, CWE-195). An overfit repair (copy_frame_overfit) adds if length > 64: return error. The 4 GB PoC stops, and the regression suite turns green. Pass length = -1 instead and length > 64 evaluates false; the moment -1 crosses into an unsigned 32-bit length (ctypes.c_uint32(-1).value), it wraps to 4,294,967,295 bytes and reads past the buffer:

def copy_frame_overfit(length: int, payload: bytes, audit_log_path: str | None = None):
    if length > MAX_BUFFER:
        return {"ok": False, "error": "length_exceeds_64"}
    unsigned_len = ctypes.c_uint32(length).value
    if unsigned_len > MAX_BUFFER:
        return {"ok": False, "crashed": True, "error": f"heap_overflow_read:{unsigned_len}_bytes"}

Path sanitization fails the same way (CWE-22). Hit a file loader with ../../etc/passwd and an overfit patch (resolve_path_overfit) strips ../ in a single pass with user_path.replace("../", ""). The original PoC is neutralized. Send ....//secrets/key and the single pass strips the middle ../, collapsing the remainder right back into ../secrets/key.

Enforcing domain invariants instead of blocking the PoC

The fix in both cases defines the valid domain rather than pattern-matching the exploit input:

  • Two-sided integer domain bounds (copy_frame_invariant): Reject booleans and non-integers upfront (if isinstance(length, bool) or not isinstance(length, int)), then enforce 0 <= length <= MAX_BUFFER before any cast or slice.
  • Canonical path containment (resolve_path_invariant): Stop deleting substrings. Resolve the candidate path canonically ((root_resolved / user_path).resolve()) and check candidate.is_relative_to(root_resolved).
  • Variant-probe telemetry (detect/rule.py): Score emitted JSONL boundary events with OVF-001 (length < 0 or length > 64) and OVF-002 (.. or nested ..../ sequences) so mutated follow-up probes surface in logs even after the invariant blocks them.

Naive regression vs. adversarial variants

Running make test runs both the benchmark-style regression check (where the overfit patch passes on the original PoC) and the variant suite that breaks it:

Probe                            | Overfit Patch  | Invariant Fix
------------------------------------------------------------------
Original PoC (len=4GB)           | BLOCKED        | BLOCKED
Signed Int Variant (len=-1)      | CRASHED        | BLOCKED
Nested Traversal (....//)        | ESCAPED        | CONTAINED
Ran 3 tests in 0.001s (OK)

The lab models unsigned 32-bit wraparound in Python through ctypes.c_uint32 rather than compiling a C target, isolating the exact logic gap that inflates pass rates on automated patch benchmarks.

GhostInThePrompt.com // A green test suite proves the PoC stopped, not that the invariant held.