java-topology/defects/gitlab-foss/patch/gitlab-foss-0002-network-graph-overlap-spaces-array-include.patch

27 lines
1.2 KiB
Diff

# UNDF: UNDF-2026-000000854
# UNDF: (leave blank)
# CWE-407: Network::Graph#overlap? spaces Array#include? in range loop
# Severity: LOW-MEDIUM
# Speedup: ~50x at 200 spaces per commit across 300 time range
# File: app/models/network/graph.rb
# The overlap? method iterates over a time range and calls
# @commits[i].spaces.include?(overlap_space) on each commit's spaces
# array. Each include? is O(S) where S = number of spaces assigned
# to that commit. Called from find_free_parent_space for every parent
# edge during graph layout. With many branches, spaces per commit
# can accumulate.
# Fix: maintain a spaces_set alongside spaces for O(1) membership.
# Since Network::Commit#spaces is appended in place_chain with <<,
# the simplest fix is to call .to_set once per overlap? call per commit.
--- a/app/models/network/graph.rb
+++ b/app/models/network/graph.rb
@@ -175,7 +175,7 @@ module Network
def overlap?(range, overlap_space)
range.each do |i|
if i != range.first &&
i != range.last &&
- @commits[i].spaces.include?(overlap_space)
+ @commits[i].spaces.to_set.include?(overlap_space)
return true
end