Skip to content

Mode A (_slice_by_labels) generic args-count search is unbounded, can attribute unrelated text to a function's parameter count #1973

Closed

Description

@squid-protocol

Summary

_calculate_block_metrics (gitgalaxy/core/detector.py:4452)'s generic per-function args_count
derivation runs the language's args regex against the entire swept block when no caller
passes args_search_text -- for Mode A (_slice_by_labels, used by cobol/fortran/assembly/
dockerfile after #1972's sibling fix routes it there too), the "block" is the whole greedy span
from one func_start match to the next, which can contain several unrelated instructions/
statements, not just the matched function's own signature.

For a language whose args metric has no real per-function parameter-list concept at all (the
"none" granularity case documented in tri-comparison-ledger-sweep's SKILL.md -- Dockerfile's
RUN/CMD/ENTRYPOINT/HEALTHCHECK don't take formal parameters; ARG is a whole-file build
argument, unrelated to any specific instruction), this means a RUN's reported "Input Parameters"
count can pick up an unrelated ARG declaration that happens to sit between it and the next
RUN/CMD/etc. match, crediting the ARG's presence to a function that structurally cannot have
parameters at all.

Evidence

Surfaced while re-blessing the golden master after fixing dockerfile's Mode B->Mode A routing
(the func_start recall fix itself, tracked separately). Post-fix diff on
language-crucible/data/dockerfile/moby/test_targets/daemon.Dockerfile, several RUN entries in
"5. Function Analysis" now show 'Input Parameters': 2 where the pre-fix baseline (when almost
no real functions were captured at all, via the unrelated Mode B bug) always showed 0:

{'Function Name': 'RUN', ..., 'Start Line': 163, 'End Line': 182, 'Input Parameters': 2, ...}

Real source at that span (daemon.Dockerfile:162-164):

ARG DOCKER_STATIC
RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
    --mount=type=cache,target=/root/.cache/go-build,id=containerd-build-$TARGETPLATFORM <<EOT

The ARG DOCKER_STATIC on line 162 is a file-level build argument, unrelated to this specific
RUN's own (nonexistent) parameter list -- but because Mode A's greedy body for the previous
RUN (line 157) spans forward and swallows line 162's ARG before reaching line 163's RUN, the
generic args_pattern.search(block) call finds it and attributes it as that earlier RUN's
"parameter count."

Why this isn't blocking the routing fix

This is a pre-existing, generic characteristic of _calculate_block_metrics's fallback path
(args_search_text=None -> search the whole block), not something introduced by the routing fix
-- it was already latent for dockerfile under the old (badly broken) Mode B routing too, just
far less visible since Mode B was silently dropping ~74-100% of real functions and coincidentally
zeroing out most of this signal along with them. It's also not specific to dockerfile: cobol/
fortran/assembly share the exact same unbounded-search code path today. Fixing the much larger
func_start recall gap (dockerfile's own tri-comparison manual-verification pass) is a clear,
independent correctness win and shouldn't be blocked on this narrower, pre-existing args-
attribution quirk.

Suggested fix

For languages whose args metric is documented as none/program_level granularity (no real
per-function parameter list -- see the SKILL.md list: dockerfile, yaml, jcl, cobol), either (a)
skip the generic args-count derivation entirely for Mode A callers of those languages (mirroring
how abap/assembly/agc_assembly already get a dedicated args_count_override instead of the
generic path), or (b) bound the search the same way args_sig_end/args_search_text already
bounds Mode B's c/cpp/objc callers -- to just the matched function's own line(s), not the full
greedy span to the next match.

Activity

  1. added
    bug
    core-engine
    testing
    threat: false-positive
    on Aug 21, 2026
  2. added this to the v2.4.9 milestone on Aug 31, 2026
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

    bugcore-enginepriority: mediumtestingthreat: false-positive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions