From 7b76131b656adca53b12c6bf0f07b7ee97a656df Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 18 Nov 2024 15:56:03 +0100 Subject: [PATCH] Use io.ReadFull to read the bundle content The io.Reader documentation says: > Read reads up to len(p) bytes into p. It returns the number of bytes > read (0 <= n <= len(p)) and any error encountered. ... If some data is > available but not len(p) bytes, Read conventionally returns what is > available instead of waiting for more. Read is not guaranteed to fill the data argument. Use io.ReadFull to fill the buffer. In some cases (a relatively big bundle), the bundle content was not completely read and it would fail to parse. Using `io.ReadFull` fixes the issue. Signed-off-by: Vincent Demeester --- pkg/resolution/resolver/bundle/bundle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resolution/resolver/bundle/bundle.go b/pkg/resolution/resolver/bundle/bundle.go index f5f9997f63b..bc6a7fed07f 100644 --- a/pkg/resolution/resolver/bundle/bundle.go +++ b/pkg/resolution/resolver/bundle/bundle.go @@ -194,7 +194,7 @@ func readTarLayer(layer v1.Layer) ([]byte, error) { } contents := make([]byte, header.Size) - if _, err := treader.Read(contents); err != nil && !errors.Is(err, io.EOF) { + if _, err := io.ReadFull(treader, contents); err != nil && err != io.EOF { // We only allow 1 resource per layer so this tar bundle should have one and only one file. return nil, fmt.Errorf("failed to read tar bundle: %w", err) }