1.6 KiB
1.6 KiB
UNDF: UNDF-2026-000000352
Classification
| Field | Value |
|---|---|
| CWE | CWE-407 Inefficient Algorithmic Complexity |
| Severity | MEDIUM |
| Component | Compiler/src/reinfer.jl:432 |
| Function | (method order determination — morespecific BFS) |
| Hot path | Method dispatch ordering — called during type inference for every ambiguous method pair |
| Status | PATCHED (unit test PASS) |
Defect
Method interference graph BFS uses visited = Method[] (Array) with method3 in visited
for cycle prevention. in on a Julia Vector/Array is O(V) linear scan:
visited = Method[] # Array — O(V) membership
push!(visited, method2)
workqueue = Method[method2]
while !isempty(workqueue)
current = pop!(workqueue)
for k = 1:length(interferences)
method3 = interferences[k]::Method
method3 in visited && continue # O(V) per check — CWE-407
push!(visited, method3)
push!(workqueue, method3)
end
end
With V methods reachable in the interference graph, total membership checks: O(V²). Called during type inference for every ambiguous method pair resolution.
Fix
visited = Set{Method}() # O(1) membership
push!(visited, method2)
workqueue = Method[method2]
while !isempty(workqueue)
current = pop!(workqueue)
for k = 1:length(interferences)
method3 = interferences[k]::Method
method3 in visited && continue # O(1) hash lookup
push!(visited, method3)
push!(workqueue, method3)
end
end
Speedup: O(V²) → O(V) — ~250× at V=500 (62,500 → 500 checks).