45 lines
2 KiB
Diff
45 lines
2 KiB
Diff
# UNDF: UNDF-2026-000000798
|
|
# UNDF: (leave blank)
|
|
# Defect: kdenlive-0001
|
|
# Component: src/utils/thumbnailcache.hpp + thumbnailcache.cpp
|
|
# Pattern: CWE-407 — m_storedOnDisk/m_storedVolatile vector<int> with std::find for dedup
|
|
# Severity: MEDIUM — O(C*P*V) in saveCachedThumbs, O(F*V) in invalidateThumbsForClip
|
|
# Fix: Change vector<int> to unordered_set<int> for O(1) membership test
|
|
--- a/src/utils/thumbnailcache.hpp
|
|
+++ b/src/utils/thumbnailcache.hpp
|
|
@@ -16,6 +16,7 @@
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
+#include <unordered_set>
|
|
#include <vector>
|
|
|
|
/** @class ThumbnailCache
|
|
@@ -89,8 +90,8 @@
|
|
|
|
// the following maps keeps track of the positions that we store for each clip in volatile caches.
|
|
// Note that we don't track deletions due to items dropped from the cache. So the maps can contain more items that are currently stored.
|
|
- std::unordered_map<QString, std::vector<int>> m_storedVolatile;
|
|
- mutable std::unordered_map<QString, std::vector<int>> m_storedOnDisk;
|
|
+ std::unordered_map<QString, std::unordered_set<int>> m_storedVolatile;
|
|
+ mutable std::unordered_map<QString, std::unordered_set<int>> m_storedOnDisk;
|
|
};
|
|
--- a/src/utils/thumbnailcache.cpp
|
|
+++ b/src/utils/thumbnailcache.cpp
|
|
// In all getThumbnail/storeThumbnail/saveCachedThumbs methods, replace:
|
|
// std::find(m_storedOnDisk[binId].begin(), m_storedOnDisk[binId].end(), pos) == m_storedOnDisk[binId].end()
|
|
// with:
|
|
// m_storedOnDisk[binId].find(pos) == m_storedOnDisk[binId].end()
|
|
// (or equivalently: m_storedOnDisk[binId].count(pos) == 0)
|
|
//
|
|
// Replace push_back(pos) with insert(pos).
|
|
//
|
|
// In invalidateThumbsForClip, replace std::find + erase with:
|
|
// cachedFrames.erase(f); // O(1) for unordered_set
|
|
//
|
|
// Same changes for m_storedVolatile.
|
|
//
|
|
// saveCachedThumbs signature change:
|
|
// void saveCachedThumbs(const std::unordered_map<QString, std::vector<int>> &keys)
|
|
// The parameter can remain vector<int> (caller provides frame list),
|
|
// but internal dedup uses the unordered_set.
|