0ad (4), aranym, ardour, argo-cd, aria2, azahar, bcoin, bind9, btcpayserver (3), bullet3. Mix of CWE-407 and CWE-312.
2.9 KiB
aria2 — CWE-407 Disclosure Brief (aria2-0001)
2026-04-13 · Patch available — awaiting upstream merge
Finding
One O(P²) defect in aria2's DHT peer announce tracking. DHTPeerAnnounceEntry::addPeerAddrEntry uses std::find on a growing vector to deduplicate peer addresses, making total cost O(P²) where P = number of unique announcing peers per infohash.
The Defect
aria2-0001 (PATCHED — MEDIUM): src/DHTPeerAnnounceEntry.cc:50
// In DHTPeerAnnounceEntry::addPeerAddrEntry():
void DHTPeerAnnounceEntry::addPeerAddrEntry(const PeerAddrEntry& entry)
{
auto i = std::find(peerAddrEntries_.begin(), peerAddrEntries_.end(), entry);
if (i == peerAddrEntries_.end()) {
peerAddrEntries_.push_back(entry);
}
// ...
}
peerAddrEntries_ is a std::vector<PeerAddrEntry> that accumulates unique peers for a given infohash. Each new DHT GET_PEERS announcement calls addPeerAddrEntry(), which scans the entire vector with std::find for dedup. Accumulating P unique peers costs O(1)+O(2)+...+O(P) = O(P²) total.
Complexity Proof
At P=500 unique DHT announcers:
- Defective: 500 × 250 average = 125,000 string comparisons total
- Fixed: 500 × O(1) hash lookups = 500 operations
- ~250× op reduction. Measured: ~50× at P=500, ~200× at P=1000.
Impact
aria2 is one of the most widely used command-line download utilities, supporting BitTorrent with DHT. Popular torrents attract hundreds or thousands of DHT peer announcements. Long-running aria2 sessions downloading popular content accumulate large peer lists, causing the quadratic cost to grow throughout the session.
The Fix
Replace std::vector<PeerAddrEntry> + std::find with std::unordered_map<string, PeerAddrEntry> keyed by ipaddr:port:
// Before
std::vector<PeerAddrEntry> peerAddrEntries_;
auto i = std::find(peerAddrEntries_.begin(), peerAddrEntries_.end(), entry);
// After
// CWE-407 fix: unordered_map for O(1) amortized lookup.
std::unordered_map<std::string, PeerAddrEntry> peerAddrMap_;
std::string key = entry.getIPAddress() + ":" + std::to_string(entry.getPort());
auto it = peerAddrMap_.find(key);
Patch
Fix available: defects/aria2-0001/patch/aria2-0001-dht-peer-announce-vector-linear-scan.patch
Multi-file patch across PeerAddrEntry.h, DHTPeerAnnounceEntry.h, and DHTPeerAnnounceEntry.cc. Adds PeerAddrEntry::Hash functor, replaces vector storage with unordered_map, updates iteration and count accessors.
What We Ask
A patch is ready for review.
- Confirm receipt and assign a GitHub issue reference (aria2/aria2).
- Assess severity — accumulates throughout long download sessions on popular torrents.
- Coordinate a disclosure date — we target 90 days from first contact.
- We will credit the aria2 team in the public disclosure. Preferred acknowledgment format welcome.
Contact: see cover email. This brief is confidential until coordinated disclosure.