| .. | ||
| patch | ||
| test | ||
| README.md | ||
libreoffice-0001: SavePivotTableXml member-to-cache linear scan O(M*C)
Target: LibreOffice (sc/source/filter/excel/xepivotxml.cxx) MOAD: 0001 (CWE-407) Severity: MEDIUM-HIGH Complexity: O(M*C) -> O(M+C) Measured speedup: 7.1x at M=C=2000
Location
sc/source/filter/excel/xepivotxml.cxx
XclExpXmlPivotTables::SavePivotTableXml(), loop around line 1409
Defect
When exporting a pivot table to XLSX format, the code builds a member sequence by matching each pivot member name against a flat vector of cache field items:
for (const auto & rMember : aMembers)
{
auto it = std::find(aCacheFieldItems.begin(), aCacheFieldItems.end(), rMember.maName);
// ...
}
std::find scans the entire aCacheFieldItems vector for each member, giving
O(M * C) total work where M = aMembers.size() and C = aCacheFieldItems.size().
A pivot table with 5000 distinct values in a text dimension produces M=C=5000,
making the save operation 5000x slower than necessary.
Fix
Build a std::unordered_map<OUString, size_t> index from aCacheFieldItems
once before the loop, then look up each member in O(1).
MOAD-0002 through 0005 (scan notes)
- MOAD-0002 (Intertangle): ScDocument is our known god object. Not a new finding.
- MOAD-0003 (Leaked Context):
thread_local ScDocumentThreadSpecificholds formula evaluation state (pContext, xRecursionHelper), not request-scoped identity. CLEAN. - MOAD-0004 (CWE-312):
tabprotection.cxxpassword logging is behind#if DEBUG_TAB_PROTECTIONwhereDEBUG_TAB_PROTECTION 0. Compiled out. CLEAN. - MOAD-0005 (Thundering Herd): No unguarded cache get+null+compute+put found. CLEAN.