Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use io.ReadFull to read the bundle content #8389

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/resolution/resolver/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func readTarLayer(layer v1.Layer) ([]byte, error) {
}

contents := make([]byte, header.Size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header.Size is smaller than the actual size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope it has the right size.

Copy link
Contributor

@lcarva lcarva Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why does it not read all the data into the buffer of the right size?
(Likely a noob question 😅)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

io.Reader doesn't give you that guarantee. Why ? I am not sure 🙃

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)
}
Expand Down