Commit ba4027e
committed
fix(flexbuffers): harden Reader against panics from untrusted input
The FlexBuffers Rust Reader had multiple code paths that could panic
when processing malformed or malicious input:
1. Bounds check failures: `get_bool()`, `get_key_len()`, `read_usize()`,
and `MapReader::lazy_strcmp()` used direct slice indexing
(`buffer[addr..]`) which panics on out-of-bounds access. Replaced
with checked `.get()` calls that return errors instead.
2. Integer overflow: `get_str()`, `get_blob()`, `get_key()`,
`get_slice()`, `VectorReader::index()`, `VectorReader::get_elem_type()`,
`MapReader::index_key()`, and `MapReader::usize_index()` computed
`address + length` or `address + width * count` using unchecked
arithmetic, which panics on overflow in debug mode and wraps in
release mode. Replaced with `checked_add()` / `checked_mul()`.
These panics are reachable from any code that deserializes FlexBuffers
from untrusted sources (network, files, IPC), enabling denial of service.
All three crash inputs found by fuzzing now return `Err` instead of
panicking.
Fixes #89231 parent c21bda1 commit ba4027e
3 files changed
+74
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
| |||
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
92 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
118 | | - | |
119 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
120 | 136 | | |
121 | 137 | | |
122 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
308 | 315 | | |
309 | 316 | | |
310 | 317 | | |
| |||
323 | 330 | | |
324 | 331 | | |
325 | 332 | | |
326 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
327 | 339 | | |
328 | 340 | | |
329 | 341 | | |
| |||
332 | 344 | | |
333 | 345 | | |
334 | 346 | | |
335 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
336 | 352 | | |
337 | 353 | | |
338 | 354 | | |
| |||
342 | 358 | | |
343 | 359 | | |
344 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
345 | 366 | | |
346 | 367 | | |
347 | | - | |
| 368 | + | |
348 | 369 | | |
349 | 370 | | |
350 | 371 | | |
351 | 372 | | |
352 | 373 | | |
353 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
354 | 379 | | |
355 | 380 | | |
356 | | - | |
| 381 | + | |
357 | 382 | | |
358 | 383 | | |
359 | 384 | | |
| |||
366 | 391 | | |
367 | 392 | | |
368 | 393 | | |
369 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
370 | 399 | | |
371 | 400 | | |
372 | 401 | | |
| |||
601 | 630 | | |
602 | 631 | | |
603 | 632 | | |
604 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
605 | 637 | | |
606 | | - | |
| 638 | + | |
607 | 639 | | |
608 | 640 | | |
609 | 641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
73 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
| |||
0 commit comments