Skip to content

feat(native): read embedded cargo-auditable Rust dependency lists - #2456

Merged
morluto merged 15 commits into
morluto:mainfrom
mvanhorn:fix/rust-auditable-dependencies
Oct 13, 2026
Merged

morluto merged 15 commits into
morluto:mainfrom
mvanhorn:fix/rust-auditable-dependencies

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Agents can now read the dependency list that cargo auditable embeds in a Rust binary. inspect_rust_binary / inspect-rust-binary reads the .dep-v0 section (__DATA,.dep-v0 on Mach-O) from one ELF, PE or thin Mach-O file without running it, and returns the packages, their versions and sources, the root package and the dependency edges. It answers for Rust the question inspect_go_binary answers for Go.

No issue is linked. This is a new static, read-only primitive within the existing format-inspection scope, proposed here with the implementation.

Demo

Rust dependency list demo

Full-quality MP4

Simulated demo rendered from real output. Every value on screen is copied from rea inspect-rust-binary on this branch, run against an auditable and a plain build of the same one-line crate.

Problem and expected behavior

Rust binaries built with cargo auditable carry their full crate dependency tree as zlib-compressed JSON in a .dep-v0 section. REA had no Rust metadata lane, so an agent asked "which crates and versions are in this binary" had nothing to call short of a full disassembly.

With this change, one call returns the section name, file offset, compressed and uncompressed sizes, format version, packages in original order (name, version, source, kind, dependencies, root), the root package index, dependency edges, and any packages that sit on a dependency cycle. When the section is absent, auditable_metadata is null with the limitation "Absence of .dep-v0 does not mean the binary has no dependencies." Read-only /rustc/<commit>/ paths are reported separately as an inferred compiler commit.

Change and scope

Section lookup reuses the ELF, PE and Mach-O readers that inspect_go_binary already validates; they now also expose a list of named sections with their file ranges. PE content length is min(VirtualSize, SizeOfRawData), so file-alignment padding never reaches the decoder, and ELF SHT_NOBITS sections are never treated as stored bytes. The inflate is capped by a fixed ratio and an absolute maximum. The JSON is parsed with a strict schema, dependency indices are range-checked, and cycle members are found with an iterative strongly-connected-component pass, so long chains cannot exhaust the stack. Overlapping read-only sections are scanned once, and more than 64 distinct compiler paths is a typed resource failure rather than unbounded output.

Universal Mach-O files are refused with a typed unsupported error rather than picking a slice. Not included: recovering dependencies from binaries built without cargo auditable (panic strings, symbol names); that would be inference rather than an embedded record.

One naming note for review: the shared container readers keep their existing Go* names (GoImageSection and friends) to keep this diff small. If you would rather they move to neutral names now that two lanes use them, I can do that here or in a follow-up.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/rust/RustAuditableReader.ts (section payload), src/rust/RustBinaryImage.ts (section selection and compiler paths), schema in src/domain/rust/rustBinary.ts; section ranges added to src/go/Go{Elf,Pe,Macho}Image.ts.
  • Contribution scope fit and linked maintainer decision: static format inspection of a caller-selected file; no execution, injection, mutation or protection recovery, so not applicable.
  • CLI and MCP/tool-catalog contract: new inspect_rust_binary / inspect-rust-binary with one path input; registered next to the Go tool, effects entry read-only, catalog builders and capability inventory updated.
  • Provider, bridge, target-format, or platform compatibility: ELF, PE and thin Mach-O; cargo auditable format version 1.
  • Evidence, artifact, provenance, or reconstruction contract: package data is labeled as file content that is not authenticated; the compiler commit is labeled inferred.
  • Target selection, authority, upstream behavior, and cleanup details: reads one admitted regular file.
  • Generated metadata, package, or installation impact: skill text in .agents/skills/reverse-engineer-anything/, docs/rust-binaries.md, a README row; build outputs not committed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/rust/RustAuditableReader.test.ts (schema, inflate bound, out-of-range indices, cycle membership including members reached through finished vertices, a 20,000-package chain), src/application/rust/RustBinaryService.test.ts, tests/boundary/rust/rustBinaryImage.test.ts (ELF, PE with aligned raw size, Mach-O, missing section, universal refused, SHT_NOBITS, compiler-path cap), tests/acceptance/rustBinaryCli.test.ts, tests/boundary/mcp/rustBinaryMcp.test.ts; Go boundary tests rerun unchanged.
  • Base reproduction or other evidence: executed on two real macOS arm64 builds of a one-line crate that depends on itoa, one with cargo auditable build --release and one with plain cargo build --release.
  • User-visible CLI/MCP output: the auditable build reports __DATA,.dep-v0 at file offset 298088, 120 compressed and 165 uncompressed bytes, format 1, packages itoa 1.0.18 (crates.io) and sample 0.1.0 (local, root, depends on 0). That matches an independent read of the same section with otool and zlib. The plain build reports auditable_metadata: null with the absence limitation. Both report the inferred compiler commit b940084d7eb6a299eb4bfeb8e34901bc051e7ac4, which matches rustc -vV for the toolchain that built them. A full result is about 960 tokens.
  • Remaining proof gaps: no real Windows or Linux build was checked; PE and ELF are covered by fixtures.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

All on macOS 27 with Node 26 and the pinned npm 11.16.0, on this branch rebased on a2d8b94:

npm run check                  # pass (typecheck, lint, format, knip, metadata, jscpd, architecture guards)
npm run test:focused -- <Rust and Go boundary, acceptance, MCP and unit tests>   # pass: 11 files, 156 tests
npm run docs:check             # pass
npm run verify:test-discovery  # pass
rea inspect-rust-binary target/release/sample   # both real builds, results above

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Additive tool; inspect_go_binary output is unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only for real binaries.
  • Package or release metadata impact: skill text and docs only.
  • Security, privacy, process, or containment review: reads one caller-selected file; bounded inflate, scan coverage and retained output; no process launch, writes or network.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking defect was found.

Summary

Adds inspect_rust_binary and inspect-rust-binary to read cargo-auditable dependency records from ELF, PE, and thin Mach-O files without running them.

  • Rust binaries can reveal their embedded crate lists through a new static inspection.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI or MCP: selected path"] --> B["RustBinaryService"]
  B --> C["RustBinaryProvider"]
  C --> D["Stable regular-file read"]
  D --> E["ELF / PE / thin Mach-O sections"]
  E --> F["Bounded inflate and package checks"]
  F --> G["Packages, edges, and cycles"]
  E --> H["Read-only compiler paths"]
  G --> I["Validated report and Evidence"]
  H --> I
Loading

Reviews (10) · Last reviewed commit: "Merge branch 'main' into fix/rust-audita..." · Reviewed by Greptile

Comment thread src/rust/RustAuditableReader.ts Resolved
Comment thread src/domain/rust/rustBinary.ts Resolved
Comment thread src/rust/RustAuditableReader.ts Resolved
Comment thread src/rust/RustBinaryImage.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

Source fix: 0b84e3413ae91b4822e7a715ab17b4109b6b624a.

The output limit was applied after normalization, edge allocation, reverse-graph construction, and serialization. The reader now admits raw package/dependency counts against a conservative lower bound on the required normalized JSON representation before Zod clones the document or any graph arrays are built. Admission reports the existing 8 MiB transport budget; the final exact serialized-size guard still covers string sizes and all other report fields.

Added an unrun regression with 400,000 valid repeated indices in a below-1-MiB, ratio-admissible section. Source inspection confirms admission precedes normalization and SCC/reverse-edge construction. No superseded graph representation remains. Tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested; performance was not measured.

  1. thread 1

Source fix: 0b84e3413ae91b4822e7a715ab17b4109b6b624a.

The reader failure carried every limit in a single maximum_bytes field, and the provider reinterpreted every failure as memory. Replaced that representation with a typed constraint carrying resource kind and unit-specific limits. Compiler paths now report capacity with maximum_rustc_hashes: 64; actual memory/transport byte limits retain their own units, and the provider forwards the producer's constraint unchanged.

Updated the overflow assertion and added an unrun public MCP error-contract regression using the same shared overflow fixture. Source inspection followed the failure from image reader through provider projection to the MCP contract; no old count-as-bytes consumer remains. Tests, typechecks, builds, lint, provider workloads, and CI reruns were not run, as explicitly requested.

@morluto morluto added enhancement New feature or request i18n Translations and localization workflow area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: cli CLI adapter and one-shot commands area: server Server layer and tool wiring P2: medium Medium priority issue labels Oct 13, 2026
Comment thread src/rust/RustAuditableReader.ts Resolved
Comment thread src/domain/rust/rustBinary.ts Resolved
Comment thread src/go/GoElfImage.ts Resolved
cursoragent and others added 3 commits October 13, 2026 15:58
…er paths

Fail the first malformed cargo-auditable package before Zod collects an
issue per field. Require cyclic dependency indices to match the cycles in
package dependencies. Keep read-only ELF ranges when a section name does
not fit the bounded name window, so a rustc path in that range is still
reported.
Comment thread src/go/GoMachoImage.ts Resolved
@morluto
morluto merged commit 0e6eca4 into morluto:main Oct 13, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: server Server layer and tool wiring enhancement New feature or request i18n Translations and localization workflow P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants