Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
images: Fix read past end of file for pull --cache
Pull has two modes: - No cache: Extract and decompress the target VM image from the docker filesystem to the host filesystem. Result: One file, image.qcow. - Cache: Same as no cache, but also copy the compressed image to the host filesystem. Result: two files, image.qcow{,.zst} Previously, the logic for extracting the target VM image from the docker image with --cache enabled was to: - Extract and decompress the target file directly from inside the docker image filesystem to the host filesystem - Do not seek the source Reader back to the start of the file - Attempt (and fail) to copy the entire compressed image also to the host filesystem, but starting from the end of the source file. - This resulted in an EOF error because the reader wasn't reset to start from the beginning. Unfortunately, tar.Reader doesn't expose a way to seek back to the start of the source file. We could perhaps get an additional reference to a reader starting from the beginning of the current tar header in order to reset back to the beginning of the target file in cache mode, but this was getting a bit complicated. The solution in this patch is to: - Copy the compressed file to a temporary path on the host filesystem - Extract the compressed file from this temporary host-side cache to the intended destination directory. - If in cache mode, move the temporary file also to the output directory. Otherwise, delete the temporary file. There's one minor extra case, if the qcow inside the docker image is not compressed at all then we skip decompression, and in that case we also need to move the temporary path to the destination directory. Fixes: ea09cb7 ("images: Add docker pull support") Reported-by: Lorenz Bauer <[email protected]> Signed-off-by: Joe Stringer <[email protected]>
- Loading branch information