Commit 5fd67f9
fix(content): reject descriptor sizes exceeding 32 MiB in ReadAll (#1153)
## Summary
- Adds a `maxDescriptorSize` constant (32 MiB) in `content/reader.go`
- Rejects any descriptor whose `Size` exceeds this limit in `ReadAll()`
with `ErrInvalidDescriptorSize`, the same error already returned for
negative sizes
- Adds `TestReadAll_OversizedDescriptor` to confirm a 2^62 size value is
safely rejected without panic
Fixes GHSA-f36w-mj3v-6jqv
### Root cause
`ReadAll()` only checked for negative `Size` values. A crafted OCI
layout `index.json` can supply a large positive `Size` (e.g.
`4611686018427387904`, or 2^62), causing `make([]byte, desc.Size)` to
trigger a Go runtime panic (`makeslice: len out of range`) before any
allocation occurs. The `recover()` in `syncutil/once.go` unconditionally
re-panics, so the ORAS process terminates unconditionally.
This is reachable via any ORAS CLI command that accepts `--oci-layout`,
`--from-oci-layout`, or `--input` flags (`cp`, `pull`, `restore`,
`manifest fetch`, `repo tags`, `resolve`, `discover`).
### Fix
```go
const maxDescriptorSize = 32 * 1024 * 1024 // 32 MiB
func ReadAll(r io.Reader, desc ocispec.Descriptor) ([]byte, error) {
if desc.Size < 0 || desc.Size > maxDescriptorSize {
return nil, ErrInvalidDescriptorSize
}
...
}
```
## Test plan
- [x] `TestReadAll_OversizedDescriptor` — verifies `Size:
4611686018427387904` returns `ErrInvalidDescriptorSize` without panic
- [x] All existing `TestReadAll_*` tests continue to pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 4683c46 commit 5fd67f9
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
122 | | - | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
0 commit comments