31 lines
1.3 KiB
Diff
31 lines
1.3 KiB
Diff
# UNDF: UNDF-2026-000000789
|
|
# UNDF: (leave blank)
|
|
# LibreOffice CWE-407: InsertLine() table line dedup O(L^2)
|
|
#
|
|
# In sw/source/core/docnode/ndtbl1.cxx, the static InsertLine() function
|
|
# checks for duplicates via std::find() on a vector before push_back.
|
|
# It is called in a loop (line 222) for every table line during table
|
|
# operations (merge, split, selection), making total cost O(L^2).
|
|
#
|
|
# Similarly, InsertCell() at line 661 does the same pattern for cell frames.
|
|
#
|
|
# Fix: use an unordered_set alongside the vector for O(1) dedup.
|
|
#
|
|
# Severity: MEDIUM — Writer tables with hundreds of rows trigger this
|
|
# during table selection/merge operations. At L=500 lines:
|
|
# 125,000 comparisons reduced to 500.
|
|
--- a/sw/source/core/docnode/ndtbl1.cxx
|
|
+++ b/sw/source/core/docnode/ndtbl1.cxx
|
|
@@ -169,8 +169,11 @@
|
|
-static void InsertLine( std::vector<SwTableLine*>& rLineArr, SwTableLine* pLine )
|
|
+static void InsertLine( std::vector<SwTableLine*>& rLineArr,
|
|
+ std::unordered_set<SwTableLine*>& rLineSet,
|
|
+ SwTableLine* pLine )
|
|
{
|
|
- if( rLineArr.end() == std::find( rLineArr.begin(), rLineArr.end(), pLine ) )
|
|
+ if( rLineSet.find(pLine) == rLineSet.end() )
|
|
+ {
|
|
+ rLineSet.insert(pLine);
|
|
rLineArr.push_back( pLine );
|
|
+ }
|
|
}
|