Skip to content

feat(artifacts): inventory and extract stored and gzip-compressed tar archives - #14245

Merged
morluto merged 12 commits into
mainfrom
feat/tar-inventory
Nov 24, 2026
Merged

morluto merged 12 commits into
mainfrom
feat/tar-inventory

Conversation

@morluto

@morluto morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Fixes #14177

What changes

inspect-artifact and extract-artifact now read POSIX tar archives, stored or gzip-compressed, as a new tar artifact format (archive target kind). This covers Linux release tarballs and Unity .unitypackage files. Before this change, both were refused as file_format_rejected / "unsupported binary format".

  • Recognition (src/domain/tarFormat.ts, shared recognizer table): a checksum-valid ustar or GNU header at offset 0, or a gzip member whose first decompressed block is one. The gzip probe inflates at most 2 KiB of input with a 4 MiB output cap. A plain gzip stream that is not tar is not claimed. A first block that carries the ustar magic but fails its checksum is refused with the reason ("tar first header checksum does not match").
  • Walk (src/artifacts/tar/TarWalk.ts): headers are read once and member data is skipped. Pax path, linkpath, size, uid, gid, uname, gname and mtime records apply (local and global), as do GNU L/K long names and the ustar prefix. Regular files, directories and symlinks become occurrences. Character and block devices, FIFOs, hard links, sparse members and vendor typeflags are reported as traversal omissions. The ./ root and GNU volume labels carry no occurrence. A leading ./ is dropped and kept in source_path, as for ZIP.
  • Reader (src/artifacts/tar/TarArtifactReader.ts): stored members are carrier ranges with a real source_location. Gzip members are read by forward decompression. An idle decompression is kept, so in-order opens (the inventory scan) cost one pass. An out-of-order open starts a fresh one.
  • Facts: root format_metadata kind: "tar" records compression, dialects, pax header count, member count, tar-stream bytes, end_state, end_offset and trailing non-zero bytes. Each member has kind: "tar-entry" with its offsets, typeflag, mode, owner, mtime and link target. compare-artifacts compares typeflag, mode and link target.

Unrecognised, malformed and truncated stay distinct

  • An invalid first header refuses the archive as malformed tar (a ParseFailure with offset: 0).
  • A later bad header or malformed pax record, a member or header cut off by the end of the stream, a cut gzip stream, a deflate or CRC error, or non-zero bytes after the end marker do not refuse the archive. The members already read are kept, coverage is unknown, and end_state/end_offset record the reason.
  • Coverage is complete only when the walk reaches the end-of-archive marker and only zeros follow it.

#14239 note: the failure model (TargetFailure) has not landed yet, so the new failures stay minimal and use the existing ParseFailure/ArtifactReaderFailure and file_format_rejected paths. #14239 migrates them.

Bounds

  • Every decompressed byte is charged to artifact_limits.expanded_bytes (shared default: max(256 MiB, 500 times the file size)). This includes preparation and each member decompression, and uses Budget.
  • Fixed allowances: 1 MiB per pax or GNU long-name record, and 64 MiB of retained member metadata.
  • At most four active member streams.
  • Unsafe paths use the shared ZIP path validator. Extraction stays inside its fresh root.

Tests

  • src/artifacts/tar/TarArtifactReader.test.ts (19 tests), each run for stored and gzip archives where it applies:
    • recognition, including plain gzip and a bad checksum;
    • members, modes and links;
    • pax, GNU long-name and prefix paths;
    • omissions;
    • malformed later header;
    • trailing data;
    • truncated stored member and cut gzip stream;
    • malformed first header;
    • expansion limit;
    • out-of-order gzip open;
    • root inventory hashing;
    • extraction.
  • tests/boundary/filesystem/binaryTarget.test.ts: .tar and .unitypackage resolve to the archive/tar target, plain gzip stays unsupported, and a corrupt checksum is refused with its reason.
  • tests/acceptance/tarArchiveCli.test.ts: compiled CLI inventory and extraction for .tar and .tar.gz, a truncated archive giving partial coverage, and a malformed first header.
  • tests/boundary/mcp/tarArchiveMcp.test.ts: MCP summary, an inspect_analysis_view page of one member, and extraction.
  • Mutation checks:
    • always reusing the idle decompression fails the out-of-order test;
    • ignoring non-zero trailing bytes fails both trailing-data cases.

Validation

  • npx vitest run over the tar, target, vocabulary, format-recognition, inventory and analysis-view tests: 119 files, 2426 passed.
  • Scoped tsc over the changed modules and tests: clean. oxfmt, oxlint (no errors) and architecture-guards.mjs: pass.
  • The compiled CLI and MCP tests need a build and were not run locally. CI covers them.

Real public files (downloaded to a scratch directory, never executed)

File SHA-256 Result (source reader, macOS arm64)
Orama-Interactive/Pixelorama v1.2.4 Pixelorama-Linux-64bit.tar.gz 692473e4…c568e0b tar/gzip/GNU, 39 members, complete. Pixelorama.x86_64 is classified elf and Pixelorama.pck is classified godot-pck. 1.07 s, 244 MB peak RSS
vrm-c/UniVRM v0.131.4 UniVRM-0.131.4_efd2.unitypackage 3f0e7349…2730c445a tar/gzip/GNU, 3,091 members (the count the issue reports), complete. 0.33 s

Remaining

  • The walkTar function is long and trips the complexity lint warnings. No lint errors.
  • Not read: xz, bzip2 and zstd wrappers; a .unitypackage pathname → GUID projection; pre-POSIX v7 headers; hard-link content.

… archives

Recognize POSIX ustar and GNU tar headers, plain or as the first block of
a gzip member, as the new tar artifact format, so Linux release tarballs
and Unity .unitypackage files inventory and extract like ZIP archives.

The tar reader walks every header once, applying pax path, linkpath and
size records, GNU long names and the ustar prefix. Regular files,
directories and symlinks are occurrences with typeflag, mode, owner,
mtime and link target; devices, FIFOs, hard links and sparse members
are traversal omissions. Gzip members are read by forward decompression
with an idle stream reused for in-order opens, and every decompressed
byte is charged to artifact_limits.expanded_bytes.

A later corrupt header, a truncated member or gzip stream, and non-zero
bytes after the end marker keep the members read so far with unknown
coverage and an explicit end_state; a first block with the ustar magic
and a bad checksum is refused with that reason.

Fixes #14177
@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-24T01:51:14.463022Z
We couldn’t complete this review. Comment @codex review to try again.
658d117 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

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; all three numbered findings are addressed.

Summary

Adds stored and gzip-compressed tar inventory and extraction, including member metadata and partial coverage for damaged archives.

  • REA recognizes stored and gzip-compressed tar archives by their contents.
  • Tar archives expose supported members for inventory and extraction.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Archive bytes] --> B[Recognize tar]
  B --> C{Compression}
  C -->|Stored| D[Read carrier ranges]
  C -->|Gzip| E[Read decompressed bytes]
  D --> F[Walk headers and record coverage]
  E --> F
  F --> G[Inventory and hash members]
  G --> H[Extract selected files safely]
Loading

Reviews (10) · Last reviewed commit: "fix(tar): enforce stored-read budget, de..." · Reviewed by Greptile

Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/domain/tarFormat.ts Resolved
Comment thread src/domain/tarFormat.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
- Charge omitted devices, FIFOs and links to the retained-metadata allowance.
- Probe a small gzip tar without verifying its trailer, and feed the final
  trailer to zlib separately so data before a bad CRC stays readable;
  queue decompressed output so a later failure cannot drop it.
- Decode negative GNU base-256 numbers; only mtime may be negative.
- Apply pending pax records only to the next member, never to extension
  headers, and let an empty pax value delete the keyword.
- Push a member once its data is complete, then skip its padding.
- Treat a cut-off zero block as truncation, not an end marker.
- Stop with malformed partial coverage, not a refusal, when a later header
  declares an unsafe size.
Comment thread src/artifacts/tar/TarByteStream.ts Resolved
The decompressed-output queue charged the plaintext-work allowance only
when the reader took a chunk, so bytes queued for an idle reader were
not bounded by artifact_limits.expanded_bytes. Each chunk is now charged
in the data handler before it is queued; an exhausted allowance stops the
inflater, and the queued, already-charged bytes are served before the
limit failure.
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/domain/tarFormat.ts Resolved
… fields

- A pax size, uid, gid or mtime record that does not parse now stops the
  walk as malformed at that member, keeping earlier members, instead of
  silently falling back to the header field.
- The gzip-wrapped tar probe skips the RFC 1952 FEXTRA, FNAME, FCOMMENT
  and FHCRC fields before applying its 2 KiB compressed-data bound, so a
  long name or comment no longer hides the archive.
@morluto
morluto enabled auto-merge (squash) November 24, 2026 03:57
# Conflicts:
#	docs/.vitepress/documentation.ts
#	docs/README.md
#	docs/reference/supported-targets.md
#	src/application/binary/TargetFormatVocabularies.test.ts
#	src/artifacts/artifactFormats.ts
#	src/domain/artifactFormatRecognition.ts
#	src/domain/artifactGraph.ts
#	src/domain/targetFormats.ts
#	src/resources/ArtifactReader.ts
#	tests/boundary/filesystem/binaryTarget.test.ts
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
Comment thread src/artifacts/tar/TarByteStream.ts Resolved
…nour cancellation in gzip waits

- An old GNU sparse header (typeflag S) can continue its sparse map in
  512-byte extension blocks before the stored data; they are now skipped
  so the next header stays aligned. The member is still an omission.
- The non-UTF-8 name fallback decodes each byte as its own code point.
  The WHATWG latin1 label is Windows-1252 and rewrote bytes 0x80-0x9f.
- A gzip read waiting for decompressed output now wakes on cancellation
  and raises it, rather than waiting for output or the end of input.
Comment thread src/artifacts/tar/TarArtifactReader.ts Resolved
Comment thread src/artifacts/tar/TarByteStream.ts Resolved
Comment thread src/artifacts/tar/TarWalk.ts Resolved
@morluto
morluto merged commit 225a19a into main Nov 24, 2026
58 checks passed
@morluto
morluto deleted the feat/tar-inventory branch November 24, 2026 15:40
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 26, 2026
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.

[Feature] Inventory tar and gzip-compressed tar archives (Linux game releases, .unitypackage)

1 participant