Skip to content

fix: prevent unbounded tar layer allocation - #3201

Merged
tekton-robot merged 1 commit into
tektoncd:mainfrom
anwesha-palit-redhat:fix/SRVKP-13858
Sep 10, 2026
Merged

fix: prevent unbounded tar layer allocation#3201
tekton-robot merged 1 commit into
tektoncd:mainfrom
anwesha-palit-redhat:fix/SRVKP-13858

Conversation

@anwesha-palit-redhat

@anwesha-palit-redhat anwesha-palit-redhat commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Changes

Previously, readTarLayer used the tar header's declared size directly in make([]byte, header.Size), allowing a malicious bundle to specify an arbitrarily large size and potentially cause the CLI to exhaust available memory and crash.

Updated readTarLayer to use a bounded reader with a 1.5 MiB maximum layer size, preventing attacker-controlled tar metadata or oversized layer contents from causing excessive memory allocation. Added regression coverage to verify that layers exceeding the maximum size are rejected.

Signed-off-by: Anwesha Palit [apalit@redhat.com]

Assisted-by: Claude Opus 4.6

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

NONE

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Sep 7, 2026
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 7, 2026
@anwesha-palit-redhat
anwesha-palit-redhat force-pushed the fix/SRVKP-13858 branch 2 times, most recently from 04b8038 to c605381 Compare September 7, 2026 11:24
Comment thread pkg/bundle/reader.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The bounded read and regression coverage address the vulnerability with no unresolved issues.

Pull request overview

Prevents excessive memory allocation when reading untrusted bundle tar layers.

Changes:

  • Limits layer reads to 10 MiB.
  • Rejects oversized layers with a clear error.
  • Adds regression tests and updates test helpers.
File summaries
File Description
pkg/cmd/bundle/push_test.go Uses bounded layer reads in push tests.
pkg/bundle/reader.go Enforces the layer size limit.
pkg/bundle/reader_test.go Tests oversized-layer rejection.
pkg/bundle/builder_test.go Uses bounded layer reads in builder tests.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@divyansh42 divyansh42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @anwesha-palit-redhat
Overall it looks good, I just have a minor comment regarding the test files.

maxLayerSize is hardcoded as 10 << 20 in three test files separately from
the constant in reader.go. If the limit in reader.go changes,
the test copies won't catch the drift — no compiler error will surface it.
Consider exporting the constant (e.g. MaxLayerSize) from reader.go so
tests can reference it directly instead of duplicating the value.

@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: divyansh42

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

The pull request process is described here

Details 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 Sep 7, 2026
@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@divyansh42

Copy link
Copy Markdown
Member

/retest

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 8, 2026
Comment thread pkg/bundle/reader.go Outdated
@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@divyansh42

Copy link
Copy Markdown
Member

/retest

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The layer-size limit is incorrectly set to 1.5 MiB instead of 10 MiB.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread pkg/bundle/reader.go
@divyansh42

Copy link
Copy Markdown
Member

/cc @vdemeester @pratap0007

@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-v0.44.x

@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-v0.45.x

@savitaashture

Copy link
Copy Markdown
Contributor

LGTM

Previously, `readTarLayer` used the tar header's declared size directly in `make([]byte, header.Size)`, allowing a malicious bundle to specify an arbitrarily large size and potentially cause the CLI to exhaust available memory and crash.

Updated `readTarLayer` to use a bounded reader with a 10 MiB maximum layer size, preventing attacker-controlled tar metadata or oversized layer contents from causing excessive memory allocation. Added regression coverage to verify that layers exceeding the maximum size are rejected.

Signed-off-by: Anwesha Palit [apalit@redhat.com]

Assisted-by: Claude Opus 4.6
@pratap0007

Copy link
Copy Markdown
Contributor

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2026
@tekton-robot
tekton-robot merged commit bb57149 into tektoncd:main Sep 10, 2026
12 checks passed
@pratap0007

Copy link
Copy Markdown
Contributor

/cherry-pick release-v0.46.x

@tekton-robot

Copy link
Copy Markdown
Contributor

Cherry-pick to release-v0.46.x successful!

A new pull request has been created to cherry-pick this change to release-v0.46.x.

Please review and merge the cherry-pick PR.

@pratap0007

Copy link
Copy Markdown
Contributor

/cherry-pick release-v0.45.x

@tekton-robot

Copy link
Copy Markdown
Contributor

Cherry-pick to release-v0.45.x successful!

A new pull request has been created to cherry-pick this change to release-v0.45.x.

Please review and merge the cherry-pick PR.

@pratap0007

Copy link
Copy Markdown
Contributor

/cherry-pick release-v0.44.x

@pratap0007

Copy link
Copy Markdown
Contributor

/cherry-pick release-v0.37.x

@tekton-robot

Copy link
Copy Markdown
Contributor

Cherry-pick to release-v0.44.x successful!

A new pull request has been created to cherry-pick this change to release-v0.44.x.

Please review and merge the cherry-pick PR.

@tekton-robot

Copy link
Copy Markdown
Contributor

Cherry-pick to release-v0.37.x failed!

The automatic cherry-pick to release-v0.37.x failed.

Output:

🤖 Starting cherry-pick process...
Fetching PR #3201 information...
Found merge commit: bb57149f2ea2d1e3f3c16c7fe0d849657103a47a
PR title: fix: prevent unbounded tar layer allocation
Fetching target branch: release-v0.37.x...
From https://github.com/tektoncd/cli
 * branch                release-v0.37.x -> FETCH_HEAD
Checking for existing cherry-pick PR...
Creating cherry-pick branch: cherry-pick-3201-to-release-v0.37.x...
Switched to a new branch 'cherry-pick-3201-to-release-v0.37.x'
branch 'cherry-pick-3201-to-release-v0.37.x' set up to track 'origin/release-v0.37.x'.
Cherry-picking commit bb57149f2ea2d1e3f3c16c7fe0d849657103a47a...
Auto-merging pkg/bundle/reader.go
CONFLICT (content): Merge conflict in pkg/bundle/reader.go
error: could not apply bb57149f2... fix: prevent unbounded tar layer allocation
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
❌ ERROR: Cherry-pick failed due to conflicts or other errors.

Next steps:

  • Check the action logs for complete details
  • If the PR is not merged, merge it first and try again
  • If there are conflicts, you'll need to manually cherry-pick this PR

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. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants