GpgOL 2.7.2 hangs 17+ minutes in do_in_ui_thread type=1103 after Send event (network-independent)

Summary

When clicking Send on an encrypted message, Outlook hangs for 15-20 minutes before
the pinentry dialog appears and the message is finally sent. The freeze occurs
reproducibly on multiple client machines in our environment, regardless of antivirus
or network state. Disabling the network does NOT resolve the freeze.

GpgOL debug logs pinpoint the hang to do_in_ui_thread sending a type 1103 message
to the UI thread immediately after the Outlook Send event handler completes. A
secondary hang occurs when resolver.exe is invoked.

Environment

  • Gpg4win 5.0.2
  • GpgOL 2.7.2
  • GPGME 2.0.1
  • Outlook 16.0.0.17932 (Outlook 2024, 64-bit)
  • Windows 10, 64-bit
  • IMAP account (not Exchange, not M365)
  • No smart cards (SCardSvr is not running)
  • gpg.conf has auto-key-locate wkd,local
  • HKCU\Software\GNU\GpgOL\autoresolve = “0”
  • HKCU\Software\GNU\GpgOL\autosecure = “0”

Steps to reproduce

  1. Compose a new email to a recipient whose public key is already in the local keyring
  2. Click the GpgOL Encrypt button (Sign+Encrypt)
  3. Click Send

Result: Outlook UI freezes for 15-20 minutes. Eventually pinentry appears,
user enters passphrase, and the message is sent successfully.

Key timing evidence from the debug log

Each Send produces a multi-minute gap at exactly the same code path. Three
consecutive Send actions in one debug session produced:

Gap 1: 17 min 34 sec
Before: 01:41:58/1796/windowmessages.cpp:do_in_ui_thread: Sending message of type 1103
After: 01:59:32/5292/common.cpp:get_tmp_outfile: Extension found .dat

Gap 2: 1 min 26 sec
Before: 01:59:32/5292/cryptcontroller.cpp:resolve_keys: resolving keys with ‘resolver.exe’
After: 02:00:58/5292/common.cpp:bring_to_front: done

Gap 3: 4 min 42 sec (second Send action, same session)
Before: 02:11:38/15568/windowmessages.cpp:do_in_ui_thread: Sending message of type 1103
After: 02:16:20/10820/common.cpp:get_tmp_outfile: Extension found .dat

Gap 4: 4 min 9 sec (second resolver.exe invocation)
Before: 02:16:20/10820/cryptcontroller.cpp:resolve_keys: resolving keys with ‘resolver.exe’
After: 02:20:29/10820/common.cpp:bring_to_front: done

Notable: each Send triggers three windowmessages of type 1103 sent from three
different thread IDs to the UI thread (5292) just before the freeze:

01:41:58/8172/windowmessages.cpp:do_in_ui_thread: Sending message of type 1103
01:41:58/7440/windowmessages.cpp:do_in_ui_thread: Sending message of type 1103
01:41:58/1796/windowmessages.cpp:do_in_ui_thread: Sending message of type 1103
← hang for 17 min 34 sec →
01:59:32/5292/common.cpp:get_tmp_outfile: Extension found .dat

This pattern suggests the UI thread is blocked or unable to dispatch the
synchronous SendMessage call for an extended period.

What we have ruled out

  • Network: Disabling the network adapter and reproducing offline produces the
    same 17+ minute freeze in the same location. Three offline reproductions
    showed identical gap positions in the log.

  • Antivirus: Reproduced on machines with Windows Defender and on machines with
    ESET NOD32. Identical behavior on both.

  • GpgOL version: Reproduced on both Gpg4win 5.0.2 (GpgOL 2.7.2) and
    Gpg4win 4.4.1 (GpgOL 2.6.2).

  • Smart card subsystem: SCardSvr is not running. gpg --card-status returns
    immediately with “Service is not running”. gpg-agent.conf has no scdaemon
    configuration.

  • gpg-agent startup: gpg --list-keys from cmd returns in milliseconds even
    on a fresh boot. The gpg backend itself is fast.

  • Roaming profile / folder redirection: %APPDATA% resolves to a local path,
    not a UNC share.

  • autoresolve / autosecure: Set to “0” prior to all tests above. These fixed
    the freeze when opening compose window, but not when clicking Send.

  • Legacy Symantec PGP Desktop: Never installed on these machines.

  • Encryptomatic / other PGP COM add-ins: Not installed.

What we tried

  • Set autoresolve=“0” and autosecure=“0” → Fixed compose-window hang but
    NOT the Send hang
  • Downgrade to Gpg4win 4.4.1 → No effect
  • Reinstall Gpg4win → No effect
  • Disable network → No effect on Send hang

Attached files

  • Full GpgOL debug log covering three consecutive Send actions (one online,
    two offline)
  • Registry export of HKCU\Software\GNU\GpgOL

Affected users

gpgol.txt (115.3 KB)

This is reproducible across multiple end-user machines in our deployment
(approximately 10 users, all configured identically). Not a single-machine
issue.

Hello Chris, thank you for the excellent report!

We had a few similar (if not as thorough) reports and have now a suspect for the cause. If questions arise during our ongoing investigation we’ll come back to you.

The suspicion for a cause in the other case didn’t pan out and it seems the cases are not connected.

Which encoding is used on the systems, do you use a multi byte code encoding? Or does this occur with UTF-8?

Would you be willing to make a test run with a gpgol.dll modified to give more log details?

Hi,

Thanks for your kindly reply.

Yes, the systems use multi-byte encoding (CP936 / GBK, Simplified Chinese). The system locale is set to Chinese (PRC). chcp returns 936. The “System locale for non-Unicode programs” setting in Control Panel → Region is also “Chinese (Simplified, China)”.

All test machines use the same regional settings.

and

Yes, absolutely happy to run a custom build for debugging. Please send the modified gpgol.dll (or a link/zip), and I’ll deploy it on a test machine and capture a new debug log of the freeze.

Some questions to confirm the procedure on my side:

  • Path to replace: I assume C:\Program Files\Gpg4win\bin\gpgol.dll. Should I keep Gpg4win 5.0.2 installed and just swap this single file?

  • Do I need to re-register the COM component (regsvr32) after replacement?

  • Any specific environment variables or registry keys to set for your added logging output?

I can run the test after received the build ASAP.

Hi Chris,
unfortunately Gpg4win does not support multi-byte encoding, only UTF-8. We believe the issue is cause by the encoding.

But we would have a look at the issue anyway and see if it is something easily fixed.

Path to replace: I assume C:\Program Files\Gpg4win\bin\gpgol.dll.

Yes, as your Outlook is the usual 64bit version.

Should I keep Gpg4win 5.0.2 installed and just swap this single file?

yes.

Do I need to re-register the COM component (regsvr32) after replacement?

You only need to restart Outlook.

As to the last question: The info will come from the developer preparing the debug-version. And before you ask: I don’t know when it will be ready.

Thanks for the clear explanation — that confirms our suspicion that this is a systemic encoding issue affecting most Windows users in China, since the default system locale here is CP936 (GBK).

Looking forward to the debug build whenever it’s ready. I’ll run it on the test machine and report back with logs as soon as I have it.

In the meantime, do you have any short-term workaround suggestions for users on multi-byte locales? For example, would forcing the Windows “System locale for non-Unicode programs” setting to “English (US)” be expected to work around the issue temporarily?

I am not knowledgeable in that area but I’d not expect it, as the issue here is that the system itself is non-Unicode and the program needs Unicode. I’d think using Outlook with en-US setting might be worth a try, though.

What you can always do is deacivate (or deinstall) det GpgOL Add-In and attach already encrypted files. I am not aware of any complaints that file encryption with Kleopatra (or GpgEX) does not work with multi-byte encoding.

@Chris: It took a little longer. The developer decided to put the improved debug login output into the regular gpgol.dll. It is now available with Gpg4win 5.1.0.

Please install the new version, then set GpgOL logging to “+Call tracing” and take the steps to reproduce the issue. Log only one send action and zip the log to compress it before sending it.

Sorry for reply so late, I try to use Claude AI to solve this, the result list below

Suggested title: GpgOL 2.7.x hangs Outlook (UI thread, multi-GB memory churn) when the user locale is Chinese (CP936) — root cause: std::regex construction after setlocale(LC_ALL, “”)


Summary

On Windows machines whose user locale / regional format is Chinese (Simplified, China), GpgOL 2.7.2 (Gpg4win 5.0.2, GnuPG 2.5.18) hangs Outlook the first time it sanitizes a file name, e.g. when clicking “Secure” in a new mail. Outlook’s UI thread spins and the process memory oscillates between about 100 MB and 8 GB.

The trigger is not the system code page and not UTF-8 vs. non-UTF-8 system locale. The trigger is the C runtime locale that GpgOL itself sets in main.c (setlocale (LC_ALL, "")), which takes the user locale (here Chinese (Simplified)_China.936).

Environment

  • Gpg4win 5.0.2 (GpgOL 2.7.2, GPGME 2.0.1, GnuPG 2.5.18), 64-bit
  • Outlook 16.0.0.17932 (64-bit), Windows 10 21H2
  • Windows system locale: Chinese (PRC), ACP 936 — but the result is the same with the system locale set to English (US) (ACP 1252) and with “Beta: Use Unicode UTF-8” (ACP 65001), as long as the regional format (user locale) is Chinese (China)

Where it hangs

GpgOL debug log (enableDebug with trace, flags data oom trace) ends with:

mail.cpp:updateOOMData_o: Called. For encryption: 0
TRACE/mail.cpp:isCryptoMail:1315 enter
TRACE/mail.cpp:isCryptoMail:1321: return
TRACE/common.cpp:get_tmp_outfile:578 enter
<nothing more — Outlook is hung>

According to the 2.7.2 sources the next log output would be get_tmp_outfile: Extension found .dat. In between, the code calls sanitizeFileName(), which calls std::regex_match() with the function-local static, case-insensitive regex objects windowsDeviceNoSubDirPattern() (common.cpp). This is the first use of these static objects in the process.

Standalone reproduction

A small program (mingw-w64 GCC 13, static libstdc++; source and a trimmed GpgOL trace log are in my next post) that contains a verbatim copy of sanitizeFileName() and the two regex patterns, run in three variants (each in its own process):

Variant Result on the affected machine
nothing (default “C” locale) finishes in ~30 ms
std::locale::global(std::locale("")) finishes in ~30 ms
setlocale (LC_ALL, "") (returns Chinese (Simplified)_China.936) never finishes; stuck in construction of the static std::regex; working set oscillates 360 MB … 4 GB while the process spins

After changing only the Windows regional format to English (United States) and nothing else, setlocale (LC_ALL, "") returns English_United States.1252, all three variants finish in ~30 ms, and GpgOL works normally in Outlook (Secure, sign, send).

So the combination setlocale (LC_ALL, "") with a multibyte code page (CP936; presumably also CP932/949/950) plus std::regex with icase is what breaks. I did not analyse the libstdc++/CRT internals further.

Likely related reports

  • The earlier forum thread where an Outlook with a Japanese system froze/crashed when sending, fixed by switching the OS to English.
  • The GpgOL 2.7.2 hang in do_in_ui_thread on a Simplified Chinese (CP936) system.

(These may be the same issue; I have only verified the one above.)

Workaround / fix

Replacing the two std::regex_match calls (in sanitizeFileName and validateWindowsFileName, src/common.cpp) by a small hand written, locale independent ASCII matcher for ^(CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\..*)?$ (and the sub-directory variant) removes the hang. With that change GpgOL works with the regional format set to Chinese (China). The matcher was checked against the original std::regex on 6,000,050 random and edge-case inputs (158,000 positives): 0 mismatches. The patch against gpgol-2.7.2 (only src/common.cpp) is included at the end of this post. The same std::regex code is still present on current master.

Alternatively, constructing the regex objects before setlocale() is called, or avoiding std::regex altogether, would also be options.

Patch (against gpgol-2.7.2, only src/common.cpp)

diff --git a/src/common.cpp b/src/common.cpp
index e2d2ecf..05fffa1 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -43,7 +43,6 @@
 
 #include <string>
 #include <fstream>
-#include <regex>
 #include <algorithm>
 #include <vector>
 
@@ -1293,21 +1292,118 @@ compliance_string (bool forVerify, bool forDecrypt, bool isCompliant)
 }
 
 
-#define WINDOWS_DEVICES_PATTERN "(CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\\..*)?"
 #define SLASHES "/\\"
 
-static const std::regex&
-windowsDeviceNoSubDirPattern()
+/* Hand written replacement for the former std::regex based check.
+ *
+ * The former implementation used two function-local static std::regex
+ * objects with std::regex_constants::icase.  After GpgOL has called
+ * setlocale (LC_ALL, "") (see main.c) a CRT locale with a multibyte
+ * code page (e.g. "Chinese (Simplified)_China.936", i.e. whenever the
+ * user's regional format is Chinese/Japanese/Korean) makes the
+ * construction of such a regex loop forever while allocating and
+ * freeing gigabytes of memory in the libstdc++/CRT code.  Outlook's
+ * UI thread then hangs the first time GpgOL sanitizes a file name
+ * (e.g. when clicking "Secure" in a new mail).
+ *
+ * This code is locale independent (ASCII only) and implements the
+ * same semantics as the former patterns
+ *
+ *   ^(CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\..*)?$       (no sub dirs)
+ *   ^.*[/\\](CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\..*)?$  (sub dirs)
+ *
+ * with icase; '.' does not match CR or LF as in ECMAScript.  */
+static char
+ascii_upper (char c)
 {
-  static const std::regex rc ("^" WINDOWS_DEVICES_PATTERN "$", std::regex_constants::icase);
-  return rc;
+  return (c >= 'a' && c <= 'z') ? (char)(c - 'a' + 'A') : c;
 }
 
-static const std::regex&
-windowsDeviceSubDirPattern()
+static bool
+has_line_terminator (const std::string &s, size_t from, size_t to)
 {
-  static const std::regex rc ("^.*[/\\\\]" WINDOWS_DEVICES_PATTERN "$", std::regex_constants::icase);
-  return rc;
+  for (size_t i = from; i < to; i++)
+    {
+      if (s[i] == '\n' || s[i] == '\r')
+        return true;
+    }
+  return false;
+}
+
+/* Returns true if s[start..] matches DEVICE(\..*)? completely.  */
+static bool
+matchesWindowsDeviceAt (const std::string &s, size_t start)
+{
+  const size_t len = s.size () - start;
+  size_t devlen = 0;
+
+  if (len >= 3)
+    {
+      const char a = ascii_upper (s[start]);
+      const char b = ascii_upper (s[start + 1]);
+      const char c = ascii_upper (s[start + 2]);
+      if ((a == 'C' && b == 'O' && c == 'N') ||
+          (a == 'A' && b == 'U' && c == 'X') ||
+          (a == 'P' && b == 'R' && c == 'N') ||
+          (a == 'N' && b == 'U' && c == 'L'))
+        {
+          devlen = 3;
+        }
+    }
+  if (!devlen && len >= 4)
+    {
+      const char a = ascii_upper (s[start]);
+      const char b = ascii_upper (s[start + 1]);
+      const char c = ascii_upper (s[start + 2]);
+      const char d = s[start + 3];
+      if (((a == 'C' && b == 'O' && c == 'M') ||
+           (a == 'L' && b == 'P' && c == 'T')) &&
+          d >= '1' && d <= '9')
+        {
+          devlen = 4;
+        }
+    }
+  if (!devlen)
+    {
+      return false;
+    }
+  if (start + devlen == s.size ())
+    {
+      return true;
+    }
+  if (s[start + devlen] != '.')
+    {
+      return false;
+    }
+  return !has_line_terminator (s, start + devlen + 1, s.size ());
+}
+
+static bool
+isWindowsDeviceName (const std::string &name, bool allowDirectories)
+{
+  if (matchesWindowsDeviceAt (name, 0))
+    {
+      return true;
+    }
+  if (!allowDirectories)
+    {
+      return false;
+    }
+  /* "^.*[/\\]DEVICE..." - the part before the slash may not contain
+     CR or LF because '.' does not match them.  */
+  for (size_t i = 0; i < name.size (); i++)
+    {
+      if (name[i] == '\n' || name[i] == '\r')
+        {
+          break;
+        }
+      if ((name[i] == '/' || name[i] == '\\') &&
+          matchesWindowsDeviceAt (name, i + 1))
+        {
+          return true;
+        }
+    }
+  return false;
 }
 
 static const char notAllowedCharsSubDir[] = ",^@={}[]~!?:&*\"|#%<>$\"'();`' ";
@@ -1342,12 +1438,7 @@ validateWindowsFileName(const std::string& name, bool allowDirectories)
   }
 
   // Windows devices
-  bool matchesWinDevice = std::regex_match(name, windowsDeviceNoSubDirPattern());
-  if (!matchesWinDevice && allowDirectories)
-    {
-      matchesWinDevice = std::regex_match(name, windowsDeviceSubDirPattern());
-    }
-  return !matchesWinDevice;
+  return !isWindowsDeviceName (name, allowDirectories);
 }
 
 std::string
@@ -1377,8 +1468,7 @@ sanitizeFileName(std::string name, bool allowDirectories)
     }
 
   // Windows devices
-  if (std::regex_match(name, windowsDeviceNoSubDirPattern()) ||
-      (allowDirectories && std::regex_match(name, windowsDeviceSubDirPattern())))
+  if (isWindowsDeviceName (name, allowDirectories))
     {
       name = "_" + name;
     }

If an official fix is released, please let me know here. I’d be happy to test it on our systems (Chinese regional format, Outlook 64-bit).

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;
}

Hello @Chris, thank you for your analysis. A developer will have a look at it.

Your user-locale theory is testable: setlocale(LC_ALL,“”) follows the Windows regional format, not the system ACP. A short-term workaround for affected users may be to change Settings > Time & Language > Language & region > Regional format to English (United States), then restart Outlook; changing only the non-Unicode system locale likely won’t help. For confirmation, a developer build that skips setlocale or uses setlocale(LC_ALL,“C”) before regex construction should eliminate the hang. If it does, the locale/regex path is the culprit.