[GpgOL] Outlook hangs (multi-GB allocation) on DBCS locales: setlocale(LC_ALL,"") + std::regex

yiguei lin yiguei.hyjr at gmail.com
Wed Oct 28 06:51:42 CET 2026


Affected: GpgOL 2.5.14 (Gpg4win 4.4.0); the same code is in 2.7.6.
Windows 10, Outlook 16 x64, system locale zh-TW (cp950).
Possibly the same as forum.gnupg.org/t/6599 and /t/7356
(15-30 min hangs around get_tmp_outfile).

Facts
- Clicking Reply freezes Outlook: main thread 100% CPU in
  msvcrt!memmove, private memory ~4.2 GB.
- The log stops at "mail.cpp:updateOOMData_o: Called", before
  "Attachment candidate is ..." in get_tmp_outfile (common.cpp).
  In between only sanitizeFileName() does real work: std::regex.
- main.c i18n_init() calls setlocale (LC_ALL, "")
  (LC_MESSAGES is not defined on mingw-w64).
- Under cp950, msvcrt strxfrm() returns 0x7fffffff (errno EILSEQ)
  for every byte 0x80..0xFF. libstdc++ transforms all 256 bytes when
  compiling a bracket range, so it allocates ~2 GiB per byte.

Reproduce (mingw-w64 GCC 10.5, msvcrt, Windows with a DBCS ANSI
code page):

  #include <regex>
  #include <clocale>
  int main(){ setlocale(LC_ALL,""); std::regex r("[1-9]"); }

- no setlocale: returns at once.
- setlocale(LC_ALL,""): never returns.
- setlocale(LC_COLLATE,"") alone hangs; setlocale(LC_CTYPE,"") alone
  does not.
- Patterns without a range ("abc", "COM1") do not hang.

Proposed fix (the regex hang disappears with this change in the
program above): after
setlocale (LC_ALL, ""), call setlocale (LC_COLLATE, "C").
Alternative: avoid std::regex in sanitizeFileName().

--- a/src/main.c
+++ b/src/main.c
@@ -50,6 +50,10 @@
   setlocale (LC_MESSAGES, "");
 # else
   setlocale (LC_ALL, "" );
+  /* With a DBCS ANSI code page (e.g. cp950) msvcrt's strxfrm returns
+   * INT_MAX for bytes 0x80..0xFF; libstdc++'s regex then tries to
+   * allocate ~2 GiB per byte while compiling any "[x-y]" expression.  */
+  setlocale (LC_COLLATE, "C");
 # endif
 #endif

Credit: the root-cause analysis, the reproduction program and the
proposed patch were produced by Claude (Anthropic's AI model, used
through Claude Code).


More information about the Gnupg-devel mailing list