diff --git a/SCAN-TODO.md b/SCAN-TODO.md index 8b1b5de99..0299fb2eb 100644 --- a/SCAN-TODO.md +++ b/SCAN-TODO.md @@ -47,14 +47,14 @@ Rule: clone, scan, delete clone after. Keep disk under 90%. - [x] Ollama (Go, local LLM runtime) — ollama-0001 MOAD-0001 CWE-407 kvcache buildMask slices.Contains O(B*E) Gemma3 multi-image HIGH 250x; MOADs 0002/0003/0004/0005 CLEAN - [x] LangChain (Python, LLM orchestration) — langchain-0001 MOAD-0001 MultiVectorRetriever id dedup O(D^2) (pre-existing); langchain-0002 MOAD-0001 MultiQueryRetriever _unique_documents slice-in-loop O(D^2) 21x at D=500 MEDIUM; MOADs 0002/0003/0004/0005 CLEAN -- [ ] Hugging Face Transformers (Python) -- [ ] vLLM (Python/C++, LLM serving) +- [x] Hugging Face Transformers (Python) — transformers-0001 (pre-existing) all_special_ids in convert_ids_to_tokens; transformers-0002 CWE-312 HF_TOKEN logged; transformers-0003 MOAD-0001 all_special_tokens in convert_tokens_to_string (marian/m2m100/speech_to_text/siglip/gpt_sw3); transformers-0004 MOAD-0001 all_special_ids rebuilt per loop in wav2vec2/wav2vec2_phoneme/esm; MOADs 0002/0003/0005 CLEAN +- [x] vLLM (Python/C++, LLM serving) — vllm-0001 (pre-existing) LoRA lora_index_to_id.index() per token; vllm-0002 Grok2Tokenizer dict.values() scan per output token; MOADs 0002/0003/0004/0005 CLEAN - [x] llama.cpp (C++) — llamacpp-0001 MOAD-0001 CWE-407 grammar_advance_stack std::find O(S^2) MEDIUM-HIGH; MOADs 0002/0003/0004/0005 CLEAN ## Priority 6 — Scientific/Data -- [ ] OpenFOAM (C++, CFD simulation) -- [ ] ROOT (C++, CERN data analysis) +- [x] OpenFOAM (C++, CFD simulation) -- openfoam-0001 moleculeCloud molsToDelete findIndex O(D^2) HIGH 400x (pre-existing); openfoam-0002 CFCFaceToCellStencil allGlobalFaces findIndex O(C*F*G) HIGH (pre-existing); openfoam-0003 DSMCCloud::initialise findIndex(typeIdList_) O(C*T*M*K) MEDIUM 3-10x; MOAD-0002 objectRegistry god-object structural (not patchable); MOAD-0003/0004/0005 CLEAN +- [x] ROOT (C++, CERN data analysis) -- root-cern-0001 TTreeCache potentialVetoes std::find O(B*N^2) MEDIUM (pre-existing); root-cern-0002 TWebFile Authorization header logged at gDebug>0 CWE-312 HIGH (pre-existing); root-cern-0003 TTree::InitializeBranchLists fSeqBranches std::find O(B^2) MEDIUM 500x at B=500; MOAD-0002 gROOT intertangle (gROOTMutex inconsistently applied, structural); MOAD-0003 TTHREAD_TLS method-scoped state CLEAN; MOAD-0005 RWebDisplayHandle::FindCreator static map GUI-only CLEAN - [ ] Scilab (C/Fortran, numerical computation) - [ ] Octave (deeper, C++) - [ ] R (deeper, C) diff --git a/defects/openfoam-0003/SCAN-NOTES.md b/defects/openfoam-0003/SCAN-NOTES.md new file mode 100644 index 000000000..a8809fe17 --- /dev/null +++ b/defects/openfoam-0003/SCAN-NOTES.md @@ -0,0 +1,45 @@ +# openfoam: 5-MOAD scan results (2026-04-03) + +## MOAD-0001 (CWE-407) -- NEW: openfoam-0003 + +DSMCCloud::initialise() calls `findIndex(typeIdList_, moleculeName)` inside a +triple-nested loop: forAll(mesh_.cells()) * forAll(cellTets) * forAll(molecules). +Total comparisons: O(C * T * M * K). At C=5M, T=5, M=2, K=2: ~100M string +comparisons. Fix: pre-build a HashTable before the cell loop. + +File: `src/lagrangian/DSMC/clouds/Templates/DSMCCloud/DSMCCloud.C` + +Pre-existing defects: +- openfoam-0001: moleculeCloud molsToDelete findIndex O(D^2) HIGH (patched) +- openfoam-0002: CFCFaceToCellStencil allGlobalFaces findIndex O(C*F*G) HIGH (patched) + +Other candidates examined but bounded/small: +- polyMeshAdder.C zone dedup: O(Z) per point where Z = zone count, typically <10 +- hexRef8.C pFaces dedup: O(F) per vertex, F bounded by cell face count +- cellCuts.C loopFace: O(L * E) where L,E are face-local sizes (3-6 each) +- snappyLayerDriver.C getVertexString: single findIndex call outside loops + +## MOAD-0002 (Intertangle) -- STRUCTURAL, not patchable + +OpenFOAM objectRegistry (Time + fvMesh) is a god-object passed by reference +throughout the entire codebase. Every field, boundary condition, function +object, and solver phase reads/writes the same registry. This is architectural +and cannot be reduced to a single-site patch. + +## MOAD-0003 (Leaked Context) -- CLEAN + +No `thread_local` or `pthread_key` usage found in OpenFOAM src/. OpenFOAM +is primarily single-threaded (MPI for parallelism, not pthreads) so this +pattern does not apply. + +## MOAD-0004 (CWE-312) -- CLEAN + +No passwords, tokens, or credentials found in Info<::initialise()` + +## MOAD +0001 -- CWE-407 Algorithmic Complexity + +## Severity +MEDIUM + +## Pattern + +```cpp +forAll(mesh_.cells(), celli) // O(C) -- all mesh cells +{ + List cellTets = ...; // O(T) tets per cell + + forAll(cellTets, tetI) // O(T) + { + forAll(molecules, i) // O(M) molecule species + { + const word& moleculeName(molecules[i]); + + label typeId(findIndex(typeIdList_, moleculeName)); // O(K) string compare +``` + +`typeIdList_` is a `List` scanned with `findIndex` (linear search) for each +`(cell, tet, molecule)` combination. + +## Complexity + +| Variable | Meaning | Typical | +|----------|---------|---------| +| C | mesh cells | 1M-10M | +| T | tets per cell | 5-6 | +| M | molecule species | 2-5 | +| K | type list size | == M | + +Total comparisons: O(C * T * M * K). At C=5M, T=5, M=2, K=2: 100M string +comparisons during simulation initialisation. A pre-built `HashTable