65 lines
2.5 KiB
Diff
65 lines
2.5 KiB
Diff
# UNDF: UNDF-2026-000000805
|
|
# UNDF: (leave blank)
|
|
# Defect: shotcut-0001
|
|
# Component: src/docks/playlistdock.cpp — PlaylistProxyModel m_hashes
|
|
# Pattern: CWE-407 — std::find on vector<string> m_hashes inside filterAcceptsRow (called per row)
|
|
# Severity: MEDIUM — O(N^2) where N = playlist clips; each row calls std::find on m_hashes
|
|
# Fix: Change m_hashes from vector<string> to unordered_set<string> for O(1) lookup
|
|
--- a/src/docks/playlistdock.cpp
|
|
+++ b/src/docks/playlistdock.cpp
|
|
@@ -149,7 +149,7 @@
|
|
class ProducerHashesParser : public Mlt::Parser
|
|
{
|
|
private:
|
|
- std::vector<std::string> m_hashes;
|
|
+ std::unordered_set<std::string> m_hashes;
|
|
|
|
public:
|
|
ProducerHashesParser()
|
|
@@ -159,9 +159,7 @@
|
|
- std::vector<std::string> &hashes()
|
|
+ std::unordered_set<std::string> &hashes()
|
|
{
|
|
- std::sort(m_hashes.begin(), m_hashes.end());
|
|
- std::set<std::string> unique(m_hashes.begin(), m_hashes.end());
|
|
- std::copy(unique.begin(), unique.end(), std::back_inserter(m_hashes));
|
|
+ // unordered_set is already deduplicated
|
|
return m_hashes;
|
|
}
|
|
|
|
@@ -168,7 +166,7 @@
|
|
int on_start_producer(Mlt::Producer *producer)
|
|
{
|
|
if (producer->is_cut())
|
|
- m_hashes.push_back(Util::getHash(producer->parent()).toStdString());
|
|
+ m_hashes.insert(Util::getHash(producer->parent()).toStdString());
|
|
return 0;
|
|
}
|
|
|
|
@@ -204,7 +202,7 @@
|
|
auto hash = Util::getHash(clip->parent()).toStdString();
|
|
- return std::find(m_hashes.begin(), m_hashes.end(), hash) != m_hashes.end();
|
|
+ return m_hashes.count(hash) > 0;
|
|
|
|
@@ -229,7 +227,7 @@
|
|
auto hash = Util::getHash(clip->parent()).toStdString();
|
|
- return std::find(m_hashes.begin(), m_hashes.end(), hash) == m_hashes.end();
|
|
+ return m_hashes.count(hash) == 0;
|
|
|
|
@@ -265,8 +263,8 @@
|
|
- m_hashes.clear();
|
|
- std::set_difference(hashes.begin(), ... std::back_inserter(m_hashes));
|
|
+ m_hashes.clear();
|
|
+ // For duplicates: insert hashes that appear more than once
|
|
+ std::sort(hashes.begin(), hashes.end());
|
|
+ for (size_t i = 1; i < hashes.size(); i++) {
|
|
+ if (hashes[i] == hashes[i-1]) m_hashes.insert(hashes[i]);
|
|
+ }
|
|
|
|
@@ -278,7 +276,7 @@
|
|
- m_hashes = parser.hashes();
|
|
+ m_hashes = parser.hashes(); // now returns unordered_set
|
|
|
|
@@ -328,1 +326,1 @@
|
|
- std::vector<std::string> m_hashes;
|
|
+ std::unordered_set<std::string> m_hashes;
|