Skip to main content

Module binary_islands

Module binary_islands 

Source
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 reaches min_run_length, in order.
printable_island_rune
Whether r belongs to the island run class _ISLAND_RUN_RE from guard_core/detection_engine/binary_islands.py.
value_is_binary_like
value_is_binary_like: the artifact-character ratio of the content reaches BINARY_LIKE_ARTIFACT_RATIO.