From 7e32838a1666964f7afdd7b65940a25dbf1ec27e Mon Sep 17 00:00:00 2001 From: jpirnay Date: Wed, 15 Apr 2026 10:57:03 +0200 Subject: [PATCH] And another recommendation applied --- src/GlobalBookmarkIndex.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/GlobalBookmarkIndex.cpp b/src/GlobalBookmarkIndex.cpp index 68e8665e..7b76c319 100644 --- a/src/GlobalBookmarkIndex.cpp +++ b/src/GlobalBookmarkIndex.cpp @@ -25,6 +25,9 @@ bool readString(FsFile& f, std::string& out) { out.resize(len); return f.read(reinterpret_cast(&out[0]), len) == len; } + +constexpr uint16_t MAX_ENTRIES = 1000; +constexpr uint16_t MAX_BOOKMARKS_PER_ENTRY = 1000; } // namespace std::vector::iterator GlobalBookmarkIndex::findBySourcePath(const std::string& sourcePath) { @@ -50,7 +53,9 @@ void GlobalBookmarkIndex::load() { } uint16_t entryCount = 0; - if (f.read(reinterpret_cast(&entryCount), sizeof(entryCount)) != sizeof(entryCount)) { + if (f.read(reinterpret_cast(&entryCount), sizeof(entryCount)) != sizeof(entryCount) || + entryCount > MAX_ENTRIES) { + LOG_ERR("GBI", "Invalid entry count: %u", static_cast(entryCount)); f.close(); return; } @@ -69,7 +74,9 @@ void GlobalBookmarkIndex::load() { e.isTxt = (isTxtByte != 0); uint16_t bmCount = 0; - if (f.read(reinterpret_cast(&bmCount), sizeof(bmCount)) != sizeof(bmCount)) { + if (f.read(reinterpret_cast(&bmCount), sizeof(bmCount)) != sizeof(bmCount) || + bmCount > MAX_BOOKMARKS_PER_ENTRY) { + LOG_ERR("GBI", "Invalid bookmark count for entry %u: %u", i, static_cast(bmCount)); entries.clear(); f.close(); return;