Skip to content

fix(macos-pkg): retain cpio hard-link contents - #15141

Closed
ShuaixinHuang wants to merge 4 commits into
morluto:mainfrom
ShuaixinHuang:fix/macos-pkg-odc-hardlink-content
Closed

ShuaixinHuang wants to merge 4 commits into
morluto:mainfrom
ShuaixinHuang:fix/macos-pkg-odc-hardlink-content

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A macOS flat installer can store a regular file's body once in its odc cpio payload and give another path the same device and inode with a zero-size record. A reference libarchive read identified alias.txt as a hard link to original.txt. REA's CLI showed the original as 8 bytes and the alias as 0 bytes, and extraction wrote an empty alias.

Change and scope

The odc parser groups multiply linked regular files by device and inode within each archive. A zero-size alias shares the observed bytes and size of a nonempty group member when the group has an unambiguous body. Extraction uses the existing bounded file materializer, which writes ordinary output files. No host hard links are created. An unrelated empty file still extracts as empty.

This corrects the existing macOS package reader. The standalone cpio proposal in #15083 serves a different reader. No corresponding issue was found in the targeted search.

Verification

  • The new CLI extraction regression failed on the base because the alias was empty. After the fix, both paths contain the fixture text.
  • All 70 focused tests passed across the compiled CLI and MCP plus macOS package reader suites. Test discovery found all 4,084 files exactly once.
  • The normal push hook passed typecheck, lint and architecture guards.
  • Validation used synthetic XAR/odc fixtures on Linux and a libarchive reference read. No installer was run and no macOS-generated package was exercised. An initial build ran out of disk space. The full focused rerun succeeded after cleaning generated build directories.

Author readiness

Human owner: @ShuaixinHuang

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

Review follow-up

Commit 0eae1d1be charges resolved alias contents to the same package-wide allowance as the decoded archive before publishing entries. It retires inode groups at their declared link count. Tests cover forward aliases, inode reuse, archive isolation, and disagreeing recorded bodies. All 72 focused reader, CLI and MCP tests and the normal push gates passed locally. Package tests used synthetic fixtures on Linux.

Commit 79ecb91ff uses the same leading-current-directory normalization as package entry publication to pair AppleDouble siblings. It excludes paired empty sidecars from data groups when the inode has a validated AppleDouble sibling, preserving the recorded sidecar bodies. The CLI regression covers mixed prefixes and an empty sidecar alongside a nonempty data file. Numeric reads now use BinaryReader, addressing the previous head's architecture guard failure. All 72 focused reader, CLI and MCP tests and the normal typecheck, lint, module boundary and architecture gates passed locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T05:25:00.609948Z 79ecb91 New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the reported sidecar mix-up is addressed, and no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the reported sidecar mix-up is addressed, and no new blocking issue was found.

Summary

Retains file contents for cpio hard-link aliases inside macOS packages.

  • macOS package aliases now get their archived file contents.

Reviews (4) · Last reviewed commit: "fix(macos-pkg): pair AppleDouble aliases..." · Reviewed by Greptile

Comment thread src/artifacts/macosPkg/CpioOdc.ts Resolved
Comment thread tests/acceptance/macosPkgCli.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b913d164fa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/artifacts/macosPkg/CpioOdc.ts Resolved
Comment thread src/artifacts/macosPkg/CpioOdc.ts Resolved
@vincentkoc

Copy link
Copy Markdown
Collaborator

I reproduced a remaining extraction regression on 0eae1d1be with an Apple pkgbuild package. The source had two hard links to an empty file. In the odc Payload, each zero-byte data record is followed by a 163-byte ._ AppleDouble record with the same device, inode and link count. The reader assigns 163 bytes starting with 00 05 16 07 to each empty data file and charges 326 alias bytes. I’m fixing the grouping on this PR and checking the extracted bytes against the package source.

Comment thread src/artifacts/macosPkg/CpioOdc.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33c3b3b20d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/artifacts/macosPkg/CpioOdc.ts Resolved
@vincentkoc

Copy link
Copy Markdown
Collaborator

Closing this implementation after reproducing a wrong-file extraction on the latest revision, 79ecb91ff. Thanks to @ShuaixinHuang for the original CLI reproduction, the libarchive comparison, and the fixes for mixed path prefixes and empty AppleDouble sidecars. The underlying bug remains open in #15154.

I ran the compiled CLI from https://github.com/morluto/rea/actions/runs/46358705750 against three reduced flat packages. All entries use the same odc device, inode and link count of two.

Package Records in archive order Extracted result
Ordinary hard links alone ordinary="A", ._ordinary=empty ._ordinary="A"
File and AppleDouble records alone ._base=metadata, ./base=empty, alias="C", ._alias=empty base="C"
Both groups, in the order above Same six records, with the inode reused after the first complete group ._ordinary is empty and base="A"

Both controls pass in isolation. Joining them makes the second file inherit bytes from the first group. The AppleDouble header found later in the archive causes the parser to exclude an earlier ordinary ._ordinary from its own group. Extraction succeeds with the wrong contents. The native Apple pkgbuild control still passed on this head, with all eight files matching their archived bytes.

The next implementation needs to preserve both controls when their inode is reused. If the archive does not identify which body belongs to a path, preserve that uncertainty instead of publishing another file's bytes. The regression and original report are linked from #15154.

@vincentkoc vincentkoc closed this Nov 30, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79ecb91ffa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

!(
sidecars.size > 0 &&
member.size === 0 &&
appleDoubleSibling(member, names)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve empty sidecars at a partial cpio boundary

If cpio parsing stops after ._original (valid AppleDouble), original (hello), and empty ._alias, but before alias, with all four records sharing a device/inode and nlink=2, this lookup misses the unparsed sibling. ._alias then enters dataRecords and is rewritten with hello; the complete-archive control leaves it empty. I reproduced this for both truncated decoded cpio and the default 4,096-member cutoff. Because MacosPkgArtifactReader.#expandArchive publishes members alongside partialFailure, the invented contents reach inventory digests and extraction. Preserve the unresolved sidecar rather than treating a sibling outside the parsed prefix as absent.

AGENTS.md reference: AGENTS.md:L76-L76

Useful? React with 👍 / 👎.

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.

2 participants