Skip to content

fix(tar-extract): unpack only the manifest's listed paths (CORE-386) - #448

Merged
PrzemekGalarowicz merged 4 commits into
mainfrom
feat/core-386-unpack-listed-paths-only
Nov 25, 2026
Merged

PrzemekGalarowicz merged 4 commits into
mainfrom
feat/core-386-unpack-listed-paths-only

Conversation

@PrzemekGalarowicz

@PrzemekGalarowicz PrzemekGalarowicz commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What and why

pharn-oss v7.25.3–v7.25.5 commit seven symlinks under .claude/skills/, outside pharn-install.json. src/lib/tar-extract.ts applied its strict rules to every archive entry, so every pharn init / add / update / status failed on every channel (tar entry has an unsupported type '2': …/.claude/skills/pharn-ci-cover). The same would happen for a hard link, a pax x header (a path segment over 100 bytes), a : or \ in a name, or the repo outgrowing 20,000 entries / 128 MB, anywhere in pharn-oss — though only 616 of its 4,149 files are installed.

Select, then judge. extractPharnArchive (src/lib/repo.ts) makes two streamed passes over the downloaded .tar.gz:

  1. write only CLONE_READ_FILES (pharn-install.json, SKILLS_VERSION, MIN_CLI, .claude/settings.json), run the release check, and validate the manifest through the one parser;
  2. write only the paths the manifest lists; then verifyUpstreamManifest holds every listed file to its raw sha256, as before.

Every other entry is skipped and never written, whatever its type or name. Every header is still framing-checked (checksum, ustar magic, octal size, end marker + zero tail). A listed path keeps today's rules: regular file only, strict UTF-8, no control/format character, no absolute / .. / \ / : / empty segment, one root, and now also no duplicate. A pax x / GNU L/K header is skipped with the entry it modifies; if that entry's ustar name is a listed path it is refused, and if the record renamed a listed file away, that file is missing and the hash check refuses.

  • The decompressed tar is streamed (zlib.createGunzip), never held whole. Caps: 32 MB download (unchanged), 200,000 headers, 1 GiB decompressed bytes walked (compression-bomb bound), 128 MB written.
  • TarExtractError keeps its name/export, and every refusal still names the entry path and the rule (composes with CORE-388's boundary wrapper, fix: name the ref, the fault and the next steps when the pharn-oss archive is refused (CORE-388) #447).
  • extractTarGz(archive: Buffer, dir, { select, limits, root }) and extractPharnArchive(archive, dir, checkTree?) take bytes, never a URL, so CORE-387's verify-archive <file.tar.gz> can run the same walk + hash check with no network.
  • The layout-marker check in readUpstreamManifest also accepts a manifest that lists a file under pharn/pharn-contracts/, so the manifest validates between the passes (equivalent once extracted; the hash check proves the file arrived).
  • A rootless entry whose whole name is a listed path is refused ("no path below the archive root"), not skipped. A listed file after a modifier header is refused naming that header's type (unsupported type 'x' (a pax extended header, …)).
  • tests/tar-extract.test.ts keeps every base test name and body: a test-level LIMITS selects every path the base fixtures use, so each is judged exactly as before; new blocks cover the unselected side. The old "rejects a symlink entry outright, rather than skipping it" decision is narrowed, not reversed, with the reason recorded: degit's silent skip lost listed files; now an unlisted entry is skipped unwritten and a listed one is still refused or fails the manifest hash check.
  • tests/project-lock.test.ts: the signal children's signalHandled helper holds the loop open with a ref'd timer. The SIGINT-after-fetch child exited 13 (unsettled top-level await) once extraction became streamed — it had only passed on main because a tsx IPC ConnectWrap happened to still be pending. No assertion changed.
  • Docs: CLAUDE.md ("The clone is data", network bounds), docs/architecture.md, docs/contributing.md, SECURITY.md, THREAT-MODEL.md (applied by the maintainer from a patch script, as it is hook-protected), CHANGELOG.md [0.21.6] section (Fixed + Security). Version 0.21.6 (epic-coordinated: 386 = 0.21.6, 388 = 0.21.7, 387 = 0.22.0); v0.21.5 added to KNOWN_TAGS.

How tested

  • New/updated unit tests: outside the selection, a symlink, hard link, devices, fifo, directory, pax x + renamed entry, GNU L/K, : / \ / invalid-UTF-8 / control-character names, absolute, .., second root and rootless entries all install and write nothing; the same entry at a listed path is refused (or, pax-renamed, fails the hash check in tests/repo.test.ts). Plus duplicate, header/scanned/written caps, odd chunk boundaries (1/7/511/513/1500-byte chunks give byte-identical trees), gzip errors, and a repo larger than the written cap.
  • Local floor: format:check, lint, lint:md, typecheck, vitest (106 files, 3,662 tests, coverage 98.59/95.75/99.08/99.08), build — all exit 0. /pharn-dev-ship artifacts in .dev/features/core-386-unpack-listed-paths-only/ (regress no-regressions, verify PASS).
  • End to end against the real pharn-oss archive with the built dist/index.js, in throwaway projects:
    • baseline 0.21.5 build: init --yes → exit 1, tar entry has an unsupported type '2': pharn-oss-1755d6b…/.claude/skills/pharn-ci-cover;
    • default channel (--ref latest → release v7.25.5, commit 1755d6b8, 7 symlinks): init --yes exit 0 (592 files), status "No drift", update --yes "Up to date"; no symlink in the project;
    • --ref main (commit a2cacaef, 7 symlinks): init --yes exit 0, status "No drift", update --yes "Up to date"; and update --yes --ref main on the latest install exit 0.

Linear: https://linear.app/pharn-dev/issue/CORE-386

🤖 Generated with Claude Code

… other entry (CORE-386)

pharn-oss v7.25.3-v7.25.5 commit seven symlinks under .claude/skills/, outside
pharn-install.json, and the extractor refused any non-file entry anywhere in the
archive, so every init/add/update/status failed on every channel.

The extractor now selects, then judges: two streamed passes over the archive
write only the files the CLI reads itself (CLONE_READ_FILES) and then, once the
manifest has validated, only the paths it lists. Every other entry is skipped
and never written, whatever its type or name. A listed path keeps every rule
(regular file, strict UTF-8, no control/format char, no absolute/../\/:, one
root, no duplicate) and a pax/GNU-modified entry at a listed path is refused;
verifyUpstreamManifest still fails a listed file that is missing or altered.
The tar is streamed through createGunzip, so the 128 MB cap now bounds bytes
written; headers (200k) and decompressed bytes (1 GiB) bound the walk.
extractPharnArchive takes a buffer, for a later local verify-archive mode.

Docs (CLAUDE.md, architecture, contributing, SECURITY, THREAT-MODEL via the
user's patch) and CHANGELOG [Unreleased] updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 51a96d2 and ab300d9.

Files ignored due to path filters: 9

  • .dev/features/core-386-unpack-listed-paths-only/GRILL.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/PLAN.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/REGRESSION.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/REVIEW.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/SHIP.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/VERIFY.md is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/regression-report.json is excluded by !.dev/**
  • .dev/features/core-386-unpack-listed-paths-only/verify-report.json is excluded by !.dev/**
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 15

  • CHANGELOG.md
  • CLAUDE.md
  • SECURITY.md
  • THREAT-MODEL.md
  • docs/architecture.md
  • docs/contributing.md
  • package.json
  • src/lib/repo.ts
  • src/lib/tar-extract.ts
  • src/lib/upstream-manifest.ts
  • tests/project-lock.test.ts
  • tests/release-consistency.test.ts
  • tests/repo.test.ts
  • tests/tar-extract.test.ts
  • tests/upstream-manifest.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

pharn

🛡️ pharn-ci · ✅ Pass

Tip

Pass · Diff coverage of this change is 100% against a threshold of 80%; 33 agent setup files found.

Verdict Diff coverage Test integrity Agent setup
✅ Pass 100% (threshold 80%) none (block) 33 files

🧪 Diff coverage

▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰ 100%

100% of changed lines covered (132/132, threshold 80%)

Changed files (3)
File Coverage Covered Uncovered lines
src/lib/repo.ts 100% 15/15
src/lib/tar-extract.ts 100% 112/112
src/lib/upstream-manifest.ts 100% 5/5

🔍 Test integrity

No test-integrity findings (mode: block).

Tests changed: +25 −0 ~33 · 1 renamed
Test file Added Removed Modified Renamed
tests/repo.test.ts 5 0 0 0
tests/tar-extract.test.ts 19 0 32 1
tests/upstream-manifest.test.ts 1 0 1 0

🤖 Agent setup (33 files)

Agent setup: 33 files · amp, claude-code, codex, copilot, cursor, jules, opencode, zed

Agent setup files (33)
Path Kind
.claude/commands/pharn-dev-build.md claude-command
.claude/commands/pharn-dev-eval.md claude-command
.claude/commands/pharn-dev-grill.md claude-command
.claude/commands/pharn-dev-memory-promote.md claude-command
.claude/commands/pharn-dev-plan.md claude-command
.claude/commands/pharn-dev-regress.md claude-command
.claude/commands/pharn-dev-review.md claude-command
.claude/commands/pharn-dev-ship.md claude-command
.claude/commands/pharn-dev-verify.md claude-command
.claude/hooks/enforce-writes-scope.cjs claude-hook
.claude/hooks/enforce-writes-scope.test.cjs claude-hook
.claude/hooks/git-worktree-fixture.cjs claude-hook
.claude/hooks/protect-trusted-paths.cjs claude-hook
.claude/hooks/protect-trusted-paths.test.cjs claude-hook
.claude/hooks/session-root.cjs claude-hook
.claude/hooks/session-root.test.cjs claude-hook
.claude/hooks/set-writes-scope.cjs claude-hook
.claude/hooks/set-writes-scope.test.cjs claude-hook
.claude/settings.json claude-settings
.claude/skills/phargus-diagnose claude-skill
.claude/skills/phargus-memory claude-skill
.claude/skills/phargus-rules claude-skill
.claude/skills/phargus-setup claude-skill
.claude/skills/phargus-verify claude-skill
.claude/skills/pharn-ci-cover claude-skill
.claude/skills/pharn-ci-explain claude-skill
.claude/skills/pharn-ci-fix claude-skill
.claude/skills/pharn-ci-install claude-skill
.claude/skills/pharn-ci-policy claude-skill
.claude/skills/pharn-cli claude-skill
.claude/skills/security-audit claude-skill
AGENTS.md agents-md
CLAUDE.md claude-md

pharn-ci 0.12.0 · report schema v2 · coverage format lcov

PrzemekGalarowicz and others added 3 commits November 25, 2026 17:37
… (CORE-386)

Bump to 0.21.6 (epic-coordinated) and move the CORE-386 entry into the
[0.21.6] CHANGELOG section; v0.21.5 joins KNOWN_TAGS.

pharn-ci TI02 read the restructured tar-extract tests as removals. The tests
keep their base names now (the same behaviour, re-expressed against the
selection), with the old merged g-header and BOM cases split back out. The
init test is back to its base text: the new marker message still contains it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pharn-ci TI02 still read eight base tests as removed (computed it.each names
match by body). They are back with their base bodies: a test-level LIMITS
selects every path they use (latin1 keys), so each entry is judged by the full
rules exactly as before. A rootless entry named like a selected path is now
refused ("no path below the archive root") rather than skipped, which restores
"rejects a file with no component to strip". CLAUDE.md no longer names
pharn-install.json as a repo path (pharn-ci SETUP_STALE_SI02).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CORE-386)

The refusal of a listed file after a modifier header now names that header's
type through describeTypeflag ("unsupported type 'x' (a pax extended
header, ...)"), so the base pax test keeps its expected value. The base test
"bounds the bytes written by the decompressed size" keeps its name, now over
the streamed decompressed cap (maxScannedBytes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PrzemekGalarowicz
PrzemekGalarowicz merged commit f9fa96b into main Nov 25, 2026
15 checks passed
@PrzemekGalarowicz
PrzemekGalarowicz deleted the feat/core-386-unpack-listed-paths-only branch November 25, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant