Skip to content

feat(artifacts): inspect Debian package control metadata and contents - #10689

Merged
morluto merged 91 commits into
morluto:mainfrom
mvanhorn:feat/deb-package-metadata
Nov 26, 2026
Merged

morluto merged 91 commits into
morluto:mainfrom
mvanhorn:feat/deb-package-metadata

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add inspect-deb-package / inspect_deb_package: a local, read-only inspection of a Debian .deb as typed Evidence. The reader parses the SysV ar container (debian-binary, control.tar.*, data.tar.*), reports control metadata and relationships, inventories data members, and cross-checks md5sums paths. It does not install the package or run maintainer scripts.

This change adds the runtime dependency @napi-rs/[email protected] so control.tar.xz and data.tar.xz can be decoded in-process. Current Debian/Ubuntu packages ship those members as xz; gzip and zstd already had in-tree decoders, and xz needs a native decoder to inspect those archives under the same size budgets.

No tracking issue exists for this change.

Problem and expected behavior

Operators need to inspect a .deb they already hold without installing it. The existing desktop Debian helper shells out to dpkg-deb for capture work and is a different authority; it is not a typed inspect tool.

Expected outcome: given a local path, the CLI and MCP tool return Evidence whose normalized_result includes ar members, parsed control fields, relationship alternatives (operators and arch qualifiers), conffiles/md5sums presence, maintainer-script interpreter and byte length, a bounded data inventory, and an md5sums path cross-check. Gzip, zstd, xz, and uncompressed tars succeed. Bad ar magic, truncated members, tar checksum failures, truncated/corrupt/oversized xz, and oversize counts refuse with typed errors and partial observations rather than silent zeros. If the xz native binding cannot load, the refusal is typed unsupported_target rather than a process crash. Missing optional control fields are null, not empty strings.

Change and scope

New dedicated inspect tool on the existing contract path: domain schema and Debian version/relationship parsers, ar/tar reader, xz decoder via @napi-rs/lzma, provider, application port/service, composition, CLI registerContractCommand, MCP evidence handler, analysis-view summary, docs, and catalog wording in authored skill references.

The @napi-rs/lzma pin is exact (1.5.3). License inventory, runtime notices, and the documented MIT-notice gap for that package and its same-release prebuilt family are updated with npm run licenses:generate / licenses:check.

Intentionally not included: bzip2 and lzma (legacy .lzma) decompression, debsig/dpkg-sig verification, hashing file contents for md5sums, returning maintainer-script text, installing packages, or executing scripts.

Contribution scope: this is a local shipped-artifact read. It does not execute the target, inject, mutate bytes, or recover protections. No additional maintainer execution/injection decision is required for that reason.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/deb/DebPackageParser.ts owns ar/tar/control/data facts. src/deb/xzDecoder.ts owns xz inflate, uncompressed-size pre-check, and native-binding load. Consumers (DebPackageProvider, DebPackageService, CLI, MCP, debPackageView) use those parsed fields; they do not re-parse raw ar/tar bytes or reinterpret xz errors. No superseded inspect path was removed. Desktop dpkg-deb capture remains a separate authority.
  • Contribution scope fit and linked maintainer decision: not applicable (local file read; no target execution, injection, mutation, or protection recovery).
  • CLI and MCP/tool-catalog contract: new operation inspect_deb_package, CLI inspect-deb-package, family artifact, effect evidence. Input schema includes path plus the documented byte/member/entry limits. Catalog JSON is generated in CI; authored skill text names the command.
  • Provider, bridge, target-format, or platform compatibility: reads SysV ar .deb with control.tar / .gz / .zst / .xz and the same for data.tar. bzip2 and lzma are typed unsupported targets. Requires Node zlib gzip and zstd (already in-tree) plus @napi-rs/lzma for xz. A missing native addon is unsupported_target.
  • Evidence, artifact, provenance, or reconstruction contract: createEvidence + completeProviderEvidence; subject digest is the selected file; locations include artifact path and byte range; limitations list the no-install, no-signature, no-script-text, and no-content-hash rules.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): caller-selected local path only. No child process, no install, no cleanup of foreign files. Truncated/malformed inputs keep partial / partial_observation.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): authored skill references and docs/index catalog wording updated; generated catalogs not committed. New runtime dependency @napi-rs/[email protected] (MIT) plus its optional platform packages; third-party notices and the runtime fingerprint are updated.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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

Parser, domain, service, filesystem, CLI, and MCP tests use in-code ar+tar fixtures, including xz control members (valid, truncated, oversized) and an unavailable native binding. Executed CLI on those fixtures plus two public hello packages (gzip success; xz success). Source-derived: Debian ar/tar/control field shapes. No Hopper/Ghidra/browser provider run.

  • Tests added or updated: src/domain/deb/debPackage.test.ts, src/deb/DebPackageParser.test.ts, src/deb/xzDecoder.test.ts, src/application/deb/DebPackageService.test.ts, tests/acceptance/debPackageCli.test.ts, tests/boundary/mcp/debPackageMcp.test.ts, tests/boundary/filesystem/debPackage.test.ts, plus registrations in local-path admission, stable parser-failure CLI, local tool contracts, CLI integer arguments, and absolute local path MCP tests.
  • Base reproduction or other evidence: before this change, rea inspect-deb-package was not a command. After, fixture inspect returns package hello, epoch/upstream/revision, Depends alternatives with operators and arch restrictions, six maintainer scripts at 17 bytes /bin/sh, and a seven-entry data inventory. Truncated members and non-ar files exit 1 with invalid_request / invalid_format and a partial file snapshot. Public hello_2.10-3_amd64.deb (control.tar.xz / data.tar.xz) inspects with exit 0 and coverage complete.
  • User-visible CLI/MCP output (if applicable): recorded in the demo branch demo/deb-package-metadata (commands.log, out.mp4, preview.gif). Representative human and --json output for the gzip fixture; public gzip hello_2.4-3_amd64.deb; truncated and non-ar refusals; successful xz inspect of hello_2.10-3_amd64.deb.
  • Remaining proof gaps: package signatures (debsig/dpkg-sig) are not verified; bzip2/lzma members remain unsupported; native xz addon load is covered by a test double rather than every optional platform package; no real-world corpus beyond the fixtures and the two public hello packages that were actually run.

Boundary regressions covered: malformed input (bad magic, truncated member, tar checksum, oversize limits), typed unsupported compression, truncated/corrupt/oversized xz, unavailable xz binding, permission/path admission via existing local-path tests, and identity preservation on parser failure (partial snapshot hash). Lifecycle regressions: not applicable (no owned child process or session cleanup).

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

  • npx vitest run src/deb/xzDecoder.test.ts src/deb/DebPackageParser.test.ts src/domain/deb/debPackage.test.ts src/application/deb/DebPackageService.test.ts tests/acceptance/debPackageCli.test.ts tests/boundary/mcp/debPackageMcp.test.ts tests/boundary/filesystem/debPackage.test.ts — 7 files, 40 passed.
  • npm run test:focused -- those files plus tests/acceptance/localPathAdmissionCli.test.ts, tests/acceptance/stableArtifactParserFailureCli.test.ts, tests/acceptance/tools/localToolContracts.test.ts, tests/boundary/cli/cliIntegerArguments.test.ts, tests/boundary/mcp/absoluteLocalPathTools.test.ts — 12 files, 182 passed.
  • npm run check:fast — typecheck and lint passed.
  • npm run format:check — passed (8059 files).
  • npm run metadata:check — passed.
  • npm run docs:check — passed, including licenses:check fingerprint 0683afc489101481e2474d7f118bc734409cbcc22b8f62f4158190e82a8184c1.
  • npm run test:changed -- --base upstream/main — 29917 passed, 3 failed, 21 skipped. Failures are src/artifacts/NodeSeaArtifactReader.test.ts (post-classification carrier mutation) and src/artifacts/pyinstaller/PyInstallerBoundaries.test.ts (cached carrier freshness). They fail in isolation on this tree and are not the Debian reader.
  • npm run check:pr — test:run 8 failed, 49798 passed, 295 skipped. Failures: nativeVerifierPreflightOwnership, advertisedDialect, packageCatalogVerification, NodeSeaArtifactReader malformed-blob mutation, Uf2ArtifactReader forged region, DenoStandaloneArtifactReader carrier mutation, inesArtifact header overwrite, mutationWorkflow empty stderr (PS1 unbound). None are the Debian reader.
  • Real CLI: node scripts/rea.mjs inspect-deb-package on gzip/zstd/xz fixtures (exit 0), truncated and non-ar inputs (exit 1), public hello_2.4-3_amd64.deb gzip (exit 0), public hello_2.10-3_amd64.deb xz (exit 0). SHA-256 values are in commands.log on demo/deb-package-metadata.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. New command and MCP tool only. Adds runtime dependency @napi-rs/[email protected].
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; this tool does not use those providers. Public Debian hello packages were read as local files.
  • Package or release metadata impact: new docs page docs/deb-package.md, catalog wording, authored skill references, lockfile, and third-party notices for @napi-rs/lzma. CI remains the owner of generated catalogs and skills/ build output.
  • Security, privacy, process, or containment review: reads caller-selected local bytes only. Maintainer-script bodies are not returned. Network is not contacted by the inspector. Default limits cap file, member, entry, and decompressed tar sizes. xz uncompressed size is checked against max_control_bytes / max_data_bytes before inflate.

Author readiness

Human owner: @mvanhorn

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

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.

Demo

demo

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T00:12:53.975227Z
We couldn’t complete this review. Comment @codex review to try again.
c36b62e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The latest changes appear safe to merge; the remaining counting finding is fixed.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The latest changes appear safe to merge; the remaining counting finding is fixed.

Summary

Adds local Debian package inspection through CLI and MCP, with control metadata, file inventory, bounded decompression, and typed refusals that retain partial facts.

  • Local Debian packages now produce typed metadata and file inventories.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI / MCP"] --> B["Shared inspection service"]
  B --> C["Stable local file read"]
  C --> D["ar members"]
  D --> E["Bounded tar decompression"]
  E --> F["Control metadata and file inventory"]
  F --> G["Evidence"]
  E --> H["Typed refusal with partial facts"]
  G --> I["Retained summary view"]
Loading

Reviews (60) · Last reviewed commit: "refactor(deb): avoid throwaway filter ar..." · Reviewed by Greptile

Comment thread src/deb/xzDecoder.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/domain/deb/debPackage.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
…unts

DebPackageFormatFailure now extends ParseFailureError, as the architecture
guard requires of parser failure classes; its kind, partial and message are
unchanged. The advertised-dialect baseline takes the counts the
inspect_deb_package input schema adds ($schema in both profiles, and allOf,
default, examples, the \/ escape, the unanchored path pattern and untyped
nodes in the full profile).
@mvanhorn

Copy link
Copy Markdown
Contributor Author

44e6f9c addresses the two red CI lanes: DebPackageFormatFailure now extends ParseFailureError for the architecture guard, and src/contracts/advertisedDialectBaseline.ts records the schema counts the new inspect_deb_package input adds. It does not change the parser behavior the Greptile review flagged.

Comment thread src/deb/DebPackageProvider.ts Resolved
Comment thread tests/acceptance/debPackageCli.test.ts Resolved
dpkg-deb only reads the archive; installing with dpkg is what runs the
maintainer scripts. Correct the spec so the safety rationale names the
right tool.
The provider now maps DebPackageFormatFailure with the shared
parseFailureAnalysisError instead of its own instanceof ladder, passing the
partial ar/control/data observation as diagnostics. The helper takes that
optional diagnostics argument. DebPackageCapacityFailure extends
ParseFailureError<"limit"> with the resource and maximum as its limit, and
the provider keeps its limit recovery.
Resolve parseFailureAnalysisError: keep main's field parameter and add the
optional diagnostics argument after it; the deb provider passes "path".
@mvanhorn

Copy link
Copy Markdown
Contributor Author

eb62c98 merges current main. The one conflict was parseFailureAnalysisError, where main added a field parameter; it keeps field and adds the optional diagnostics argument after it, and the deb provider passes "path".

The CLI acceptance and MCP boundary tests now take the contract from
DEB_PACKAGE_TOOL_CONTRACTS instead of the full catalog, as the testing guide
asks of focused contract tests.
Coverage was complete with a missing or empty debian-binary, or a control.tar
that held no control file. It now needs a known format version and the
control file as well as the control and data members, and each gap adds a
limitation.
dpkg lists every name of a hardlinked file in md5sums, while tar stores the
later names as hardlink entries. The cross-check inventory now takes
hardlink paths as well as regular files, so those names are no longer
counted missing.
The sync @napi-rs/lzma decoder takes no output bound, so a member whose
index could not be read was decoded with no limit and checked only after
allocation. decodeXz now refuses such a member, as truncated when the footer
is missing and malformed otherwise, before calling the decoder.
md5sums that is not UTF-8 counted as zero listed paths, and a package with
no data.tar counted as an empty inventory. The cross-check is now computed
only when both were read; otherwise it stays null and a limitation says
which input was missing.
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
…rejects

A Version with an empty upstream part or Debian revision (1:, 1:-1, 1.0-)
and an Installed-Size past the safe integer range reached DebControl and
failed the output schema, so the service lost the report. The parser now
records a malformed field issue and leaves the value null.
Main now requires every top-level src unit in UNIT_LAYERS. src/deb is a
provider like src/sqlite, and its two type imports of application ports
are recorded in the upward-import baseline the same way. The xz spy
binding now accepts the string or bytes input XzApi.compressSync takes.
Read ustar name, prefix and linkname fields, and GNU long names, as
NUL-terminated UTF-8 without trimming or rewriting backslashes, and keep
spaces in md5sums paths. A name that is not UTF-8 is shown with U+FFFD
replacements and counted in a limitation, since it may not match md5sums.
Look up control, conffiles, md5sums and maintainer scripts by their
normalized root path, so a nested subdir/control or subdir/postinst no
longer stands in for the root file.
Comment thread src/deb/DebPackageParser.test.ts Resolved
PAX record lengths count bytes, so walk the extended header bytes and
decode each record on its own. A UTF-8 path no longer swallows part of
the next record. A path or linkpath record that is not UTF-8 is counted
in the same not-UTF-8 limitation as ustar names.
Accept hyphenated architecture qualifiers such as kfreebsd-amd64, and
have parseDebianRelationshipField return the alternatives it cannot
read. parseControl records each as a malformed issue on its field, so
the package reports partial coverage instead of dropping a dependency.
A Debian package refusal now carries the bounded partial report as
diagnostics.partial, so control facts, relationships, maintainer-script
facts, ar member offsets and file rows read before the failure reach CLI
and MCP callers, not just member names and a count.
@morluto morluto added the enhancement New feature or request label Nov 22, 2026
GNU PAX sparse headers (GNU.sparse.*) rename the following entry to a
synthetic GNUSparseFile path and store only mapped segments, so reading
it as a regular file reported the wrong name and size and could miss
md5sums cross-checks. Old GNU sparse (S) entries can also carry
extension blocks their size field does not count. Refuse both as an
unsupported format instead of reporting wrong file facts.
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@mvanhorn thanks for the PR — this branch has merge conflicts with main. Could you merge or rebase onto the latest main and resolve them? Once it's clean and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageProvider.ts Resolved
@mvanhorn

Copy link
Copy Markdown
Contributor Author

@morluto I merged main into the branch and pushed it as 8219900. Main has moved since then, and the branch now conflicts again in licenses/npm-dependencies.txt, which still needs resolving.

@morluto

morluto commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged latest main (resolving conflicts in src/domain/tarFormat.ts and licenses/npm-runtime-notices.txt, refreshing licenses/npm-dependencies.txt and scripts/verify/advertised-schemas/tools/inspect_deb_package.json) and resolved the remaining integration blockers from @N0zoM1z0's review in 30c9908b2c7f485fd1b1c1c8ec281092e84f13e8:

  1. Bounded XZ decoding (src/deb/xzDecoder.ts, src/deb/DebPackage.errors.ts, src/deb/DebPackageParser.ts):
    • Replaced one-shot decompressSync with full XZ stream/footer/index/block-header preflight validation (CRCs, declared uncompressed totals, and LZMA2 dictionary size <= 128 MiB reported via xz_dictionary_bytes fixed allowance before any bytes reach the native decoder) followed by streaming decompressStream with a chunk-by-chunk output cap and AbortSignal cancellation.
    • Added regression tests covering oversized LZMA2 dictionaries (refused before invoking the native decoder), spoofed-index streams (aborted mid-stream at the output budget), concatenated XZ streams, and cancellation.
  2. Global PAX size before member framing (src/deb/DebPackageParser.ts):
    • Resolved inherited global PAX size (parsed once per global header) before reading/advancing member payloads, preserving local PAX x overrides and empty-value clears.
    • Added regression tests covering inherited global PAX size, local PAX size override, and empty-value reset.
  3. Homepage URL credential redaction (src/deb/DebPackageParser.ts):
    • Routed Homepage through redactRecordedTransportUrl (src/domain/recordedTransportUrl.ts) to remove transport userinfo (and omit ambiguous credential-bearing spellings as null), recording a limitation when credentials are redacted while preserving non-credential URLs and non-URL text.
    • Added regression tests for userinfo redaction, ambiguous credentials, plain URLs, and non-URL text.
      (BSD #1/N ar member alignment by stored size was already fixed and covered by tests on the branch.)

Validation

  • npm run check:fast (typecheck, lint, architecture guards across 3,180 files) — passed
  • npm run test:local -- src/deb/xzDecoder.test.ts src/deb/DebPackageParser.test.ts src/domain/tarFormat.test.ts src/domain/deb/debPackage.test.ts src/application/deb/DebPackageService.test.ts (97 tests) — passed
  • npm run test:focused -- tests/boundary/filesystem/debPackage.test.ts tests/boundary/mcp/debPackageMcp.test.ts tests/acceptance/debPackageCli.test.ts tests/boundary/cli/cliContractCommandParity.test.ts (990 tests) — passed
  • npm run verify:advertised-schemas, npm run docs:check, npm run licenses:check — passed

Comment thread src/deb/xzDecoder.ts Resolved
Comment thread src/deb/xzDecoder.ts Resolved
# Conflicts:
#	tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts
Comment thread src/domain/deb/debPackage.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
Comment thread src/deb/DebPackageProvider.ts Resolved
Comment thread src/deb/xzDecoder.ts Resolved
Comment thread src/deb/DebPackageParser.ts Resolved
# Conflicts:
#	scripts/lib/test-projects.mjs
#	src/domain/parseFailureAnalysisError.ts
#	src/server/offlineInspectionToolBindings.ts
Comment thread src/deb/DebPackageParser.ts Resolved
@morluto
morluto merged commit 0f5ab1e into morluto:main Nov 26, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants