Bug: Missing Error Propagation on Deferred target.Close() in copyFile leads to Corrupted Rootfs

Open Beginner friendly
#566 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
backend

Research direction

Open pkg/unikontainers/utils.go and inspect the copyFile helper, starting with its io.Copy call and deferred target.Close(). Trace how errors are returned from the helper, then verify that a close failure is reported instead of being swallowed. Done means copyFile cannot report success when closing the destination file fails.

Written by the indexing model from the issue text.

Description

Core enhancement

Describe the bug
In pkg/unikontainers/utils.go, the copyFile helper manages transferring files via io.Copy() and leverages defer target.Close() for the destination file pointer cleanup.

Errors returned by target.Close() are currently silently swallowed. In Go, io.Copy() relies heavily on system-level buffered I/O. When caching runtime configurations or staging guest payloads into tight memory boundaries (e.g., small tmpfs partitions), the actual data flush often happens synchronously during process closure. When flushing fails (e.g. out of memory/disk space limits), target.Close() evaluates to an error. By abandoning this specific error matrix inside the defer, copyFile will erroneously return nil despite staging a truncated or corrupted file, which leads to urunc silently configuring corrupted boot components.

Proposed Solution
Refactor the function exit trajectory to explicitly invoke and validate the file pointer closure:
if err := target.Close(); err != nil {
return fmt.Errorf("failed to sync duplicated file: %w", err)
}
return nil

Dominant language
Go
Stars
298
Forks
202
Avg merge
2d 18h
Merged PRs (30d)
28

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from urunc-dev/urunc

All issues in urunc-dev/urunc

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.