Repository navigation
Description
Two scanner defects found while landing #833 (the Zig 0.16 migration). Both are
false positives on correct code, and both push authors toward making the
code worse to satisfy the tool.
1. RE005 matches || true inside comments
lib/rules/research_extensions.ex:608:
has_or_true? = Regex.match?(~r/\|\|\s*true\b/, body)body is the raw step body. Comments are not stripped, so a step is
flagged for text that never executes.
It fired on #833 against a step whose comment explains why it deliberately
uses awk instead of grep with a suppressed exit code:
workflow .github/workflows/zig.yml:111 step `Run the Zig tests`
swallows non-zero exit via `|| true` — failures will be masked
The step contains no || true. The detector matched the prose arguing
against the thing it was looking for.
This is the [guard asking a different question than its consumer] shape: the
rule asks "does the text || true appear" when the question is "does this
step swallow a failure".
⚠ It also creates exactly the wrong incentive. The cheapest way to clear the
alert is to delete the comment explaining why the step is safe — so the rule
rewards removing the documentation of a correct decision.
The same codebase already knows this. lib/rules/cicd_rules.ex:938 strips
comments for precisely this reason, with the comment "because a commented-out
line needs no hypatia:ignore", and lib/rules/code_safety.ex:1021-1053
implements per-language comment stripping for Rust, Idris2, Haskell, Coq,
Isabelle, HOL4 and F*. RE005 is the inconsistent one.
Acceptance criteria
- RE005 strips YAML
#comments from the step body before matching. - It also honours a
hypatia:ignore RE005 -- <reason>pragma, consistent
with the other rules. - A regression fixture proves both directions: a step with a real
|| truestill fires, and a step whose only occurrence is in a comment
does not. A fixture covering only the second is how a rule gets disabled
by accident. -
continue-on-error: truein a comment gets the same treatment — it is
matched by the same function and has the same defect. - The zig.yml comment reworded in fix(ffi/zig): migrate to the Zig 0.16 std, then gate it — tests, C ABI exports, and the version pin (#812, #813, #696) #833 can be restored to its natural
wording without re-firing.
2. zig_ptr_cast / zig_align_cast flag the mandatory opaque-handle idiom
lib/rules/code_safety.ex:354-366 matches bare ~r/@ptrCast/ and
~r/@alignCast/ at severity :high (CWE-704).
In ffi/zig/src/main.zig these appear as:
fn state(handle: *Handle) *HandleState {
return @ptrCast(@alignCast(handle));
}That is the way to implement an opaque C handle in Zig: C sees an opaque
pointer, the state lives behind it, and recovering it requires exactly this
cast. There is no safe alternative — an opaque handle is the whole point, and
the six normative ABI functions in src/Hypatia/ABI/FFI.idr depend on it.
Flagging it as an unchecked conversion is true in the abstract and useless
here.
Two sub-defects make it worse:
- No Zig comment stripping.
code_safety.exstrips comments for Rust,
Idris2, Haskell, Coq, Isabelle, HOL4 and F*. Zig is not in the list, so a
// use @ptrCast heredoc comment would also fire. - Reported at
main.zig:1, not at the real line, so the annotation points
at the file rather than the cast. That also appears to be why GitHub counted
only 1 new alert on a PR that introduced two of these.
Acceptance criteria
- Zig
//and///comments are stripped before these patterns match. - The alert reports the actual line, not line 1.
- A suppression path exists with a stated reason — either
hypatia:ignore zig_ptr_cast -- <reason>honoured in.zig, or the
opaque-handle recovery pattern recognised and exempted. -
ffi/zig/src/main.zigis clean afterwards without changing the cast.
If the rule can only be satisfied by altering correct ABI code, the rule
is wrong, not the code. - Both directions fixtured: a genuinely unchecked
@ptrCaststill fires.
Why this is an issue and not a fix in #833
Per the standing ruling, a new scanner finding is an issue with acceptance
criteria rather than a merge blocker. #833 reworded its comment so the PR is
not left red on a false positive, and deliberately did not touch the
@ptrCast, which is correct as written.
Activity
fix(governance): green the Validate Hypatia Baseline gate on main (#856)
fix: address the open issue set — CI truth, proof gates, scanner prec…