Repository navigation
fix(fdt): check that the structure block contains FDT_END - #112
Merged
Merged
Conversation
|
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 94.38% 94.39%
=======================================
Files 27 27
Lines 3652 3658 +6
=======================================
+ Hits 3447 3453 +6
Misses 205 205 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
m4tx
reviewed
Nov 11, 2026
m4tx
reviewed
Nov 11, 2026
m4tx
requested changes
Nov 11, 2026
`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
The two tests for the `size_dt_struct` check spelled out an 84-byte blob by hand as a unit test in `src/fdt.rs`. The helpers that google#108 added in `tests/common/mod.rs` build the same blob (`build_chain_dtb(1)` is a root node with one child `a`), so the tests move to `tests/fdt.rs` and use them. The padding case now builds the trailing tokens into the structure block instead of patching header fields after the fact. The integration tests can only see `FdtParseError::kind`, so the assertion on the error offset goes away; the kind still carries the `InvalidHeader` message. Also shorten the comment on the check in `validate`, as asked in review.
calef
force-pushed
the
fix-struct-size-check
branch
from
November 16, 2026 19:38
73d15b7 to
be9e76e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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