Skip to content

Mask tar header file modes during extraction - #369

Merged
AlexVulaj merged 2 commits into
mainfrom
issue-332-tar-file-mode
Nov 30, 2026
Merged

AlexVulaj merged 2 commits into
mainfrom
issue-332-tar-file-mode

Conversation

@AlexVulaj

@AlexVulaj AlexVulaj commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #332

Some bundle tar headers include Unix file-type bits in Mode (for example, 0100644). Passing those bits directly to os.Root.OpenFile can fail with “unsupported file mode.”

Mask the tar mode with os.ModePerm before opening the extracted file. Add a regression test that extracts a regular tar entry with file-type bits and verifies its contents.

Summary by CodeRabbit

  • Bug Fixes
    • Improved OCI archive extraction for files with standard archive metadata. Extracted files now retain their expected contents, with permissions applied only from the permission bits rather than other file metadata. This helps prevent file type information in an archive from interfering with extraction.

@AlexVulaj
AlexVulaj requested review from mclasmeier and porridge and removed request for porridge November 30, 2026 14:49
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review.

Walkthrough

Regular files extracted from tar archives are now created with permission bits from the header. A test covers extraction of an entry whose mode includes file-type bits.

Changes: Tar extraction

Layer / File(s) Summary
Mask regular-file modes
internal/ocihelper/ocihelper.go, internal/ocihelper/ocihelper_test.go
Regular-file creation masks the tar header mode with os.ModePerm. The test extracts an entry with mode 0o100644 and checks its contents.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: mclasmeier

Merge Risk: Minimal · up to f4aed

This change lets tar layers whose headers include file-type bits in the mode extract successfully, and regular files are created with permission bits only. A regression test covers the case. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Mask tar header file modes during extraction" matches the main change. The raw summary says tar extraction now masks regular-file modes with os.ModePerm before creating files, and a regress…
Linked Issues check Passed [#332] The issue requires that extractTarToDir mask tar header mode bits with os.ModePerm before calling root.OpenFile, so file-type bits such as 0100644 do not cause an "unsupported file mode…
Out of Scope Changes check Passed The changes stay within #332. The production change is one expression in the regular-file open call. The added test exercises that exact path. The whole-PR diff of ocihelper_test.go shows a new file…
Full details: Title check

Explanation

The title "Mask tar header file modes during extraction" matches the main change. The raw summary says tar extraction now masks regular-file modes with os.ModePerm before creating files, and a regression test was added. The PR objectives describe the same fix for issue #332, where tar header file-type bits caused Root.OpenFile to reject the mode.

Full details: Linked Issues check

Explanation

[#332] The issue requires that extractTarToDir mask tar header mode bits with os.ModePerm before calling root.OpenFile, so file-type bits such as 0100644 do not cause an "unsupported file mode" error. At the current head (f4aed2f), internal/ocihelper/ocihelper.go in the tar.TypeReg branch calls root.OpenFile(entryName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(header.Mode)&os.ModePerm). This matches the fix that the issue specifies. The new test TestExtractTarToDirMasksFileTypeBits in internal/ocihelper/ocihelper_test.go builds a tar entry crd.yaml with Mode: 0o100644, calls extractTarToDir, and verifies the extracted contents. Without the mask, the open call fails, so the test covers the reported failure. The whole-PR text diff for ocihelper.go was unavailable (changed blobs missing from checkout). The base version was therefore not compared line by line. The head file read and the PR summary together establish the change. The changes since the previous review are not visible in the current evidence, so the earlier conclusion is preserved on the current head file.

Full details: Out of Scope Changes check

Explanation

The changes stay within #332. The production change is one expression in the regular-file open call. The added test exercises that exact path. The whole-PR diff of ocihelper_test.go shows a new file with 40 added lines and no other edits. The directory, symlink, and default branches of extractTarToDir are unchanged in the reviewed head evidence. The ocihelper.go whole-PR diff was unavailable, so the claim that no other production lines changed rests on the PR summary (+1/-1), not on a direct diff read.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: stackrox/roxie
  • Branch: main
  • File: .coderabbit.yml
  • Commit: 0d0a0d3
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 5c35e8b5-6286-471d-8cf5-5d3193fb6ba8
Commits

Reviewing files that changed from the base of the PR and between 5c2adb5 and f4aed2f.

Files selected for processing: 1

  • internal/ocihelper/ocihelper_test.go
Files skipped from review as they are similar to previous changes: 1

  • internal/ocihelper/ocihelper_test.go

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@AlexVulaj
AlexVulaj requested a review from porridge November 30, 2026 14:49
@AlexVulaj AlexVulaj self-assigned this Nov 30, 2026

@mclasmeier mclasmeier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you! Just a few nits, up to you.

Comment thread internal/ocihelper/ocihelper_test.go Resolved
Comment thread internal/ocihelper/ocihelper_test.go Resolved
Comment thread internal/ocihelper/ocihelper_test.go Resolved
@AlexVulaj
AlexVulaj enabled auto-merge (squash) November 30, 2026 15:38
@AlexVulaj
AlexVulaj merged commit d93f82b into main Nov 30, 2026
8 checks passed
@AlexVulaj
AlexVulaj deleted the issue-332-tar-file-mode branch November 30, 2026 15:39
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.

OCI layer extraction fails with "unsupported file mode" on some bundle images

2 participants