And another recommendation applied

This commit is contained in:
jpirnay
2026-04-15 10:57:03 +02:00
parent 51e6be58c8
commit 7e32838a16
+9 -2
View File
@@ -25,6 +25,9 @@ bool readString(FsFile& f, std::string& out) {
out.resize(len); out.resize(len);
return f.read(reinterpret_cast<uint8_t*>(&out[0]), len) == len; return f.read(reinterpret_cast<uint8_t*>(&out[0]), len) == len;
} }
constexpr uint16_t MAX_ENTRIES = 1000;
constexpr uint16_t MAX_BOOKMARKS_PER_ENTRY = 1000;
} // namespace } // namespace
std::vector<GlobalBookmarkIndex::Entry>::iterator GlobalBookmarkIndex::findBySourcePath(const std::string& sourcePath) { std::vector<GlobalBookmarkIndex::Entry>::iterator GlobalBookmarkIndex::findBySourcePath(const std::string& sourcePath) {
@@ -50,7 +53,9 @@ void GlobalBookmarkIndex::load() {
} }
uint16_t entryCount = 0; uint16_t entryCount = 0;
if (f.read(reinterpret_cast<uint8_t*>(&entryCount), sizeof(entryCount)) != sizeof(entryCount)) { if (f.read(reinterpret_cast<uint8_t*>(&entryCount), sizeof(entryCount)) != sizeof(entryCount) ||
entryCount > MAX_ENTRIES) {
LOG_ERR("GBI", "Invalid entry count: %u", static_cast<unsigned>(entryCount));
f.close(); f.close();
return; return;
} }
@@ -69,7 +74,9 @@ void GlobalBookmarkIndex::load() {
e.isTxt = (isTxtByte != 0); e.isTxt = (isTxtByte != 0);
uint16_t bmCount = 0; uint16_t bmCount = 0;
if (f.read(reinterpret_cast<uint8_t*>(&bmCount), sizeof(bmCount)) != sizeof(bmCount)) { if (f.read(reinterpret_cast<uint8_t*>(&bmCount), sizeof(bmCount)) != sizeof(bmCount) ||
bmCount > MAX_BOOKMARKS_PER_ENTRY) {
LOG_ERR("GBI", "Invalid bookmark count for entry %u: %u", i, static_cast<unsigned>(bmCount));
entries.clear(); entries.clear();
f.close(); f.close();
return; return;