Skip to content

Commit 224ba29

Browse files
authored
fix(analyzer): distinguish format-only opaque references in AE1 (NVIDIA#597)
* test(analyzer): capture unsupported-format AE1 regression Signed-off-by: Christopher Kevin <[email protected]> * fix(analyzer): preserve reasons when classifying reference coverage Signed-off-by: Christopher Kevin <[email protected]> * fix(analyzer): harden format-only reference coverage Signed-off-by: Christopher Kevin <[email protected]> * fix(analyzer): retain AE1 for unknown opaque targets Signed-off-by: Christopher Kevin <[email protected]> * fix(analyzer): verify passive PNG references Signed-off-by: Christopher Kevin <[email protected]> * fix(ae1): require passive image references Signed-off-by: Christopher Kevin <[email protected]> * fix(references): preserve rendered list images Signed-off-by: Christopher Kevin <[email protected]> --------- Signed-off-by: Christopher Kevin <[email protected]>
1 parent eca8df3 commit 224ba29

11 files changed

Lines changed: 2393 additions & 50 deletions

‎docs/ANALYSIS_RESOURCE_BOUNDS.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ Truncated extraction and missing or ambiguous local references are explicit part
8686
conditions. A referenced binary, opaque, or otherwise uninspected artifact is not treated as a
8787
successfully analyzed reference.
8888

89+
AE1 is suppressed only for a positively identified rendered Markdown image whose complete
90+
bytes verify as a minimal, non-interlaced PNG and whose canonical inspection evidence has
91+
only unsupported-format limitations. Active, ambiguous, escaped, code, and missing-kind
92+
references retain AE1, as do non-PNG formats, executable or concealed content, other failures,
93+
unknown reasons, and mixed limitations. Suppression leaves the coverage exception, coverage
94+
metrics, incomplete-scan recommendation, and `--fail-on-incomplete` behavior unchanged. Such
95+
an image-only limitation may report LOW severity while still recommending `CAUTION` because
96+
the scan remains incomplete.
97+
8998
## Structured skill data
9099

91100
AISOP/AISP structured extraction consumes the already-bounded cache and shares the enclosing

‎src/skillspector/artifacts.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ class ArtifactDisposition(StrEnum):
4343
OUT_OF_SCOPE = "out_of_scope"
4444

4545

46+
class ReferenceKind(StrEnum):
47+
"""Syntactic use that produced one intra-bundle reference."""
48+
49+
MARKDOWN_IMAGE = "markdown_image"
50+
MARKDOWN_LINK = "markdown_link"
51+
INLINE_COMMAND = "inline_command"
52+
QUOTED_OR_CODE = "quoted_or_code"
53+
PLAIN_PATH = "plain_path"
54+
55+
4656
class ArtifactRecord(TypedDict):
4757
"""Serializable inventory row for one discovered bundle artifact."""
4858

@@ -68,6 +78,7 @@ class BundleReference(TypedDict):
6878
target_path: str | None
6979
status: str
7080
disposition: ArtifactDisposition
81+
reference_kind: ReferenceKind
7182

7283

7384
@dataclass(frozen=True)
@@ -184,6 +195,7 @@ class _ObfuscatedIgnoreState:
184195
b"\x7fELF",
185196
b"MZ",
186197
b"\x00asm",
198+
b"\x1bLua",
187199
b"%PDF-",
188200
)
189201

@@ -198,9 +210,11 @@ class _ObfuscatedIgnoreState:
198210
".gz",
199211
".exe",
200212
".dll",
213+
".dex",
201214
".so",
202215
".dylib",
203216
".wasm",
217+
".luac",
204218
".pyc",
205219
".class",
206220
".mp3",
@@ -326,10 +340,15 @@ def _suffix(path: str) -> str:
326340
return name[index:].lower() if index >= 0 else ""
327341

328342

343+
def has_dex_magic(data: bytes) -> bool:
344+
"""Return whether bytes start with the versioned eight-byte DEX signature."""
345+
return len(data) >= 8 and data.startswith(b"dex\n") and data[4:7].isdigit() and data[7] == 0
346+
347+
329348
def classify_artifact(path: str, data: bytes, *, referenced: bool = False) -> ArtifactRecord:
330349
"""Classify from bytes and decodability; an extension is never authoritative."""
331350
contains_nul = b"\x00" in data
332-
has_binary_magic = any(data.startswith(magic) for magic in _BINARY_MAGIC)
351+
has_binary_magic = has_dex_magic(data) or any(data.startswith(magic) for magic in _BINARY_MAGIC)
333352
try:
334353
decoded = data.decode("utf-8")
335354
decodable = True

‎src/skillspector/nested_artifacts.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ArtifactRecord,
2626
ContentKind,
2727
classify_artifact,
28+
has_dex_magic,
2829
)
2930
from skillspector.constants import MAX_FILE_BYTES
3031
from skillspector.input_handler import (
@@ -60,11 +61,13 @@
6061
".class",
6162
".cts",
6263
".dll",
64+
".dex",
6365
".dylib",
6466
".exe",
6567
".go",
6668
".js",
6769
".jsx",
70+
".luac",
6871
".mjs",
6972
".msi",
7073
".mts",
@@ -373,6 +376,7 @@ def _zip_member_is_link(info: zipfile.ZipInfo) -> bool:
373376
b"MZ",
374377
b"\x7fELF",
375378
b"\x00asm",
379+
b"\x1bLua",
376380
b"\xfe\xed\xfa",
377381
b"\xce\xfa\xed\xfe",
378382
b"\xcf\xfa\xed\xfe",
@@ -385,7 +389,7 @@ def _zip_member_is_link(info: zipfile.ZipInfo) -> bool:
385389

386390
def has_binary_executable_magic(data: bytes) -> bool:
387391
"""Return whether canonical bytes begin with supported executable magic."""
388-
return data.startswith(_BINARY_EXECUTABLE_MAGICS)
392+
return has_dex_magic(data) or data.startswith(_BINARY_EXECUTABLE_MAGICS)
389393

390394

391395
def is_executable_content(path: str, data: bytes, mode: int = 0) -> bool:

‎src/skillspector/nodes/build_context.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
MAX_MANIFEST_PARSE_SECONDS = 1.0
112112
MAX_MANIFEST_OUTPUT_RECORDS = 1_024
113113
MAX_MANIFEST_OUTPUT_CHARACTERS = 256 * 1024
114-
_EXECUTABLE_PROBE_BYTES = 4
114+
_EXECUTABLE_PROBE_BYTES = 8
115115

116116

117117
def _is_allowed_inactive_git_hook_template(path: str, probe: bytes) -> bool:

0 commit comments

Comments
 (0)