fix: prevent unbounded tar layer allocation - #3201
Conversation
04b8038 to
c605381
Compare
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
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.
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
c605381 to
6a9c95d
Compare
|
/retest |
1 similar comment
|
/retest |
6a9c95d to
43832ca
Compare
|
/retest |
1 similar comment
|
/retest |
There was a problem hiding this comment.
🟡 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
|
/cherry-pick release-v0.44.x |
|
/cherry-pick release-v0.45.x |
|
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
43832ca to
bff5b12
Compare
|
/lgtm |
|
/cherry-pick release-v0.46.x |
|
✅ Cherry-pick to A new pull request has been created to cherry-pick this change to Please review and merge the cherry-pick PR. |
|
/cherry-pick release-v0.45.x |
|
✅ Cherry-pick to A new pull request has been created to cherry-pick this change to Please review and merge the cherry-pick PR. |
|
/cherry-pick release-v0.44.x |
|
/cherry-pick release-v0.37.x |
|
✅ Cherry-pick to A new pull request has been created to cherry-pick this change to Please review and merge the cherry-pick PR. |
|
❌ Cherry-pick to The automatic cherry-pick to Output: Next steps:
|
Changes
Previously,
readTarLayerused the tar header's declared size directly inmake([]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
readTarLayerto 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:
make checkmake generatedSee the contribution guide
for more details.
Release Notes