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

Conversation

vdemeester
Copy link
Member

@vdemeester vdemeester commented Nov 18, 2024

Changes

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.

Note: because bundles are cached, one will need to clean their cache
bundle (~/.tekton/bundles) to make sure it re-fetches correct
content.

Signed-off-by: Vincent Demeester [email protected]

/kind bug

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

Fix an issue on `bundle list` command with relatively big bundles that couldn't be parsed (truncated data)

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.

*Note:* because bundles are cached, one will need to clean their cache
bundle (`~/.tekton/bundles`) to make sure it re-fetches correct
content.

Signed-off-by: Vincent Demeester <[email protected]>
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Nov 18, 2024
@tekton-robot tekton-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 18, 2024
@vdemeester
Copy link
Member Author

cc @chmouel @piyush-garg @PuneetPunamiya
We will need to cherry-pick this to previous LTS releases.

@vdemeester
Copy link
Member Author

vdemeester commented Nov 18, 2024

This is related to tektoncd/pipeline#8388

Copy link

@arewm arewm left a comment

Choose a reason for hiding this comment

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

This seems like a reasonable change since the issue was indicative of not reading the entire blob.

@@ -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)

@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arewm, vinamra28

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 25, 2024
@piyush-garg
Copy link
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2024
@tekton-robot tekton-robot merged commit 5ab892f into tektoncd:main Nov 26, 2024
9 checks passed
@vdemeester vdemeester deleted the fix-bundle-list branch November 26, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants