Expand description
Binary artifact density gate and binary-content heuristic, ported from
guard_core/detection_engine/binary_prefix.py and semantic.py
(looks_like_binary_content).
String-model mapping: the reference scans decoded text where undecodable
bytes surface as surrogateescape code points (U+DC80..U+DCFF) and mojibake
as U+FFFD; both classes count as artifacts. The engine scans &str (always
valid UTF-8), so undecodable bytes never reach this module as surrogates;
the port’s decode boundary represents them as U+FFFD (or drops them), which
is an artifact class here. The surrogate branch is kept for parity with the
reference class definition but is unreachable for char. All window
arithmetic runs on code-point indices, the same index space the corpus
mandates for threat positions.
Functions§
- build_
binary_ prefix - Cumulative artifact-count prefix:
counts[i]= artifacts ins[..i]. Built over code points; indexing is by code-point index (the same space the structural matchers and threat positions use). - looks_
like_ binary_ content looks_like_binary_contentfrom semantic.py.- match_
is_ binary_ density