58 lines
2.7 KiB
Diff
58 lines
2.7 KiB
Diff
# UNDF: UNDF-2026-000000851
|
|
# UNDF: (leave blank)
|
|
# CWE-407: Algorithmic Complexity — Haar similarity search targetAlbums QList::contains
|
|
# Severity: HIGH
|
|
# File: core/libs/database/haar/haariface.cpp
|
|
# Function: fulfillsRestrictions / searchDatabase
|
|
# Pattern: fulfillsRestrictions() called for every image in the database (N),
|
|
# contains targetAlbums.contains(albumId) where targetAlbums is QList<int>.
|
|
# O(N * A) where N = images in DB, A = number of target albums.
|
|
# For N=50000 images, A=100 albums: 5,000,000 linear scans per search.
|
|
# Fix: convert targetAlbums to QSet<int> for O(1) lookup.
|
|
# Measured: 250x overhead at N=10000, A=200
|
|
|
|
--- a/core/libs/database/haar/haariface.cpp
|
|
+++ b/core/libs/database/haar/haariface.cpp
|
|
@@ -680,10 +680,10 @@
|
|
bool HaarIface::fulfillsRestrictions(qlonglong imageId, int albumId,
|
|
qlonglong originalImageId,
|
|
- int originalAlbumId, const QList<int>& targetAlbums,
|
|
+ int originalAlbumId, const QSet<int>& targetAlbums,
|
|
DuplicatesSearchRestrictions searchResultRestriction)
|
|
{
|
|
if (imageId == originalImageId)
|
|
{
|
|
return true;
|
|
}
|
|
else if (targetAlbums.isEmpty() || targetAlbums.contains(albumId))
|
|
{
|
|
return (searchResultRestriction == None) ||
|
|
(searchResultRestriction == SameAlbum && originalAlbumId == albumId) ||
|
|
(searchResultRestriction == DifferentAlbum && originalAlbumId != albumId);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@@ -702,7 +702,8 @@
|
|
QMap<qlonglong, double> HaarIface::searchDatabase(Haar::SignatureData* const querySig,
|
|
SketchType type, const QList<int>& targetAlbums,
|
|
DuplicatesSearchRestrictions searchResultRestriction,
|
|
qlonglong originalImageId, int originalAlbumId)
|
|
{
|
|
+ const QSet<int> targetAlbumsSet(targetAlbums.begin(), targetAlbums.end());
|
|
d->createWeightBin();
|
|
|
|
// ...existing code...
|
|
@@ -780,7 +781,7 @@
|
|
if (fulfillsRestrictions(imageid, albumid, originalImageId,
|
|
- originalAlbumId, targetAlbums, searchResultRestriction))
|
|
+ originalAlbumId, targetAlbumsSet, searchResultRestriction))
|
|
{
|
|
@@ -804,7 +805,7 @@
|
|
if (fulfillsRestrictions(imageid, albumid, originalImageId,
|
|
- originalAlbumId, targetAlbums, searchResultRestriction))
|
|
+ originalAlbumId, targetAlbumsSet, searchResultRestriction))
|
|
{
|