Delete temporary file when ExportedImageTar construction fails#51117
Open
wantaekchoi wants to merge 1 commit into
Open
Delete temporary file when ExportedImageTar construction fails#51117wantaekchoi wants to merge 1 commit into
wantaekchoi wants to merge 1 commit into
Conversation
ExportedImageTar creates a temporary file in its constructor and then copies the exported image into it and builds the layer factory. If either step throws, the constructor fails before the instance is assigned, so the try-with-resources statement that uses it never calls close() and the docker-layers- temporary file is left behind. Delete the temporary file when the constructor fails so its cleanup matches close(). Signed-off-by: wantaek <wantaekchoi@gmail.com>
wantaekchoi
force-pushed
the
fix/exported-image-tar-temp-file
branch
from
July 24, 2026 07:41
5badd6c to
f6480f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExportedImageTarcreates a temporary file in its constructor, copies the exported image into it, and then builds the layer factory from it:The only caller relies on try-with-resources to clean the file up:
If
Files.copyorLayerArchiveFactory.createthrows, the constructor fails after the temporary file has been created, so the instance is never assigned andclose()never runs.LayerArchiveFactory.createdoes throw on a tar that has neitherindex.jsonnormanifest.json(Assert.state(...)), which can happen for a malformed or unexpected image export, and thedocker-layers-file is then left behind in the temp directory.This wraps the constructor body so the temporary file is deleted if either step fails, matching the cleanup already done in
close().This mirrors #50919, which fixed the same kind of leak in the buildpack platform and included a temp-file test; the new test in
ExportedImageTarTestsuses the same approach.