Follow-up with the details referenced above.
1. GpgOL trace log (enableDebug = oom+data+trace), shortened
Addresses and host/user names replaced by placeholders. The last line is where Outlook hangs.
### Trimmed GpgOL 2.7.2 debug log (enableDebug = oom+data+trace). Full log: 5958 lines.
### Kept: startup/version lines (orig. 1, 29-40) and everything from opening the compose window (orig. line 5741) to the hang. Hang = last line.
### Mail addresses / host / user names replaced by placeholders.
07:15:57/3452/enabled debug flags: data oom trace
07:15:57/3452/TRACE/gpgoladdin.cpp:GpgolAddin:189
07:15:57/3452/GetModuleFileName: 'D:\PGP\Gpg4win\bin\gpgol.dll'
07:15:57/3452/Using install dir: 'D:\PGP\Gpg4win'
07:15:57/3452/using gpgme version '2.0.1'
07:15:57/3452/TRACE/gpgoladdin.cpp:GpgolAddin:211
07:15:57/3452/gpgoladdin.cpp:~GpgolAddinFactory: Object deleted
07:15:57/3452/gpgoladdin.cpp:OnConnection: this is GpgOL 2.7.2
07:15:57/3452/DBG_OOM/gpgoladdin.cpp:OnConnection:346 AddRef on 000001aa84340230
07:15:57/3452/TRACE/oomhelp.cpp:get_oom_string:889 enter
07:15:57/3452/TRACE/oomhelp.cpp:get_oom_string:915: return
07:15:57/3452/gpgoladdin.cpp:OnConnection: using GPGME 2.0.1
07:15:57/3452/gpgoladdin.cpp:OnConnection: in Outlook 16.0.0.17932
### [... original lines 41-5740 omitted: normal startup, reading test mails ...]
### [... lines omitted; the last part of the log follows ...]
07:16:03/3452/TRACE/oomhelp.cpp:get_unique_id:2489: return
07:16:03/3452/TRACE/mail.cpp:getMailForUUID:291 enter
07:16:03/3452/TRACE/mail.cpp:getMailForUUID:296: lock 00007ffe51d703c0 lock
07:16:03/3452/TRACE/mail.cpp:getMailForUUID:298: lock 00007ffe51d703c0 unlock.
07:16:03/3452/TRACE/mail.cpp:getMailForUUID:301: return
07:16:03/3452/ribbon-callbacks.cpp:mark_mime_action: Failed to get mail object.
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_base_message:1900 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_message:1849 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_iunknown:941 enter
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_iunknown:963 AddRef on 000001aa846193e8
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_iunknown:964: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_message:1857: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_base_message_from_mapi:1863 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_object_by_id:1795 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_object_by_id:1807: return
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_base_message_from_mapi: About to call GetBaseMessage.
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_base_message_from_mapi:1886 AddRef on 000001aa84c6da78
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_base_message_from_mapi:1894: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_base_message:1911: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgol_draft_info_flags:3308 enter
07:16:03/3452/TRACE/mapihelp.cpp:mapi_get_gpgol_draft_info:3191 enter
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:254 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:118 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:148: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:260: return
07:16:03/3452/TRACE/mapihelp.cpp:mapi_get_gpgol_draft_info:3204: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgol_draft_info_flags:3313: return
07:16:03/3452/TRACE/mapihelp.cpp:set_gpgol_draft_info_flags:3334 enter
07:16:03/3452/TRACE/mapihelp.cpp:mapi_set_gpgol_draft_info:3235 enter
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:254 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:118 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:148: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:260: return
07:16:03/3452/TRACE/mapihelp.cpp:mapi_set_gpgol_draft_info:3264: return
07:16:03/3452/TRACE/mapihelp.cpp:set_gpgol_draft_info_flags:3342: return
07:16:03/3452/gpgoladdin.cpp:invalidateRibbons: Invalidating ribbon: 000001aafea739c8
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method:1958 enter
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method_with_parms:1949 enter
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method_with_parms_type:1919 enter
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method_with_parms_type:1942: return
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method_with_parms:1952: return
07:16:03/3452/TRACE/oomhelp.cpp:invoke_oom_method:1960: return
07:16:03/3452/gpgoladdin.cpp:invalidateRibbons: Invalidation done.
07:16:03/3452/TRACE/mail.cpp:locateAllCryptoRecipients_o:4679 enter
07:16:03/3452/TRACE/mail.cpp:locateAllCryptoRecipients_o:4680: lock 00007ffe51d70400 lock
07:16:03/3452/TRACE/mail.cpp:locateAllCryptoRecipients_o:4683: lock 00007ffe51d70400 unlock.
07:16:03/3452/TRACE/mail.cpp:needs_crypto_m:2329 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_message:1849 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_iunknown:941 enter
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_iunknown:963 AddRef on 000001aa846193e8
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_iunknown:964: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_message:1857: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgol_draft_info_flags:3308 enter
07:16:03/3452/TRACE/mapihelp.cpp:mapi_get_gpgol_draft_info:3191 enter
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:254 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:118 enter
07:16:03/3452/TRACE/mapihelp.cpp:create_gpgol_tag:148: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgoldraftinfo_tag:260: return
07:16:03/3452/TRACE/mapihelp.cpp:mapi_get_gpgol_draft_info:3212: return
07:16:03/3452/TRACE/mapihelp.cpp:get_gpgol_draft_info_flags:3324: return
07:16:03/3452/TRACE/mail.cpp:needs_crypto_m:2340: return
07:16:03/3452/TRACE/mail.cpp:locateKeys_o:4153 enter
07:16:03/3452/TRACE/addressbook.cpp:check_o:420 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_object:227 enter
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_object: looking for 000001aa8497cca0->`Recipients'
07:16:03/3452/DBG_OOM/oomhelp.cpp:get_oom_object:411 AddRef on 000001aa844b0000
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_object:283: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_recipients_with_addrEntry:1589 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_int:782 enter
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_int:808: return
07:16:03/3452/TRACE/oomhelp.cpp:get_oom_recipients_with_addrEntry:1596: return
07:16:03/3452/TRACE/addressbook.cpp:check_o:521: return
07:16:03/3452/TRACE/oomhelp.cpp:release_disp:3220 enter
07:16:03/3452/TRACE/oomhelp.cpp:release_disp:3222: return
07:16:03/3452/TRACE/mail.cpp:updateOOMData_o:2377 enter
07:16:03/3452/mail.cpp:updateOOMData_o: Called. For encryption: 0
07:16:03/3452/TRACE/mail.cpp:isCryptoMail:1315 enter
07:16:03/3452/N
07:16:03/3452/TRACE/mail.cpp:isCryptoMail:1321: return
07:16:03/3452/TRACE/common.cpp:get_tmp_outfile:578 enter
2. Standalone reproduction (regex_test.cpp)
Build: x86_64-w64-mingw32-g++ -std=c++17 -O1 -static -static-libgcc -static-libstdc++ -o regex_test.exe regex_test.cpp -lpsapi
// Standalone reproduction of the code path GpgOL 2.7.2 runs between
// "get_tmp_outfile enter" and "Extension found"
// (common.cpp: getTmpPathUtf8 / wchar_to_utf8_string / sanitizeFileName).
// sanitizeFileName and the regex patterns are copied verbatim from
// gpgol-2.7.2 src/common.cpp.
//
// Usage: regex_test.exe -> run all variants, each in its own
// child process with a 20 s timeout
// regex_test.exe child <v> -> (internal) run one variant
//
// Output: console + regex_test_result.txt (next to the exe)
#include <windows.h>
#include <psapi.h>
#include <algorithm>
#include <clocale>
#include <cstdio>
#include <cstring>
#include <locale>
#include <regex>
#include <string>
#include <vector>
#define WINDOWS_DEVICES_PATTERN "(CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\\..*)?"
#define SLASHES "/\\"
static const std::regex &
windowsDeviceNoSubDirPattern ()
{
static const std::regex rc ("^" WINDOWS_DEVICES_PATTERN "$",
std::regex_constants::icase);
return rc;
}
static const std::regex &
windowsDeviceSubDirPattern ()
{
static const std::regex rc ("^.*[/\\\\]" WINDOWS_DEVICES_PATTERN "$",
std::regex_constants::icase);
return rc;
}
static const char notAllowedCharsSubDir[] = ",^@={}[]~!?:&*\"|#%<>$\"'();`' ";
static const char notAllowedCharsNoSubDir[] =
",^@={}[]~!?:&*\"|#%<>$\"'();`' " SLASHES;
static const char *notAllowedSubStrings[] = {".."};
static FILE *g_out = nullptr;
static char g_progress_path[MAX_PATH] = {0};
static void
say (const char *fmt, ...)
{
char buf[1024];
va_list a;
va_start (a, fmt);
vsnprintf (buf, sizeof buf, fmt, a);
va_end (a);
fputs (buf, stdout);
fflush (stdout);
if (g_out)
{
fputs (buf, g_out);
fflush (g_out);
}
}
/* child progress: append one line, flush immediately */
static void
progress (const char *stage)
{
FILE *f = fopen (g_progress_path, "a");
if (f)
{
fprintf (f, "%s\n", stage);
fclose (f);
}
}
static std::string
sanitizeFileName (std::string name, bool allowDirectories = false)
{
if (name.empty ())
return "attachment";
progress ("sanitize: remove not-allowed chars");
const char *notAllowedChars = allowDirectories ? notAllowedCharsSubDir
: notAllowedCharsNoSubDir;
for (const char *c = notAllowedChars; *c; ++c)
name.erase (std::remove (name.begin (), name.end (), *c), name.end ());
progress ("sanitize: remove not-allowed substrings");
for (const auto &subStr : notAllowedSubStrings)
{
size_t pos;
while ((pos = name.find (subStr)) != std::string::npos)
name.erase (pos, std::strlen (subStr));
}
progress ("sanitize: construct static regex (first use)");
const std::regex &re = windowsDeviceNoSubDirPattern ();
progress ("sanitize: regex constructed, running regex_match");
bool m = std::regex_match (name, re);
if (m ||
(allowDirectories &&
std::regex_match (name, windowsDeviceSubDirPattern ())))
name = "_" + name;
progress ("sanitize: regex_match done");
return name.empty () ? "_" : name;
}
static std::string
wide_to_utf8 (const wchar_t *w)
{
int n = WideCharToMultiByte (CP_UTF8, 0, w, -1, NULL, 0, NULL, NULL);
if (n <= 0)
return std::string ();
std::string r (n, '\0');
WideCharToMultiByte (CP_UTF8, 0, w, -1, &r[0], n, NULL, NULL);
r.resize (n - 1);
return r;
}
static int
run_variant (const std::string &v)
{
progress ("child: start");
if (v == "plain")
{
/* nothing: default "C" CRT locale, classic C++ locale */
}
else if (v == "setlocale")
{
/* CRT locale = system ANSI code page (e.g. Chinese_China.936) */
const char *r = setlocale (LC_ALL, "");
char b[200];
snprintf (b, sizeof b, "child: setlocale(LC_ALL,\"\") -> %s",
r ? r : "(null)");
progress (b);
}
else if (v == "cxxglobal")
{
try
{
std::locale::global (std::locale (""));
progress ("child: std::locale::global(std::locale(\"\")) ok");
}
catch (const std::exception &e)
{
char b[300];
snprintf (b, sizeof b, "child: std::locale(\"\") threw: %s",
e.what ());
progress (b);
}
}
progress ("stage1: GetTempPathW");
wchar_t tmp[MAX_PATH + 2];
if (!GetTempPathW (MAX_PATH, tmp))
{
progress ("stage1: GetTempPathW FAILED");
return 2;
}
std::string tmpUtf8 = wide_to_utf8 (tmp);
progress ("stage2: utf8 conversion done");
std::string name = sanitizeFileName ("gpgol_enc.dat");
progress ("stage3: sanitizeFileName returned");
char b[400];
snprintf (b, sizeof b, "child: DONE ok, result='%s' tmp='%s'",
name.c_str (), tmpUtf8.c_str ());
progress (b);
return 0;
}
static std::string
read_last_line (const char *path)
{
FILE *f = fopen (path, "r");
std::string last;
if (!f)
return last;
char line[600];
while (fgets (line, sizeof line, f))
last = line;
fclose (f);
while (!last.empty () && (last.back () == '\n' || last.back () == '\r'))
last.pop_back ();
return last;
}
int
main (int argc, char **argv)
{
char exe[MAX_PATH];
GetModuleFileNameA (NULL, exe, MAX_PATH);
std::string dir (exe);
dir = dir.substr (0, dir.find_last_of ("\\/") + 1);
if (argc >= 3 && !strcmp (argv[1], "child"))
{
snprintf (g_progress_path, sizeof g_progress_path,
"%sprogress_%s.txt", dir.c_str (), argv[2]);
return run_variant (argv[2]);
}
std::string outpath = dir + "regex_test_result.txt";
g_out = fopen (outpath.c_str (), "w");
say ("== GpgOL 2.7.2 sanitizeFileName reproduction ==\n");
say ("GetACP=%u GetOEMCP=%u UserDefaultLCID=0x%04lx\n", GetACP (),
GetOEMCP (), (unsigned long)GetUserDefaultLCID ());
say ("CRT setlocale(LC_ALL,NULL)=%s\n", setlocale (LC_ALL, NULL));
say ("C++ std::locale().name()=%s\n", std::locale ().name ().c_str ());
say ("(each variant runs in its own process, 20 s timeout)\n\n");
const char *variants[] = {"plain", "setlocale", "cxxglobal"};
for (const char *v : variants)
{
std::string prog = dir + "progress_" + v + ".txt";
DeleteFileA (prog.c_str ());
std::string cmd = std::string ("\"") + exe + "\" child " + v;
STARTUPINFOA si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof si);
si.cb = sizeof si;
ZeroMemory (&pi, sizeof pi);
std::vector<char> cl (cmd.begin (), cmd.end ());
cl.push_back (0);
say ("--- variant: %s ---\n", v);
DWORD t0 = GetTickCount ();
if (!CreateProcessA (NULL, cl.data (), NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
{
say (" CreateProcess failed (%lu)\n", GetLastError ());
continue;
}
bool timeout = false;
SIZE_T peak = 0;
for (;;)
{
DWORD w = WaitForSingleObject (pi.hProcess, 1000);
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo (pi.hProcess, &pmc, sizeof pmc))
{
peak = std::max (peak, pmc.PeakWorkingSetSize);
if (w == WAIT_TIMEOUT)
say (" t=%2lus working set %6.1f MB (peak %.1f MB)\n",
(GetTickCount () - t0) / 1000,
pmc.WorkingSetSize / 1048576.0, peak / 1048576.0);
}
if (w != WAIT_TIMEOUT)
break;
if (GetTickCount () - t0 > 20000)
{
timeout = true;
TerminateProcess (pi.hProcess, 99);
WaitForSingleObject (pi.hProcess, 2000);
break;
}
}
DWORD code = 0;
GetExitCodeProcess (pi.hProcess, &code);
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
std::string last = read_last_line (prog.c_str ());
if (timeout)
say (" RESULT: HANG (killed after 20 s). Last stage reached: %s\n\n",
last.c_str ());
else
say (" RESULT: finished in %lu ms, exit code %lu. Last stage: %s\n\n",
GetTickCount () - t0, code, last.c_str ());
}
say ("Done. Please send regex_test_result.txt and the progress_*.txt files.\n");
if (g_out)
fclose (g_out);
return 0;
}