Commit 8981a1b
authored
fix(chain): cap block::Hash and CountedHeader preallocation at protocol-level constants (#10570)
`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.
Co-authored-by: dingledropper <dingledropper@users.noreply.github.com>1 parent b46207b commit 8981a1b
4 files changed
Lines changed: 83 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
263 | 282 | | |
264 | | - | |
265 | 283 | | |
266 | 284 | | |
267 | | - | |
268 | | - | |
269 | | - | |
| 285 | + | |
270 | 286 | | |
271 | 287 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | 155 | | |
167 | 156 | | |
168 | 157 | | |
169 | 158 | | |
170 | 159 | | |
171 | 160 | | |
172 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
173 | 167 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
177 | 171 | | |
178 | 172 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | | - | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
15 | 27 | | |
16 | | - | |
| 28 | + | |
17 | 29 | | |
18 | 30 | | |
19 | 31 | | |
20 | | - | |
| 32 | + | |
21 | 33 | | |
22 | 34 | | |
23 | 35 | | |
24 | | - | |
25 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
29 | 43 | | |
30 | | - | |
| 44 | + | |
31 | 45 | | |
32 | 46 | | |
33 | 47 | | |
34 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | | - | |
38 | | - | |
39 | 54 | | |
40 | 55 | | |
41 | 56 | | |
| 57 | + | |
42 | 58 | | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
59 | 76 | | |
60 | 77 | | |
61 | 78 | | |
62 | | - | |
63 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
64 | 85 | | |
65 | 86 | | |
66 | 87 | | |
| |||
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
72 | | - | |
| 93 | + | |
73 | 94 | | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
77 | 102 | | |
78 | 103 | | |
79 | | - | |
80 | | - | |
81 | 104 | | |
82 | 105 | | |
83 | 106 | | |
| 107 | + | |
84 | 108 | | |
| 109 | + | |
85 | 110 | | |
86 | 111 | | |
87 | 112 | | |
0 commit comments