25 lines
1.2 KiB
Diff
25 lines
1.2 KiB
Diff
# UNDF: UNDF-2026-000000215
|
|
--- a/src/pip/_internal/cache.py
|
|
+++ b/src/pip/_internal/cache.py
|
|
@@ -130,6 +130,10 @@ class SimpleWheelCache(Cache):
|
|
wheels_dir = self.get_path_for_link(link)
|
|
if os.path.isdir(wheels_dir):
|
|
candidates = []
|
|
+ # CWE-407 fix: precompute tag->priority dict once, reuse for all wheel
|
|
+ # candidates. Before this patch support_index_min() linearly enumerated
|
|
+ # supported_tags (200-600 entries) per candidate — O(C*T) per lookup.
|
|
+ tag_to_priority = {tag: idx for idx, tag in enumerate(supported_tags)}
|
|
for wheel_name in os.listdir(wheels_dir):
|
|
try:
|
|
wheel = Wheel(wheel_name)
|
|
@@ -155,7 +159,7 @@ class SimpleWheelCache(Cache):
|
|
if not wheel.supported(supported_tags):
|
|
# Built for a different python/arch/etc
|
|
continue
|
|
candidates.append(
|
|
(
|
|
- wheel.support_index_min(supported_tags),
|
|
+ wheel.find_most_preferred_tag(supported_tags, tag_to_priority),
|
|
wheel_name,
|
|
wheel_dir,
|
|
)
|