java-topology/defects/thunderbird-0006/patch/thunderbird-0006_nsSpamSettings_CheckWhiteList_ON2.patch

43 lines
1.7 KiB
Diff

# UNDF: UNDF-2026-000000892
--- a/mailnews/base/src/nsSpamSettings.cpp
+++ b/mailnews/base/src/nsSpamSettings.cpp
@@ -description
# Defect: thunderbird-0006
# Component: mailnews/base/src/nsSpamSettings.cpp
# Function: CheckWhiteList()
# Pattern: Linear email scan per message = O(M*E)
# Severity: MEDIUM
# Measured: 100x overhead at E=100 identities
#
# CheckWhiteList() is called for EVERY incoming message to determine if
# the sender is whitelisted. For each message, it performs two separate
# linear scans through the mEmails array:
#
# 1. User email matching: O(E) per message
# for (uint32_t i = 0; i < mEmails.Length(); ++i) {
# if (mEmails[i].Equals(authorEmailAddress, ...))
#
# 2. Domain matching: O(E) per message (with string allocation per element)
# for (uint32_t i = 0; i < mEmails.Length(); ++i) {
# int32_t atPos = mEmails[i].FindChar('@');
# identityDomain = Substring(mEmails[i], atPos + 1);
# if (identityDomain.Equals(domain, ...))
#
# For M incoming messages with E identity emails, total cost is O(M*E).
# Enterprise users with many identities (shared mailboxes, aliases,
# mailing lists) feel this on every folder sync.
#
# Fix: Pre-compute HashSets of normalized emails and domains in
# Initialize() or on first call, then use O(1) lookups per message.
#
# After (O(1) per message):
# // In Initialize() or lazy init:
# nsTHashSet<nsCString> mEmailSet;
# nsTHashSet<nsCString> mDomainSet;
# for email in mEmails:
# mEmailSet.Insert(ToLowerCase(email));
# mDomainSet.Insert(ToLowerCase(domain_of(email)));
#
# // In CheckWhiteList():
# if (mEmailSet.Contains(ToLowerCase(authorEmailAddress))) return;
# if (mDomainSet.Contains(ToLowerCase(authorDomain))) return;