Expand description
Binary islands reduction, ported from guard_core/detection_engine/ binary_islands.py (upstream commit 5f399234).
A multipart file-part payload whose binary artifact characters fill at least a fifth of it is reduced to its printable runs before pattern scanning: compressed or encrypted upload bytes stop producing attack-shaped matches whose rate grows with file size, while text genuinely embedded in an upload (a script inside a PDF, a stored path inside an archive) forms printable runs past the minimum length and is still scanned in full.
String model: like the binary artifact gate (crate::patterns::binary),
artifact classes are evaluated over decoded code points. Invalid UTF-8
bytes of an engine body surface as U+FFFD at the decode boundary (Python
decodes with surrogateescape, so one binary byte is one surrogate rune
there and one U+FFFD per maximal invalid run here); U+FFFD is part of the
artifact class and is excluded from the printable-run class, so binary
bytes end islands exactly like the surrogateescape range does in Python.
Constants§
- BINARY_
LIKE_ ARTIFACT_ RATIO _BINARY_LIKE_ARTIFACT_RATIO: a payload is binary-like when artifact characters make up at least this fraction of it.
Functions§
- extract_
binary_ islands extract_binary_islands: the maximal printable runs of the content whose code-point length reachesmin_run_length, in order.- printable_
island_ rune - Whether
rbelongs to the island run class_ISLAND_RUN_REfromguard_core/detection_engine/binary_islands.py. - value_
is_ binary_ like value_is_binary_like: the artifact-character ratio of the content reachesBINARY_LIKE_ARTIFACT_RATIO.