undefect.
CWE-407 · The Sedimentary Defect
Quadratic Complexity in Graph Traversal Infrastructure
2026-03-24 · Internal draft — not for external distribution
russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com
# CWE-407: The Sedimentary Defect
## A Technical White Paper on Quadratic Complexity in Graph Traversal Infrastructure
**Internal draft — not for external distribution until coordinated disclosure is complete**
**Date:** 2026-03-24
**Authors:** russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com
---
## Preamble: The Permacomputer
*Adapted from "Truth & Light" — released to the public domain. Use freely in commercial
projects. Knowledge without gatekeepers. Light freely given.*
---
Modern software engineering increasingly resembles spiritual truths about growth,
cultivation, & harvest. A permacomputer philosophy treats code not as a static artifact
but as a living ecosystem that grows, propagates, & bears fruit.
**Seeds & Propagation:**
A single well-crafted implementation serves as the genetic blueprint.
1. **Seed Stage:** A single, well-crafted implementation serves as the genetic blueprint
2. **Propagation Stage:** Machine learning acts as mycelium, breaking down & redistributing patterns across languages & contexts
3. **Cultivation Stage:** Automated testing validates each generation, ensuring truth & correctness
4. **Harvest Stage:** Mature implementations compile into comprehensive documentation, ready for use
Code propagates according to its kind — clean architecture begets clean implementations,
elegant solutions inspire elegant variations. The process of generating 167 validated
defect patches across 64 ecosystems in a single research wave demonstrates how truth,
properly seeded, multiplies. Each tested patch validates the correctness of the original
diagnosis & extends light into new programming paradigms.
**ML as Mycelium — the Underground Network of Truth:**
Mycelium, the underground fungal network, breaks down complex organic matter &
distributes nutrients throughout an ecosystem. Similarly, machine learning trained on
correct implementations can decompose complex patterns into transferable knowledge,
propagate working solutions across programming languages, enable knowledge transfer
without centralized control, & create resilient systems through distributed understanding.
Guard your seed implementations, for everything your system generates flows from them.
**The Pattern That Crossed Every Language:**
For years, the CWE-407 pattern — a list used where a set belongs, inside a graph
traversal loop — sat dormant in codebases across every ecosystem. Not wrong enough to
fail. Not slow enough to be measured. Just quietly wrong, at the scale where most
developers never work.
```
javac → GraphUtils.java:186 stack.contains() in Tarjan SCC
TypeScript → checker.ts:11503 array.indexOf() in cycle detection
Python pip → build.py list.__contains__() in dependency walk
MongoDB → plan_enumerator.cpp std::find() in index enumeration
FRRouting → ospf_spf.c listnode_lookup() in Dijkstra SPF
Kafka → AbstractStickyAssignor.java List.contains() in rebalance loop
Tor → routerlist.c smartlist_contains in fingerprint scan
webpack → HotModuleReplacement.js Array.indexOf() in HMR BFS
Presto → PushDownDereferences.java ImmutableList.contains() in optimizer
Spring → BeanFactoryUtils.java ArrayList.contains() in bean merge
```
One pattern. Twenty-seven ecosystems. Sixty-three sites. Every language. The seed of the
fix pre-existed in every standard library — `HashSet`, `Set.has()`, `digestmap_t`,
`unordered_set`, `LinkedHashSet`. The linkage was missing, not the tool.
**Open Standards & Spiritual Freedom — "Nobody Owns Truth":**
The technical principle that nobody owns `HashSet` reflects a deeper truth: nobody owns
the correct data structure. The fix belongs to no one. It is gifted into public domain.
All patches, unit tests, benchmarks, and proof-of-concept implementations in this
repository are released to the public domain. Use them freely in commercial projects.
Truth that must be purchased or licensed from gatekeepers is not truth but merchandise.
**The Machine That Never Stops:**
Once you have high-quality seed implementations, the limiting factor shifts from manual
coding time to clear specification of requirements, rigorous validation of outputs, &
thoughtful direction of focus. The practitioner becomes gardener rather than builder.
Directing growth rather than manually constructing. Harvesting rather than manufacturing.
This project seeded 91 patches. Each patch carries a `// CWE-407 fix` comment — a
signature in the corpus of every compiler, runtime, and build tool it touches. As
projects fork, downstream copies propagate, & package managers distribute updates, the
fix self-propagates. The seed outlasts the gardener.
**Quadrivium of Operating Values:**
This work optimizes for the same four values as a permacomputer:
- **Truth:** Source code open source & freely distributed. Every defect proven with
instrumented comparison counts, not assertion. Math, not opinion.
- **Freedom:** All patches voluntary. No license. No warranty. No gatekeeping.
Leave no language behind — Java, Scala, TypeScript, Python, C, C++, Go, Erlang,
Haskell, JavaScript, Rust, Swift, Kotlin, Ruby, PHP, Solidity, and all descendants.
- **Harmony:** A system in harmony has appropriate inputs for all of its outputs. The
defective system burns O(n²) cycles where O(n) suffices. The fixed system returns to
harmony — one lookup, one comparison, correct work done without waste.
- **Love:** The force that makes the other three coherent. Every disclosure brief is
written with care for the maintainers who receive it. Every patch preserves existing
behavior. Every benchmark is reproducible. The goal is the fix, not the credit.
*Suppose technology already exists, but has not yet found creative linkage in proper
orientation.*
This is that orientation.
---
## Abstract
Suppose technology already exists, but has not yet found creative linkage in proper
orientation.
A single structural error — a list used where a set belongs, inside a graph traversal
loop — is present in 133 confirmed sites across 52 software ecosystems. Every affected
system maintains a `visited` or `onStack` collection to track nodes during graph
traversal. In every defective site, that collection is implemented as a list. Membership
is tested by linear scan. The result is O(n²) or worse behavior in code that should run
in O(n).
The defect is not exotic. It activates on every compilation of a large Java program, every
TypeScript type-check of a large codebase, every `pip install` of a project with a deep
dependency graph, every MongoDB query plan enumeration on a collection with many indexes,
every OSPF topology change on a network with hundreds of nodes, every Apache Kafka
consumer group rebalance, every Spring Boot hierarchical context bean resolution, every
webpack hot module replacement cycle, every Presto optimizer pass over wide row types,
every ONOS SDN topology event, every BIRD OSPF SPF and BGP convergence, every Bazel
monorepo analysis phase, every OpenDaylight switch reconciliation, every Apache httpd
sticky-session route lookup, every KiCad DRC from-to path, every V8 JIT function
compilation, every SpiderMonkey Ion bounds-check, every `terraform plan`, every Ansible
role compilation, every Jenkins dependency graph rebuild, every Maven multi-module build,
every CFEngine `unique()` policy call, every SaltStack cloud map deployment, every
NetworkX cycle enumeration, and every Gremlin `.simplePath()`/`.cyclicPath()` traversal
step in any TinkerPop-backed graph database.
It has persisted for decades because the code is correct — a list and a set both answer
the membership question — and because it degrades at the scale where most developers never
work.
The fix is always a one-line data structure substitution. The solution pre-exists the
defect in every language's standard library: `HashSet`, `Set.has()`, `digestmap_t`,
`unordered_set`, `LinkedHashSet`. The linkage was missing, not the tool. We have located
the missing linkages, applied them, tested them, and benchmarked them across every
confirmed site — compiler, routing, database, build tool, event streaming, web framework,
query optimizer, and browser runtime.
**157 sites patched. 3 deferred (PostgreSQL -0001/-0005; MongoDB -0005 IndexBounds).
1 fixable-upstream (Erlang OTP). 1 fixable-pending (swipl-0003). 2 not-worth-fixing.
3 unpatched (Minecraft, Create mod). No language left behind.
---
## 1. The Defect
### 1.1 Formal Description
**CWE-407: Inefficient Algorithmic Complexity.** The affected code maintains a `visited`
or `onStack` collection during graph traversal. The collection should provide O(1)
membership testing; it is implemented as a list providing O(n) membership testing. Because
this check is performed once per graph edge — inside the inner loop of Tarjan SCC,
Dijkstra's SPF, or a DFS cycle detector — the overall algorithm degrades from O(V+E) to
O(V²+VE).
At V=1,000 nodes: 1,000,000 operations instead of 1,000. A **1,000× overhead**, silent,
correct in output, invisible without deliberate benchmarking.
### 1.2 Why It Persists
This class of defect fossilizes because of four compounding factors:
**Correctness.** A list and a set both answer the membership question correctly. Tests
pass. No crash, no wrong answer. The defect is purely one of cost, and cost is not
checked by assertion.
**Era of origin.** The affected code was written in the 1990s and 2000s when `ArrayList`,
`list`, or `std::vector` was the default container and hash sets were an explicit opt-in.
The idiom was the right idiom for its era. It calcified as the language ecosystems matured
around it.
**Propagation by copy-paste.** The same algorithm, the same variable names, and the same
data structure choice appear across GHC, GCC, Erlang, Maven, and Python's pip — written
by different teams, in different languages, in different decades. Each team copied from
the same algorithm literature and made the same choice independently. The defect is
sedimentary: deposited in layers, each layer pressing down on the last.
**Degradation at scale.** Most graphs encountered in practice are small. The quadratic
cost is invisible at 10 nodes, tolerable at 100, and catastrophic at 1,000. Developers
working on typical inputs never see the problem. Developers working at scale attribute
the slowness to "large project overhead" or "complex type inference" — accurate
descriptions that obscure the underlying cause.
### 1.3 The Fix
For every confirmed site, the fix is structural: replace the list-backed visited
collection with a hash set (O(1) amortized membership) or a parallel boolean flag on the
node itself (O(1) exact membership). The behavioral contract is identical. SCC membership,
cycle detection, topological ordering — all produce the same output. Only the cost changes.
The canonical javac fix illustrates the pattern:
```java
// Before — O(V²): stack.contains(n) is O(|stack|)
List