java-topology/defects/peewee/patch/peewee-0001-print-table-accum-set.patch
russell@unturf.com c9e86c450c opensmtpd-0001: mta_handle_envelope TAILQ_FOREACH O(N²) task lookup — patch + unit test
Add patch replacing linear TAILQ_FOREACH scan in mta_handle_envelope()
with tree_get() on a per-relay task_by_msgid splay-tree index; assign
UNDF-2026-000000201. Unit test confirms 100x op-count improvement at
N=100 tasks/relay.
2026-03-30 07:00:50 -04:00

22 lines
1.1 KiB
Diff

# UNDF: UNDF-2026-000000209
--- a/pwiz.py
+++ b/pwiz.py
@@ -72,7 +72,10 @@ def introspect(database, table_names=None, **kwargs):
def _print_table(table, seen, accum=None):
- accum = accum or []
+ # CWE-407 fix: replace list with set for O(1) membership checks.
+ # Original code used `if dest in accum` (O(N) scan) inside a loop
+ # over foreign keys, and passed `accum + [table]` (O(N) copy) on
+ # each recursive call — O(N²) total for schema graphs with deep FK chains.
+ accum = accum or set()
foreign_keys = database.foreign_keys[table]
for foreign_key in foreign_keys:
dest = foreign_key.dest_table
@@ -85,6 +88,6 @@ def introspect(database, table_names=None, **kwargs):
# not already processed the destination table, do so now.
if dest not in seen and dest not in accum:
seen.add(dest)
if dest != table:
- _print_table(dest, seen, accum + [table])
+ _print_table(dest, seen, accum | {table})