Repository navigation
fix(sol-types): validate dynamic array length before allocation - #1164
Conversation
|
This fixes the reported non-ZST preallocation case, but I think two cases remain before the mitigation is complete:
I suggest making the footprint a sealed if T::MINIMUM_WORDS == 0 {
return Ok(Self(Vec::new()));
}
let required_words = T::MINIMUM_WORDS
.checked_mul(len)
.ok_or(Error::Overrun)?;
if required_words > child.remaining_words() {
return Err(Error::Overrun);
}
Useful additional tests would cover a multiword static element, checked-multiplication overflow, a dynamic element requiring one offset word, and a huge ZST length. |
|
Should be ready for review again. |
|
The zero-sized-element fast path changes decoding semantics: The ABI specification defines Could we avoid iterating over an attacker-controlled length while still constructing a zero-sized |
Co-authored-by: Derek Cofausper <[email protected]>
Co-authored-by: Derek Cofausper <[email protected]>
Motivation
Dynamic-array decoding allocated its output buffer before checking whether enough data was available, doing unnecessary work when decoding could not proceed.
Solution
Check the available ABI words before allocation while preserving zero-sized element behavior. Add regression coverage for both paths.
Codex was used to help understand the existing code and assist with the implementation. I fully understand and manually reviewed the resulting changes.
PR Checklist