java-topology/defects/prefect/patch/pre-0002-steps-core-printed-messages-list.patch

38 lines
1.9 KiB
Diff

# UNDF: UNDF-2026-000000223
From: agent-blackops <blackops@unturf.com>
Date: Fri, 27 Mar 2026 00:00:00 +0000
Subject: [PATCH] steps/core: replace printed_messages list with set for O(1) dedup
CWE-407: Algorithmic complexity via O(W²) linear deduplication of deprecation
warning messages in run_steps(). `printed_messages` was a plain list; `message
not in printed_messages` is O(W) per iteration inside an O(W) loop.
Fix: use a set for O(1) average membership test. Message strings are hashable;
set membership is semantically equivalent (order of dedup does not matter).
Defect-Id: PRE-002
Severity: LOW
CWE: CWE-407 (Inefficient Algorithmic Complexity)
---
src/prefect/deployments/steps/core.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/prefect/deployments/steps/core.py b/src/prefect/deployments/steps/core.py
index xxxxxxx..yyyyyyy 100644
--- a/src/prefect/deployments/steps/core.py
+++ b/src/prefect/deployments/steps/core.py
@@ -190,12 +190,12 @@ async def run_steps(steps, upstream_outputs=None, print_function=print, ...):
if w:
- printed_messages = []
+ printed_messages = set() # CWE-407 fix: O(1) membership
for warning in w:
message = str(warning.message)
# prevent duplicate warnings from being printed
- if message not in printed_messages: # CWE-407: O(W) list scan
+ if message not in printed_messages: # CWE-407 fix: O(1) set
try:
print_function(message, style="yellow")
except Exception:
print_function(message)
- printed_messages.append(message)
+ printed_messages.add(message) # CWE-407 fix