Skip to content

tarfs: keep a package file's changes once it is opened to write - #2612

Merged
kevinmdavis merged 2 commits into
chainguard-dev:mainfrom
kevinmdavis:con-3671-tarfs-truncate
Oct 28, 2026
Merged

kevinmdavis merged 2 commits into
chainguard-dev:mainfrom
kevinmdavis:con-3671-tarfs-truncate

Conversation

@kevinmdavis

Copy link
Copy Markdown
Member

A package-backed file opened to be modified copies its content into memory, and tarfs took empty memory to mean the file was still the package's. A file truncated to empty through OpenFile then read back the package's content, at the package's size, so the truncation was lost.

A node now records that it was opened to write, and from then on its content is what is in memory, even when that is nothing.

@kevinmdavis
kevinmdavis force-pushed the con-3671-tarfs-truncate branch from 368e830 to a2abe68 Compare October 27, 2026 23:45
shimmerjs
shimmerjs previously approved these changes Oct 28, 2026

@codysoyland codysoyland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review by unblok using Codex · gpt-6-astra · medium reasoning effort

Agent recommended action: Request changes

Requesting changes: a failed writable open can permanently hide the package file's content.

Worth fixing

  • Commit the written state only after buffering succeeds: pkg/tarfs/fs.go:429.

What I verified

  • At a2abe68, a backing reader returning zero bytes and an error makes OpenFile(O_RDWR) fail, but the next ReadFile succeeds with empty content and Stat reports zero. The same reproduction against the base returns the original eight bytes.
  • The written check at pkg/tarfs/fs.go:409 prevents recovery after that failure; Size uses the same state at pkg/tarfs/fs.go:999.
  • TestTarFSTruncatePackageFile covers successful truncation and subsequent content/size, but not a failed backing read.

Comment thread pkg/tarfs/fs.go Resolved
kevinmdavis and others added 2 commits October 28, 2026 17:24
A package-backed file opened to be modified copies its content into
memory, and tarfs took empty memory to mean the file was still the
package's. A file truncated to empty through OpenFile then read back the
package's content, at the package's size, so the truncation was lost.

A node now records that it was opened to write, and from then on its
content is what is in memory, even when that is nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kevinmdavis
kevinmdavis force-pushed the con-3671-tarfs-truncate branch from a2abe68 to e060645 Compare October 28, 2026 17:25

@codysoyland codysoyland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review by unblok using Codex · gpt-6-astra · medium reasoning effort

Re-reviewed after e060645. LGTM.

Addressed: failed backing read now leaves the node unchanged; pkg/tarfs/fs.go:427-434 commits data and written only after success.

What I verified

  • The error return at pkg/tarfs/fs.go:428 precedes both node mutations, including when ReadAll returns partial data.
  • Ran TestTarFSPackageFileReadFailure at e060645: passed. It checks preserved content and size, a successful writable retry, and unchanged backing content.
  • Re-ran my original zero-byte read-error reproduction at e060645: subsequent ReadFile returns the original eight bytes and Stat reports size eight.

@kevinmdavis
kevinmdavis merged commit ad680c7 into chainguard-dev:main Oct 28, 2026
12 checks passed
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.

4 participants