xhh233 commented on issue #22270:
URL: https://github.com/apache/nuttx/issues/22270#issuecomment-7131102473
Candidate fix:
```diff
--- a/drivers/mtd/mtd_config_nvs.c
+++ b/drivers/mtd/mtd_config_nvs.c
@@ -1336,6 +1336,17 @@
fs->nblocks = geo.neraseblocks / CONFIG_MTD_CONFIG_BLOCKSIZE_MULTIPLE;
fs->progsize = geo.blocksize;
+ /* The low 16 bits of an NVS address hold the byte offset within a
+ * block, so a block larger than 64 KiB cannot be represented. Reject
+ * it before the (uint16_t) casts below truncate the block-tail offset.
+ */
+
+ if (fs->blocksize > (NVS_ADDR_OFFS_MASK + 1))
+ {
+ ferr("Configuration error - block size exceeds 16-bit offset\n");
+ return -EINVAL;
+ }
+
size_t ate_size = nvs_ate_size(fs);
NVS_ATE(second_ate, ate_size);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]