Skip to content

Fix: prevent data loss in OCI spec Flush() via atomic write - #2204

Open
nextjohnp7 wants to merge 1 commit into
NVIDIA:mainfrom
nextjohnp7:fix/oci-spec-flush-data-loss
Open

nextjohnp7 wants to merge 1 commit into
NVIDIA:mainfrom
nextjohnp7:fix/oci-spec-flush-data-loss

Conversation

@nextjohnp7

Copy link
Copy Markdown

Summary

This PR fixes a critical data loss bug in internal/oci/spec_file.go where the Flush() method truncates the OCI specification file using os.Create() before writing new content. If the write operation fails (disk full, I/O error, permission denied), the original OCI config.json is permanently destroyed.

Changes

  • Modified Flush() in internal/oci/spec_file.go to write to a temporary file first, then atomically replace the target file using os.Rename() after successful write.
  • Added path/filepath import.
  • Temp file is cleaned up automatically on any failure during write, close, or rename.

Testing

  • Code compiles (syntax verified).
  • Note: Go is not installed locally, so go build / go test could not be executed on this machine.

Related Issue

Fixes #2203

DCO

Signed-off-by: John nextjohnp7@gmail.com

Write modified OCI specification to a temporary file first, then
atomically replace the target file after successful write. This
prevents data loss if the write operation fails mid-way (disk full,
I/O error, permission denied).

Fixes NVIDIA#2203

Signed-off-by: John <nextjohnp7@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

[Critical] Potential data loss in OCI spec Flush() - file truncated before write

1 participant