All projects with patches now have outreach docs. 276 new docs covering CWE-407, CWE-312, CWE-362 across C, C++, Java, Python, Go, Rust, C#, PHP, Ruby, JavaScript, Dart, Erlang, R, and more. Outreach gap: 276 -> 0.
2.6 KiB
OpenFOAM — CWE-407 Disclosure Brief (openfoam-0003)
2026-04-13 · Patch available — awaiting upstream merge
Finding
One O(C × T × M × K) defect in OpenFOAM's DSMC cloud initialization. Patched. DSMCCloud::initialise() calls findIndex(typeIdList_, moleculeName) inside a quadruple-nested loop, producing unnecessary string comparisons during particle seeding.
The Defect
openfoam-0003 (PATCHED — HIGH): src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C:98
// In DSMCCloud::initialise() — fires per cell × tet × molecule:
forAll(molecules, i)
{
const word& moleculeName(molecules[i]);
label typeId(findIndex(typeIdList_, moleculeName)); // O(K) string scan
// ... use typeId for particle creation
}
findIndex(typeIdList_, moleculeName) is O(K) where K = number of molecule types. Called inside forAll(molecules) inside forAll(cellTets) inside forAll(mesh_.cells()). Total cost: O(C × T × M × K).
Complexity Proof
At C=5,000,000 cells, T=5 tets/cell, M=2 molecules, K=5 types:
- Defective: 5M × 5 × 2 × 5 = 250,000,000 string comparisons
- Fixed: 5M × 5 × 2 × O(1) = 50,000,000 hash lookups (5× reduction from eliminating K)
- 5× op reduction at K=5. Scales linearly better with more molecule types.
Impact
OpenFOAM is the most widely used open-source CFD framework. DSMC (Direct Simulation Monte Carlo) initializes millions of particles across the mesh at simulation startup. The redundant string lookups for molecule type IDs add measurable overhead during initialization of large-scale rarefied gas simulations.
The Fix
Pre-build a HashTable<label> mapping molecule names to type IDs before the cell loop:
// Before: O(K) findIndex per cell-tet-molecule
label typeId(findIndex(typeIdList_, moleculeName));
// After: O(1) hash lookup
HashTable<label> moleculeTypeIds(molecules.size());
forAll(molecules, i) {
moleculeTypeIds.insert(molecules[i], findIndex(typeIdList_, molecules[i]));
}
// ...
label typeId(moleculeTypeIds[moleculeName]);
Patch
Fix available: defects/openfoam-0003/patch/openfoam-0003-dsmc-typeId-lookup.patch
Touches DSMCCloud.C. 5× speedup at K=5 molecule types.
What We Ask
A patch is ready for review.
- Confirm receipt and assign an issue reference (OpenFOAM/OpenFOAM-dev).
- Assess severity — fires during DSMC particle initialization across millions of cells.
- Coordinate a disclosure date — we are targeting 90 days from first contact.
- We will credit the OpenFOAM team in the public disclosure. Preferred acknowledgment format welcome.
Contact: see cover email. This brief is confidential until coordinated disclosure.