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 #2433

Merged
merged 1 commit into from
Nov 26, 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/bundle/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func readTarLayer(l v1.Layer) ([]byte, error) {
}

contents := make([]byte, header.Size)
if _, err := treader.Read(contents); err != nil && err != io.EOF {
if _, err := io.ReadFull(treader, contents); err != nil && err != io.EOF {
Copy link
Member

@chmouel chmouel Nov 18, 2024

Choose a reason for hiding this comment

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

that's not the same tho, you are going to read the whole content in memeory instead of stream it now.... would not cause other problems?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well today it doesn’t read everything. It truncates data. Also bundle are relatively small so it shouldn’t cause an issue in most case

Copy link

Choose a reason for hiding this comment

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

The extracted content would have to fit into an etcd, chunk? So there should be a maximum size of the blob, right?

If we want to prevent this from getting too big, we could potentially add validation into tkn bundle push to warn/fail if the size of the extracted content is too big.

Copy link
Member Author

Choose a reason for hiding this comment

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

But yes, there is definitely a follow-up to be done here, but this does fixes some existing issue.

Copy link

@arewm arewm Nov 18, 2024

Choose a reason for hiding this comment

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

#2434 (for the follow up)

Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to have guard on header.Size not being over 1.5MB (https://etcd.io/docs/v3.5/dev-guide/limit/), might introduce a denial of service via crafted compressed layer (zip bomb)

// 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