solang-0001: add_external_functions emits_events Vec::contains O(F×E²) MEDIUM src/sema/external_functions.rs:93-103 — dedup accumulator Vec uses linear scan for each event per function; fix: IndexSet (already a dependency) for O(1) dedup tor/bitcoin/transmission/libtorrent/solc: CLEAN markers added after full scan Tor: nodes_have_common_family_id F=1-3 IDs, O(N×F²) ≈ O(9N), not scalable issue Bitcoin: TxGraph/sets throughout, no linear scan in hot paths Transmission: bitfields for piece tracking, sorted binary search for string table libtorrent: sorted vectors with lower_bound, DHT uses binary search on results solc: unordered_set/set throughout OverrideChecker, SMTEncoder, FunctionCallGraph
1.4 KiB
1.4 KiB
CLEAN — libtorrent (C++ BitTorrent library)
Scanned 2026-03-29 for CWE-407 (algorithmic complexity / linear scan membership).
Areas Checked
src/piece_picker.cpp— piece selection:have_peersisstd::unordered_setper piece_pos (O(1) count/insert).m_recent_extentsis astd::vectorcapped at 5 entries by design — thecontains()scan is trivially O(1) in practice.m_piecessorted vector useslower_boundfor O(log N) insert.src/kademlia/traversal_algorithm.cpp— DHT Kademlia traversal:m_resultsis a sorted vector; new entries usestd::lower_boundfor O(log N) insertion. Dedup is by node-ID comparison on the sorted prefix, not a full linear scan.src/kademlia/routing_table.cpp— routing table bucket management:find_ifover per-bucket vectors (K=8 nodes per bucket by Kademlia protocol) — effectively O(1).src/peer_list.cpp— peer list: sorted multimap range lookups viafind_if(range.first, range.second, ...)— O(k) over equal-range, not full list.src/peer_connection.cpp—m_accept_fast/m_allowed_fast/m_suggested_piecesscans: these lists are bounded by BitTorrent protocol constants (Fast Extension caps at 10 pieces, Suggest Piece typically ≤10).
Result: No actionable CWE-407 defects found. libtorrent uses sorted vectors with binary search, unordered sets, and protocol-bounded lists throughout.