Repository navigation
Conversation
`Fdt::new` walks the structure tokens up to `FDT_END` bounded only by the length of the blob, and never checks that `FDT_END` lies within `off_dt_struct + size_dt_struct`. `FdtMut` then takes `size_dt_struct` and `off_dt_strings` as the bounds of the structure block, so a blob whose `size_dt_struct` is shorter than the structure that was walked can make `shift_dt_struct`, `compact` and `add_property` panic, or write a property name over a structure token. Return `InvalidHeader` from `validate` when `FDT_END` ends past `off_dt_struct + size_dt_struct`. Together with the existing check that the strings block starts at or after the end of the structure block, this also refuses a strings block that begins inside the structure. Fixes google#110 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #112 +/- ##
==========================================
+ Coverage 93.61% 93.66% +0.05%
==========================================
Files 26 26
Lines 3428 3459 +31
==========================================
+ Hits 3209 3240 +31
Misses 219 219 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| /// A root node with one child, `a`. The structure block is 28 bytes. | ||
| const FDT_CHILD_OK: &[u8] = &[ |
There was a problem hiding this comment.
Would it make sense to use the helpers added in #108 to construct this?
| // The walk above is bounded by the blob, not by `size_dt_struct`. | ||
| // Check that FDT_END lies within the structure block declared by the | ||
| // header, as `FdtMut` relies on `size_dt_struct` and `off_dt_strings` | ||
| // to bound the structure block. |
There was a problem hiding this comment.
This code comment is overly verbose IMO; it's fine to just write something like "validate that the entire dt_struct actually fits within what's declared in the header"
validatenow returnsInvalidHeader, reported atsize_dt_struct, whenFDT_ENDends pastoff_dt_struct + size_dt_struct. With the existing check that the strings block starts at or after the end of the structure block, this also refuses a strings block that begins inside the structure.The tests cover the three inputs from the issue, an exactly sized structure block, and
FDT_NOPs or padding afterFDT_ENDinsidesize_dt_struct, which are still accepted. A test onFdtMut::from_slicecovers the mutable path.Fixes #110