java-topology/defects/libreoffice-0001
2026-04-03 11:04:23 -04:00
..
patch undf: assign UNDF-2026-000001125 to mercurial-0001, stamp patches 2026-04-03 11:04:23 -04:00
test libreoffice+calligra: 2 CWE-407 defects, MOADs 0002-0005 CLEAN 2026-03-31 20:29:29 -04:00
README.md libreoffice+calligra: 2 CWE-407 defects, MOADs 0002-0005 CLEAN 2026-03-31 20:29:29 -04:00

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 ScDocumentThreadSpecific holds formula evaluation state (pContext, xRecursionHelper), not request-scoped identity. CLEAN.
  • MOAD-0004 (CWE-312): tabprotection.cxx password logging is behind #if DEBUG_TAB_PROTECTION where DEBUG_TAB_PROTECTION 0. Compiled out. CLEAN.
  • MOAD-0005 (Thundering Herd): No unguarded cache get+null+compute+put found. CLEAN.