Skip to content

fix(builtins): bound file copies, archive output, and backup paths - #887

Merged
ewhauser merged 2 commits into
mainfrom
fix/builtins-file-safety-2
Oct 20, 2026
Merged

ewhauser merged 2 commits into
mainfrom
fix/builtins-file-safety-2

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Fixes the internal/builtins findings from the second review of main at 19ff56a.

  • cp/install: copies now go through copyBounded with MaxFileBytes and check for cancellation. cp /dev/zero /tmp/big fails with cp: error writing '/tmp/big': File too large instead of growing until the process is killed.
  • dd: the skip discard loop checks ctx. Runtime change (outside builtins, kept minimal): internal/runtime/virtual_devices.go adds Seek, a no-op on readable virtual devices, so dd if=/dev/zero skip=9223372036854775807 returns at once. Write-only handles still report an illegal seek, which keeps the existing dd seek= > /dev/full behavior.
  • mv -b / install -b / ln -b: these now refuse when the backup path is the source, using cp's existing message (backing up 'y' might destroy source; 'y~' not moved).
  • tar -c: skips any member that has the same identity as the archive, so an archive reached through a hard link is no longer read while it is being written.
  • gzip -c / zcat / gzip -t / tar -O: output to stdout is capped at MaxFileBytes.
  • tar -x: adds a total budget of 16 × MaxFileBytes and at most 100000 members (archive exceeds extraction limit).
  • tar: backslashes in member names stay literal, as in GNU tar on POSIX.
  • tar: relative symlink targets are also checked against the realpath of the parent directory, which catches escapes through symlinked parents under SymlinkFollow.

SPEC.md: the file-size limits bullet now lists the cp/install and stdout decompression caps and the tar extraction budget.

Each fix has a regression test (internal/builtins/file_safety_test.go, plus TestDdDiscardObservesContext). make lint is clean, and go test -race ./internal/builtins/... ./internal/runtime/... passes.

@ewhauser
ewhauser enabled auto-merge (squash) October 20, 2026 14:57
@ewhauser
ewhauser merged commit 529fd30 into main Oct 20, 2026
17 checks passed
@ewhauser
ewhauser deleted the fix/builtins-file-safety-2 branch October 20, 2026 15:48
@ewhauser ewhauser mentioned this pull request Oct 20, 2026
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