boot: espressif: bound flash_area_get_sectors to caller capacity #2899
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.22) × (1 − Review Confidence (0.72)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.22 · 18 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.54 · 3 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.176
Real PR Conversation Timeline
6 items
@nordicjm any ideas why CI is failing?
@nordicjm any ideas why CI is failing?
Can be ignored, the pypy project broke a feature and did a release, they've fixed it but not done another release
Approved
Approved these changes.
@almir-okato can you review?
Approved
Approved these changes.
nordicjm
sylvioalves
The Espressif port's flash_area_get_sectors() ignored the capacity passed in *count and wrote one entry for every flash sector in the area. With 4 KiB sectors and MCUBOOT_MAX_IMG_SECTORS at 512, any image slot or scratch area larger than 2 MiB overran the bootutil sector table on every boot. The function also dereferenced a NULL pointer when given an unknown flash area ID.
The function now stops at the given capacity and returns -ENOMEM, matching the Zephyr flash map, and rejects unknown IDs. A second commit adds static assertions on the configured slot and scratch sizes, so a layout that can never work fails at build time instead of at boot.
How to test
Build the port with an image slot larger than 2 MiB (768 sectors):
Without this change the build succeeds and the bootloader writes past the end of the sector table at boot. With it, the build fails with
Image slot exceeds MCUBOOT_MAX_IMG_SECTORS sectors.The change is not target-specific, so the same steps apply to other targets: