Skip to content

cli/context/store: fix Export writing a truncated tar archive - #7334

Open
2arian3 wants to merge 1 commit into
docker:masterfrom
2arian3:context-export-complete-tar
Open

2arian3 wants to merge 1 commit into
docker:masterfrom
2arian3:context-export-complete-tar

Conversation

@2arian3

@2arian3 2arian3 commented Sep 25, 2026

Copy link
Copy Markdown

Summary

Export() deferred tw.Close() before writer.Close(). Deferred calls run last-in, first-out, so the pipe was closed first, and tw.Close() failed with io.ErrClosedPipe before it could write the padding after the last file and the end-of-archive marker. That error was ignored, so every docker context export produced an incomplete archive.

docker context import still reads these, but when the context has TLS files, stricter tar readers reject them. The issue has a reproducer.

This closes the tar writer before the pipe, and passes its error to CloseWithError instead of dropping it. The new test fails without the change: the exported archive isn't a multiple of 512 bytes, and it has no end-of-archive marker.

With this change, the reproducer from the issue produces a complete archive that Python's tarfile and the macOS tar both read, and docker context import still works. Errors, such as exporting a context that doesn't exist, are reported the same way as before.

Release notes (optional)

Fix `docker context export` writing an incomplete tar archive.

Export deferred tw.Close() before writer.Close(). Deferred calls run
last-in, first-out, so the pipe was closed first, and tw.Close() failed
with io.ErrClosedPipe before it could write the padding after the last
file and the end-of-archive marker. The error was ignored.

"docker context import" still reads these archives, because Go's
archive/tar stops at EOF. Stricter readers don't: with TLS files in the
context, Python's tarfile rejects the export, and so does the macOS tar
when reading it from a pipe.

Close the tar writer before closing the pipe, and pass its error to
CloseWithError instead of dropping it.

Signed-off-by: Arian Boukani <arbo@yorku.ca>
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.

docker context export writes a truncated tar archive

1 participant