From 79dee191872583d67889c879a8abda283875ca56 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 12 Dec 2023 14:43:53 +0100 Subject: [PATCH] chunked: flush the input tarball to the output Flush the entire input tarball to the output in the zstd:chunked stream writer. This is needed to include any trailing zeros that affect the uncompressed digest. Closes: https://github.com/containers/storage/issues/1771 Signed-off-by: Giuseppe Scrivano --- pkg/chunked/compressor/compressor.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/chunked/compressor/compressor.go b/pkg/chunked/compressor/compressor.go index a5feb870f5..a2fd904caf 100644 --- a/pkg/chunked/compressor/compressor.go +++ b/pkg/chunked/compressor/compressor.go @@ -420,6 +420,14 @@ func writeZstdChunkedStream(destFile io.Writer, outMetadata map[string]string, r zstdWriter.Close() return err } + + // make sure the entire tarball is flushed to the output as it might contain + // some trailing zeros that affect the checksum. + if _, err := io.Copy(zstdWriter, its); err != nil { + zstdWriter.Close() + return err + } + if err := zstdWriter.Flush(); err != nil { zstdWriter.Close() return err