You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8f5d671
Browse filesBrowse the repository at this point in the historyBrowse files
fix(buffer): bound alignment exponents read from untrusted input (#9155)
## Rationale for this change
Found a few places where untrusted alignments from input files are not
properly validated and can lead to excessive allocation sizes / OOMs.
Alignments in the file format are a power-of-two exponent in a `u8`, and
`try_from_exponent` only rejects exponents that would overflow a `usize`
shift. Satisfying an alignment can require copying the buffer into an
allocation of `len + alignment` bytes, so an exponent of 40 on a 4-byte
buffer asks the reader for 1 TiB.
This cannot be contained by the caller: Rust aborts via
`handle_alloc_error` when an allocation fails rather than unwinding, so
it is a process abort rather than an error. Fuzzing the reader found it
from two directions, array-tree buffer descriptors and footer segment
specs, with exponents from 32 to 61.
- Related: #8819
## What changes are included in this PR?
- `Alignment::MAX_UNTRUSTED` (64K) and
`Alignment::try_from_untrusted_exponent`, which rejects anything above
it.
- Use it wherever an exponent comes from a file or message: array-tree
buffer descriptors, footer segment specs, postscript segments, and IPC
buffer messages. The IPC path used the panicking `from_exponent`.
- Regression tests for the array-tree and footer-segment paths, and for
the constructor's bounds.
## What APIs are changed? Are there any user-facing changes?
`Alignment` gains a public const and constructor. Reading a file that
declares a buffer or segment alignment above 65536 now errors where it
previously succeeded. 64K is what some ARM chips use as page alignment,
but larger alignments aren't useful here.
I used Claude Code to investigate this and draw up the initial fix and
write the tests. The issue itself was found using a libFuzzer-based
harness.
---------
Signed-off-by: Lorenz Hübschle <[email protected]>
0 commit comments