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
fix(chain): cap block::Hash and CountedHeader preallocation at protocol-level constants
`block::Hash::max_allocation` previously returned 65,535 (derived from
`MAX_PROTOCOL_MESSAGE_LEN / 32`), and `CountedHeader::max_allocation`
returned ~1,409 (same message-size-derived shape). Both are reachable via
`Vec::zcash_deserialize` from any post-handshake peer through `getblocks`,
`getheaders`, and `headers` messages. A peer can claim up to those counts
and force `Vec::with_capacity` preallocation before any payload bytes are
read.
Cap at protocol-level constants:
- `MAX_BLOCK_LOCATOR_LENGTH = 101`, a new `block`-module constant that
matches Bitcoin Core's `MAX_LOCATOR_SZ` in `net_processing.cpp` (which
zcashd inherits).
- The existing `MAX_HEADERS_PER_MESSAGE = 160` constant from
`crate::serialization::zcash_serialize`, already enforced on the sending
side and at the codec level for `read_headers` (PR #10528).
Same fix shape applied to `AddrV1`/`AddrV2` in PR #10494 for
GHSA-xr93-pcq3-pxf8.
CWE-770 (Allocation of Resources Without Limits or Throttling).
Tests:
- `block_hash_max_allocation` proptest updated to assert
`Hash::max_allocation() == MAX_BLOCK_LOCATOR_LENGTH`.
- `counted_header_max_allocation` proptest updated to assert
`CountedHeader::max_allocation() == MAX_HEADERS_PER_MESSAGE as u64`.
- Test-only constants `BLOCK_HEADER_LENGTH` and `MIN_COUNTED_HEADER_LEN`,
which were used by the old message-size-derived formula in `header.rs`,
moved into the `preallocate` test module where they are the only
consumers.
0 commit comments