Adobe Acrobat Reader - resetForm - CAgg UaF - RCE Exploit - CVE-2023-21608
Published on hacksys.io
This post provides a thorough examination of a notable remote code execution vulnerability found in Adobe Reader. Specifically, the resetForm method is under scrutiny, revealing how its flawed implementation can be exploited by attackers.
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
This is the third part of a series on PDF readers. The first two parts covered an information leak in Adobe Reader through XFA ANSI-Unicode confusion (CVE-2021-45067) and a use-after-free in Foxit PDF Reader exploited for remote code execution (CVE-2022-28672). This part returns to Adobe Acrobat Reader DC, where a use-after-free found during a fuzzing campaign against popular PDF readers was turned into remote code execution in the context of the reader process. The vulnerability is CVE-2023-21608, and the Zero Day Initiative acquired both the vulnerability and the exploit.
The feature at the centre of the bug is the JavaScript form API that ships inside Acrobat Reader. PDF documents can embed JavaScript, and the reader exposes a document object (this inside document-level script) with methods for manipulating form fields. Two of those interact here:
resetForm()resets form fields to their default values. As part of that work it invokes theCalculateevent on every field that has aCalculatehandler defined.- A field's
Calculatehandler receives aneventobject. Assigning toevent.richValuemakes the reader aggregate the assigned value into an internal representation.
That internal representation is built from CAgg objects, the reader's aggregate value type, which are held in std::map<unsigned short, CAgg> containers keyed by an atom id derived from a property name. When a JavaScript object such as the document itself is assigned to richValue, the reader enumerates the object's properties recursively and converts each one into a CAgg. The bug lives in the lifetime handling of those CAgg objects during that enumeration.
The advisory for the issue is published as HI-2022-006.
Setup
The testbed listed in the report is:
- OS edition: Windows 10 Pro 20H2 19042.804
- Product: Adobe Acrobat Reader DC 2022.003.20258
- Product URL: https://get.adobe.com/reader/otherversions/
The crash analysis and the exploitation work were done on a different build from the one in the testbed list: the report notes that all analysis and exploitation was performed on Adobe Acrobat Reader DC 2022.001.20085 x86. The 32-bit build matters for everything that follows, because the exploitation strategy depends on spraying controlled data at predictable addresses in a 32-bit address space.
To observe the bug, page-heap is enabled for AcroRd32.exe and the crash.pdf file is opened with Acrobat Adobe Reader DC. With page-heap on, freed allocations are kept in a state where a later access to them faults immediately, which is what turns the lifetime bug into a clean crash in the debugger rather than silent reuse of the memory.
The proof of concept is a PDF document containing a static text field named testField:
5 0 obj << /Type /Annot /Subtype /Widget /T (testField) /FT /Tx /Rect [0 0 0 0] >>
The field is a text field (/FT /Tx) with the name testField, and its rectangle is zero-sized, so it has no visible presence on the page. The document-level JavaScript that triggers the bug is:
var testField = this.getField("testField");
testField.richText = true;
testField.setAction("Calculate", "calculateCallback()");
try { this.resetForm(); } catch (e) {}
try { this.resetForm(); } catch (e) {} // bug is triggered during this resetForm call
function calculateCallback()
{
event.__defineGetter__("target", getterFunc);
event.richValue = this;
}
function getterFunc()
{
try { Object.defineProperty(testField, "textFont", { value: this }); } catch(e) { }
}
The script does four things. It fetches the field object by name. It turns on rich text for the field and registers calculateCallback as the field's Calculate action. It then calls this.resetForm() twice, each wrapped in a try/catch because the calls are expected to throw. The comment marks the second call as the one that triggers the bug.
Inside the callback, the event object's target property is replaced with an accessor whose getter is getterFunc, using the non-standard __defineGetter__. The callback then assigns the document object (this) to event.richValue. The getter, when it runs, tries to redefine the field's textFont property with the document object as its value, inside a try/catch because the redefinition can fail.
The two resetForm calls are not redundant. The first call installs the state that makes the second one take a different path, and the report's root cause analysis explains exactly which state that is.
Finding it
With page-heap enabled, opening crash.pdf in Acrobat Adobe Reader DC produces the following fault:
eax=04f6a0f0 ebx=00000000 ecx=420fefd0 edx=44e1cff8 esi=6921ef50 edi=420fefd0 eip=6c556b99 esp=04f6a0d0 ebp=04f6a0fc iopl=0 nv up ei pl nz na pe nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206 AcroForm!CAgg::operator[](unsigned short)+0xe: 6c556b99 8b07 mov eax,dword ptr [edi] ds:002b:420fefd0=????????
The faulting instruction is a plain dereference of edi inside AcroForm!CAgg::operator[](unsigned short), and the address it reads, 420fefd0, is not mapped. The crash is in the aggregate value type, not in the JavaScript engine, which already suggests the problem is in how Acrobat's form layer handles the values it is handed.
Stack trace
The call stack shows how the reader got there:
Read from the bottom up, the chain is exactly the path the PoC describes. resetFormHandler enters ResetForm, which calls AFPDCalculateFields and then AFCalculateNthFieldEntry_x to run the Calculate action of the field. That reaches ESExecuteScriptWithEvent and the JavaScript interpreter, which executes calculateCallback. The callback's event.richValue = this assignment lands in SetRichValueEventProp, which calls ESValToCAggWrapper and then ESValToCAgg.
From there the stack repeats in groups of four frames: EScript_ESObjectEnum_CallbackProc, EScript_ESObjectEnum, EScript_ESObjectEnumWrapper and ESValToCAgg_internal. That repetition is the recursive property enumeration of the document object, with each level converting an enumerated property into a CAgg. The innermost frame is the crash: CAgg::operator[] called from EScript_ESObjectEnum_CallbackProc.
Verifying the free
The address in edi is the one that faults, so the next question is what state that memory is in. The page-heap extension answers it:
0:000> !ext.heap -p -a @edi address 420fefd0 found in _DPH_HEAP_ROOT @ 7831000 in free-ed allocation ( DPH_HEAP_BLOCK: VirtAddr VirtSize) 372134ac: 420fe000 2000 6e44ab02 verifier!AVrfDebugPageHeapFree+0x000000c2 770af766 ntdll!RtlDebugFreeHeap+0x0000003e 770668ae ntdll!RtlpFreeHeap+0x0004e0ce 770562ed ntdll!RtlpFreeHeapInternal+0x00000783 77018786 ntdll!RtlFreeHeap+0x00000046 755d3c9b ucrtbase!_free_base+0x0000001b 755d3c68 ucrtbase!free+0x00000018 6c2e7a56 AcroForm!operator delete(void *)+0x0000000b 6c555f05 AcroForm!sub_20AD5ECD+0x00000038 6c555e5f AcroForm!sub_20AD5E3B+0x00000024 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e1b AcroForm!sub_20AD5DE9+0x00000032 6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0 6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7 6c5576c0 AcroForm!CAgg::convert(CAgg::CAggType)+0x00000045 6c556d10 AcroForm!sub_20AD6CDD+0x00000033 6c555efd AcroForm!sub_20AD5ECD+0x00000030 6c555e5f AcroForm!sub_20AD5E3B+0x00000024 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e1b AcroForm!sub_20AD5DE9+0x00000032 6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0 6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7 6c55766d AcroForm!sub_20AD75F2+0x0000007b 6c551b9e AcroForm!CAggConvertToESValType(CAgg &)+0x0000001f 6c551be0 AcroForm!CAggToESVal(_s_ESValRec *, CAgg &)+0x0000003d 6c5131ce AcroForm!GetRichValueEventProp+0x0000011e 6bdde176 EScript!sub_1003DF10+0x00000266 6bde306d EScript!sub_10042FE8+0x00000085 6bdb50fd EScript!sub_10014B57+0x000005a6 6bdb4b4a EScript!sub_10014B17+0x00000033 6bdddcd2 EScript!sub_1003DC6A+0x00000068
The block is in a free-ed allocation, and the free stack names the code that released it: AcroForm!operator delete, reached through CAgg::convert and CAgg::convertASAtommap, which were themselves called from CAggToESVal inside GetRichValueEventProp. In other words, the same richValue handling that is enumerating properties also frees the CAgg objects, and the enumeration keeps using a pointer to one of them afterwards. That is a use-after-free, and the crash is the first visible symptom of it.
With the initial analysis in hand, the next step was to work out the root cause in detail and see whether the freed object could be controlled well enough to reach code execution in the reader's sandbox process.
Exploitation
The chain from the crash to code execution runs through the aggregate value handling, the JavaScript engine's object layout, and a set of primitives built on top of a corrupted ArrayBuffer. The report presents it in the order below: first the root cause, then a debugger confirmation of the free, then heap grooming, then the SpiderMonkey internals needed to build the primitives, and finally the primitives themselves, the control-flow hijack and the recovery.
Root cause analysis
The report lists four observations about the PoC that explain the trigger:
- The bug occurs during the second call to
resetForm. resetForminvokes calculate events on all fields if aCalculatehandler is defined.- In the
Calculatehandler, theeventobject'stargetproperty is overridden with a user-defined functiongetterFunc. - Inside
getterFunc, thetextFontproperty of the field is redefined with the value of thedocobject.
The crash happens when event.richValue = this is executed in the Calculate handler. The call hierarchy behind it is:
AcroForm!ResetForm | this.resetForm() AcroForm!AFPDCalculateFields AcroForm!AFCalculateNthFieldEntry AcroForm!AFCalculateNthFieldEntry AcroForm!AFCalculateNthFieldEntry |- user defined callback is triggered. | field Calculate handler invoked AcroForm!SetRichValueEventProp | event.richValue = this .. some form of aggregation starts on richValue .. AcroForm!EScript_ESObjectEnum_CallbackProc AcroForm!CAgg::operator[](unsigned short)
The aggregation inside SetRichValueEventProp enumerates the assigned object, which is the current doc object. The properties and methods of doc are enumerated recursively through EScript!ESObjectEnum, which takes a callback so that enumerated property details pass from EScript to AcroForm. AcroForm!EScript_ESObjectEnum_CallbackProc runs for every property.
With page-heap enabled, the crash lands in std::map<unsigned short,CAgg>::lower_bound while dereferencing this, a std::map object:
DWORD *__thiscall std::map<unsigned short,CAgg>::lower_bound(TREE_VAL *this, _DWORD *a2, unsigned __int16 *a3)
{
TREE_NODE *Myhead; // eax
TREE_NODE *Parent; // ecx
unsigned __int16 v5; // si
int v6; // eax
Myhead = this->_Myhead; // crash location - page-heaps enabled
Parent = this->_Myhead->_Parent;
...
}
The caller is std::map<unsigned short,CAgg>::operator[], which inserts a value into the map:
int __thiscall std::map<unsigned short,CAgg>::operator[](TREE_VAL *this, int a2, unsigned __int16 *pSomeID)
{
...
std::map<unsigned short,CAgg>::lower_bound(this, v8, pSomeID); // Crashing path when page-heap is enabled
v4 = v9;
if ( sub_208E95F2(v9, pSomeID) )
{
...
}
else
{
if ( this->_Mysize == 0x38E38E3 )
Throw_tree_length_error();
...
*(_DWORD *)a2 = std::map<unsigned short,CAgg>::insert(this, v8[0], (int)v8[1], Parent);
...
}
return result;
}
A new CAgg allocation is created while inserting into the map. Testing with heap grooming and the .dvalloc trick showed that std::map<unsigned short,CAgg>::insert also allows arbitrary writes to a chosen address:
Root cause
The mistake is a lifetime one, and it sits in the interaction between two pieces of code that each look reasonable on their own. SetRichValueEventProp starts an aggregation of the value assigned to event.richValue. Because that value is the doc object, the aggregation becomes a recursive enumeration: EScript!ESObjectEnum walks the document's properties and calls AcroForm!EScript_ESObjectEnum_CallbackProc for each one, and the callback converts the property into a CAgg by calling CAgg::operator[], which inserts into the std::map<unsigned short,CAgg> owned by the CAgg being built. Each level of the recursion allocates its own CAgg and its own map.
The enumeration is not a closed operation. It runs JavaScript: the target property of event has been replaced with an accessor, so when the enumeration reaches target, getterFunc executes in the middle of the walk. On the first resetForm, getterFunc redefines testField.textFont with the doc object as its value, and the redefinition also makes the property non-configurable and non-enumerable. On the second resetForm, the same enumeration reaches target again and getterFunc runs again, but this time Object.defineProperty on textFont raises an exception because the property is already non-configurable. That exception changes the path taken when event.richValue is accessed: the free code path in GetRichValueEventProp runs, and it frees every CAgg and every map constructed so far, including the one the enumeration is currently sitting on.
The callback still holds the pointer. EScript_ESObjectEnum_CallbackProc receives the CAgg through pCAggData, and after the free it passes that same pointer to CAgg::operator[] and then to ESValToCAgg. The report notes that the function is recursive, so the problem repeats over and over. The crash in CAgg::operator[] is simply the first frame that touches freed memory after the free path completes.
Page-heap matters for visibility, not for the bug. With page-heap enabled, the freed block is unmapped or poisoned, so the dereference of this->type in CAgg::operator[] faults immediately and the debugger shows a clean access violation on a free-ed allocation. With page-heap disabled and heap grooming performed before the bug trigger, the code takes the other branch, calling CAgg::convert and then std::map<unsigned short,CAgg>::operator[] on this->map. That is the branch the exploit needs, and it is why the report describes the page-heap crash as the diagnostic view and the non-page-heap path as the exploitable one.
The non-configurable behaviour is what makes the second call different from the first. Without it, getterFunc would succeed on both calls, the enumeration would complete normally, and the free path would not be entered mid-walk. The try/catch around Object.defineProperty in the PoC swallows the exception, but the exception has already diverted control inside the reader before the JavaScript sees it.
The primitive itself is narrow. The report states that during testing to control the use-after-free, no code path was found that would reallocate the freed memory in a way that could be exploited directly, and that the opening came from object sizes that make the reader dereference a sprayed pattern. What the researchers did find is that certain object sizes cause the reader to crash while dereferencing a sprayed pattern, which is the opening they used. The corrupted CAgg offers a readable type field and a map pointer that flows into std::map<unsigned short,CAgg>::operator[]; the insert path inside that function performs writes to addresses derived from the map's tree nodes, and with heap grooming the corrupted map pointer can be steered so those writes land on a chosen address. That is a constrained write, not a general one, and turning it into a reliable primitive took the heap layout work described in the exploitation sections.
Impact
The end result demonstrated in the report is remote code execution in the context of Adobe Acrobat Reader. The exploit runs from JavaScript embedded in a PDF, and the script drives the reader into the use-after-free and then into shellcode execution. The report describes the goal as achieving RCE in Adobe Reader's sandbox process, and the exploit log records the payload executing. The report notes that the reader crashes after the shellcode unless the context is restored, and describes the restoration steps.
The conditions are specific, and the report is explicit about them:
- 32-bit build. All analysis and exploitation was done on Adobe Acrobat Reader DC 2022.001.20085 x86. The whole chain depends on spraying controlled data at predictable addresses, which is only practical in a 32-bit address space.
- Heap grooming before the trigger. The exploit grooms LFH blocks of size 68 with 4000 allocations before the vulnerability is triggered, and sprays
ArrayBufferobjects until one lands at a predictable address such as0x20000048. Without that layout work the freedCAggis not replaced with controlled data and the corruptedstd::mappointer does not point where the exploit needs it. - A field with a
Calculatehandler and the two-call sequence. The document must contain a field whoseCalculateaction installs thetargetgetter and assigns toevent.richValue, andresetFormmust be called twice so that the second call hits the non-configurabletextFontproperty and takes the free path mid-enumeration. - CFG bypass. CFG is enabled by default in Acrobat Reader, so the exploit cannot call the shellcode directly. It relies on a non-CFG instrumented call site,
sub_20EFAA60, to redirect execution to a controlled address.
The report also covers the 64-bit version of the reader, which was affected by CVE-2023-21608 as well. The researchers evaluated exploiting it and found two blocking issues:
- Heap spraying is no longer possible in a 64-bit address space, so the
ArrayBufferspraying technique cannot place controlled data at predictable addresses. A separate information leak would be needed, which the report notes is not difficult to find. - The deeper problem is the string aggregation itself. The sprayed strings are used as aggregation objects, and new strings are created from them with standard C null terminators respected. Any address containing two consecutive null bytes stops the string copy, so the freed memory can never be reallocated with a controlled chunk that carries the leaked
ArrayBufferaddress. The bug would no longer be effective or reproducible.
The practical consequence is that the exploit as published targets the 32-bit reader, and the 64-bit build, while vulnerable, was not shown to be exploitable with this technique.
Fix
The report does not describe a patch, a code change or a vendor response. What it gives is the advisory reference, HI-2022-006, and the note that the Zero Day Initiative acquired both the vulnerability and the exploit. The testbed lists Adobe Acrobat Reader DC 2022.003.20258 while the analysis was done on 2022.001.20085 x86, so the newer build in the testbed is the one to compare against if you want to see whether the trigger still fires; the report itself draws no conclusion from that difference and does not say which build contains the fix.
What the root cause implies should change is clearer than what was actually changed. The defect is that GetRichValueEventProp can free the CAgg objects and their maps while EScript!ESObjectEnum is still walking the object graph, and EScript_ESObjectEnum_CallbackProc keeps using the pointer it was handed through pCAggData after that free. A fix at that level would need one of:
- Lifetime tied to the enumeration. The
CAggobjects created during the walk should not be released until the enumeration that owns them has finished, so that the callback's pointer stays valid for the whole recursion, including every unwinding frame. - Re-entrancy guard on the free path. The free path in
GetRichValueEventPropshould not run while an aggregation of the same value is in progress. The code sets anEventRichValueInProgressmarker before the aggregation, so the state needed to detect this is present. - Invalidation on free. If the objects must be freed mid-walk, the enumeration state should be invalidated at the same time, so the callback cannot be invoked again with a stale pointer.
The JavaScript-visible behaviour that diverts control is the exception from redefining a non-configurable textFont property. That is correct language behaviour and should not be changed; the reader's mistake is letting the resulting error path tear down state that an in-progress operation still references. The try/catch in the PoC does not matter either way, because the diversion happens inside the reader before the script regains control.
The exploitation side also suggests hardening that would raise the cost of the chain even if the lifetime bug survived: the arbitrary write reachable through std::map<unsigned short,CAgg>::insert once the map pointer is attacker-controlled, and the non-CFG instrumented call site sub_20EFAA60 that the exploit uses to bypass Control Flow Guard. Neither is the root cause, but both are what turn a crash into code execution.
Variants to test
The trigger pattern here is not specific to resetForm. It is a general shape: a reader-side API starts a recursive walk over a JavaScript object, the walk can re-enter JavaScript through an accessor the script controls, and the re-entry can make the reader take an error path that releases the objects the walk is holding. Anything that matches that shape is worth trying.
Re-entrant accessors during value aggregation
The core trick is __defineGetter__ on a property that the reader will touch while converting a JavaScript object into an internal value. On any reader that exposes a document object with a Calculate action and a rich value assignment, try installing a getter on a property that the aggregation is likely to enumerate, and have the getter throw or redefine a property that is already non-configurable.
A positive signal is a crash inside the reader's aggregate or value-conversion code rather than inside the JavaScript engine, with the faulting address in a free-ed allocation under page-heap. A second signal is that the crash only appears on the second invocation of the same API call, which is the signature of state installed by the first call changing the path taken by the second.
Property redefinition to force an error path
The PoC relies on Object.defineProperty failing because the target property is already non-configurable. The same diversion can likely be produced by other means: making a property non-writable and then assigning to it, deleting a non-configurable property, or defining a getter that throws on a property the reader reads during conversion.
try { Object.defineProperty(testField, "textFont", { value: this }); } catch(e) { }
A positive result is the same class of crash: a use-after-free in the reader's value layer, confirmed with the page-heap extension showing the faulting address in a free-ed allocation. If the crash moves into the JavaScript engine instead, the error path being taken is a different one and the lifetime bug has not been reached.
Other entry points that run Calculate handlers
resetForm is one way to make the reader run every field's Calculate action. Any other API that triggers field recalculation, formatting or validation is worth testing with the same two-call sequence, because the bug needs the first call to install state and the second to hit the error path. A positive signal is a crash in the same call hierarchy, with AFPDCalculateFields and AFCalculateNthFieldEntry visible in the stack.
Recursive enumeration of other host objects
The aggregation enumerates the doc object because that is what the script assigns to richValue. Other host objects exposed to PDF JavaScript, such as field objects, annotation objects or app-level objects, are enumerated the same way when assigned. Assigning one of those instead of this, with a getter installed on one of its properties, tests whether the same free-during-walk behaviour exists on a different object graph. A positive signal is a crash in EScript_ESObjectEnum_CallbackProc or CAgg::operator[] with a different object at the top of the recursion.
The same pattern in other PDF readers
The Foxit use-after-free covered earlier in the series came from the same fuzzing campaign, which suggests the campaign's inputs are a good starting point for other readers. For each reader that embeds a JavaScript engine and exposes a form API, look for methods that convert a JavaScript value into an internal aggregate and that can re-enter script during the conversion. A positive signal is a crash whose stack shows a conversion routine calling back into the engine and then touching a freed object, which is the same shape as SetRichValueEventProp calling ESObjectEnum and then CAgg::operator[].
JavaScript engine object layout assumptions
The exploitation path depends on the layout of ArrayBuffer, Array and string objects in the engine. On a different engine or a different build, the offsets used here will not hold. The useful test is whether a corrupted length on an ArrayBuffer can be produced at all, and whether the corrupted buffer can be found from script by comparing byteLength against the allocation size:
for (var i=0; i<bufs.length; i++)
{
if (bufs[i].byteLength != ALLOC_SIZE)
{
console.println("[+] corrupted array buffer found at " + i + " : length: " + bufs[i].byteLength + " : buf length: " + bufs.length);
...
}
}
A positive result is a buffer whose reported length differs from the size it was created with, which gives relative out-of-bounds access and is the foundation for every later primitive. If no buffer ever reports a different length, the heap layout work has not placed controlled data where the freed object lands, and the grooming parameters need to change.
64-bit builds
The report explains why the technique does not carry over to 64-bit: spraying cannot place controlled data at predictable addresses, and the string aggregation stops at two consecutive null bytes, so a leaked ArrayBuffer address cannot be carried into the reallocated chunk. A test worth running on a 64-bit build is whether the trigger still crashes at all, which confirms the lifetime bug is present even if it is not exploitable with this method. A positive signal is the same access violation in CAgg::operator[] under page-heap; a negative one is that the second resetForm completes without faulting, which would suggest the lifetime handling was changed.
Hunting notes
Where this class of bug hides
The bug is not in the PDF parser and not in the JavaScript engine. It sits in the glue layer between them: the code that converts a JavaScript value into the reader's internal aggregate type. That layer is worth attention in any product that embeds a scripting engine, because it is where two memory models meet and where ownership is easiest to get wrong.
The specific shape to look for is a conversion routine that walks a script-controlled object recursively and calls back into script during the walk. Here that is SetRichValueEventProp calling EScript!ESObjectEnum, which invokes EScript_ESObjectEnum_CallbackProc for every property, with the callback converting each property into a CAgg. Any accessor the script installs on the object runs inside that walk, so the script gets to execute arbitrary code at a point where the reader is holding pointers into a half-built structure.
The second ingredient is an error path that releases that structure. In this case an exception from redefining a non-configurable property diverts the reader into the free path in GetRichValueEventProp, which frees every CAgg and map built so far while the enumeration is still in progress. Look for conversion code where a failure part-way through triggers cleanup of everything allocated so far, rather than unwinding one level at a time.
The third ingredient is a callback that keeps its pointer across the free. EScript_ESObjectEnum_CallbackProc receives the CAgg through pCAggData and uses it after the free path has run. Because the function is recursive, every unwinding frame repeats the mistake, which is why the crash is so easy to hit once the state is right.
Recon signals
The report does not describe a recon process, but the properties of the bug point to what makes a target interesting:
- An embedded scripting engine with a host-object bridge. Acrobat Reader runs SpiderMonkey through the
EScript.APIplugin, and the bridge between EScript and AcroForm is where the bug lives. Products that expose host objects to script and convert them into native types have the same surface. - APIs that run script implicitly.
resetFormis interesting because it invokesCalculatehandlers on every field without the script asking for it. Any API that triggers user-defined callbacks as a side effect widens the window in which script runs inside a native operation. - Non-standard property machinery. The PoC uses
__defineGetter__andObject.definePropertyto install accessors and to make a property non-configurable. Host objects that allow this kind of redefinition, especially on properties the reader itself reads during conversion, are prime candidates. - A two-call trigger. The bug needs the first
resetFormto install state and the second to hit the error path. When a crash only reproduces on the second or later invocation of the same call, that is a strong hint that the first call changed something the second call depends on. - Page-heap as a diagnostic. Enabling page-heap for the reader process turns a silent reuse into an immediate fault on a free-ed allocation. Running fuzzer findings under page-heap separates genuine lifetime bugs from crashes caused by ordinary heap reuse.
How impact was demonstrated
What it does show is the level of evidence behind the submission: a reproducible crash under page-heap, a !heap trace naming the free stack, a breakpoint trace showing the CAgg allocated for textFont being freed and then accessed again during the richValue enumeration, and a full exploit that reaches shellcode execution, bypasses CFG and restores the reader's state afterwards. The exploit log records the payload executing, and the exploit itself is published in a repository alongside the write-up.
For a hunter working on a similar bug, the lesson is that a use-after-free in a reader's value layer is worth taking past the crash. The report notes that no code path was found to reallocate the freed memory directly, and that the opening came from object sizes that make the reader dereference a sprayed pattern. Demonstrating that the freed object can be steered, that the resulting write can corrupt an ArrayBuffer length, and that the corruption leads to controlled execution is what turns a crash into a report that stands on its own.
What happened, in plain words
Imagine a library where you can hand a book to the librarian and ask her to look something up. She takes the book, walks to the shelf, puts it down for a moment, and then carries on reading from it as if it were still in her hands. If someone else picks the book up while it is on the shelf and swaps its pages, the librarian ends up reading whatever the other person put there. That is the shape of the bug in this article: a program puts a piece of its own memory back on the shelf, then keeps using it, and an attacker gets to decide what sits in that memory instead.
The program is Adobe Acrobat Reader DC, the free desktop application millions of people use to open PDF files. The memory in question is internal bookkeeping the reader creates while it processes a PDF. The attacker is a PDF file itself, because PDFs can carry small programs written in JavaScript, and Acrobat Reader runs that JavaScript when the document is opened. The result, in the hands of the researchers who wrote this report, was remote code execution: the ability to make the reader run code of the attacker's choosing.
The bug has an identifier, CVE-2023-21608. A CVE is a public catalogue number for a security flaw, so that everyone talking about the same flaw uses the same name. The researchers published an advisory for it, HI-2022-006, which is a short formal notice describing the issue. The vulnerability and the exploit were acquired by the Zero Day Initiative (ZDI), an organisation that buys vulnerability research.
This work is the third part of a series about PDF readers. The first part covered an information leak in Adobe Reader, CVE-2021-45067, where a flaw let an attacker read memory they should not see. The second part covered a use-after-free in Foxit PDF Reader, CVE-2022-28672, which the researchers turned into remote code execution. This third part returns to Adobe Reader with the same kind of bug as the Foxit one, a use-after-free, and again takes it all the way to code execution.
The bug was not found by reading the source code, because Acrobat Reader's source is not public. It was found during a fuzzing campaign: an automated process that feeds a program huge numbers of malformed or unusual inputs and watches for crashes. The researchers were aiming this campaign at popular PDF readers. A crash is not yet a vulnerability, but it is a signal that something went wrong in a way the program's authors did not intend, and it gives a starting point for human analysis. That is exactly what happened here: a crash in Acrobat Reader's form-handling code became, after analysis and a lot of engineering, a reliable exploit.
The feature at the centre of it is the JavaScript form API that ships inside Acrobat Reader. PDF documents can embed JavaScript, and the reader exposes a document object to that script, with methods for manipulating form fields. Two of those methods interact in this bug:
resetForm()resets form fields to their default values. As part of that work it runs theCalculateevent on every field that has aCalculatehandler defined.- A field's
Calculatehandler receives aneventobject. Assigning toevent.richValuemakes the reader convert the assigned value into an internal representation.
That internal representation is built from CAgg objects, the reader's internal type for an aggregate value, held in containers keyed by a numeric id derived from a property name. When a JavaScript object such as the document itself is assigned to richValue, the reader walks the object's properties one by one, recursively, and converts each one into a CAgg. The bug lives in how those CAgg objects are managed during that walk: the reader frees them partway through and then keeps using a pointer to one of them.
The report is long because turning that into code execution is not a single trick. It needs an understanding of how the reader stores JavaScript values in memory, a way to place attacker-controlled data where the freed object used to be, a way to corrupt a JavaScript buffer so it can read and write outside its own boundaries, a way to bypass CFG, and finally a way to restore the reader's context afterwards. Each of those steps is explained from scratch in the sections that follow, in the same order as the original research.
The pieces you need to know first
Before any of the crash output or the exploit code makes sense, you need a small vocabulary. None of it requires programming experience, but each term below is used later without explanation, so it is worth reading this section once, slowly, and coming back to it when a term reappears.
A PDF is a file format for documents whose layout is fixed. Unlike a word processor file, which describes text and lets the program decide where to put it, a PDF describes pages, positions, fonts and images so that the document looks the same on any machine that opens it. Internally a PDF is a set of numbered objects. Each object has a number, a type and some content, and the file refers to objects by number. A very small PDF might contain an object describing a page, an object describing a font, and an object describing a form field. This matters here because the proof of concept in this report is built from exactly such objects, and you will see one written out in full later.
JavaScript embedded in a PDF
JavaScript is a programming language that normally runs inside a web browser to make pages interactive. PDF supports embedding JavaScript inside a document, and a PDF reader that supports it will run that script when the document is opened or when certain events happen. This is a legitimate feature: it lets a form add up a column of numbers, validate that a date was entered correctly, or show a warning when a field is left blank. It is also, from a security point of view, a way for a document to run code inside the reader. The script is limited to what the reader chooses to expose to it, but that exposed surface is large, and this report is about a flaw in that surface.
Adobe Acrobat Reader DC
Adobe Acrobat Reader DC is Adobe's free application for opening PDF files. It runs on Windows, macOS and other platforms, and it is one of the most widely installed desktop programs in the world. It supports embedded JavaScript, form fields and a long list of document features. Because it is so widely installed and because it processes files that arrive from strangers by email or download, it is a frequent target for attackers, and a flaw in it that leads to code execution is serious.
Form fields and the Calculate action
A form field is an interactive element in a PDF: a text box where you type your name, a checkbox, a dropdown list. Each field has a name so that scripts can find it, and each field can have actions attached to it. An action is a piece of behaviour that runs when something happens to the field.
The Calculate action is one such behaviour. It runs when the reader needs to recalculate the field's value, for example when another field it depends on changes. A common use is a total field in an invoice: when the user types a quantity, the total field's Calculate action runs and adds up the line items. The Calculate action is written in JavaScript, and when it runs it receives an event object describing what is happening.
resetForm
resetForm() is a method on the document object. It resets form fields back to their default values, as if the user had pressed a "clear form" button. As part of that work, the reader runs the Calculate action on every field that has one, because resetting a field can change values that other fields depend on. That side effect is the doorway into this bug: calling resetForm() causes the reader to run JavaScript that the document author wrote, at a moment when the reader is in the middle of its own internal work.
The event object and richValue
When a Calculate action runs, the script receives an event object. It is a small object with properties describing the event: which field it concerns, what kind of event it is, and so on. One of its properties is richValue. Assigning to event.richValue tells the reader "here is the value of this field, in rich form", where rich means it can carry formatting and structure rather than just plain text. The reader then has to convert whatever you assigned into its own internal representation, and that conversion is where the bug lives.
Use-after-free
A use-after-free is a class of memory bug. Programs ask the operating system for blocks of memory when they need them, and give them back when they are done. Giving a block back is called freeing it. A use-after-free happens when a program frees a block and then carries on using it, reading from it or writing to it, as if it still owned it.
The everyday comparison: you borrow a friend's flat for the weekend, hand the keys back on Sunday, and then let yourself in again on Monday using a copy of the key. The flat is no longer yours. Someone else may have moved in, and whatever you do there now affects them, and whatever they have put there affects you. In a program, the "someone else" is whoever gets that memory block next. If an attacker can arrange for the freed block to be filled with data they control, then the program's later use of that block reads the attacker's data instead of its own. That is the foundation of this entire exploit.
Remote code execution
Remote code execution, usually shortened to RCE, means an attacker can make a program run code of their choosing. "Remote" means the attacker does not need to be sitting at the machine: the code arrives inside a file, a message or a network request. In this report, the code arrives inside a PDF. A victim opens the document, the reader runs the embedded JavaScript, the JavaScript drives the reader into the bug, and the end result is that the attacker's machine code runs on the victim's computer. RCE is the most severe class of software flaw, because it usually means the attacker can do anything the program can do.
Sandbox process
Modern readers do not run all their code with full access to the machine. They split the work into processes and put the risky parts, such as parsing a document from an unknown source, inside a sandbox: a restricted environment where the process can only touch a limited set of resources. If the parser is compromised, the attacker is still trapped inside the sandbox and has to find a second flaw to escape it. The report describes the goal as achieving RCE "in the context of Adobe Acrobat Reader" and in "Adobe Reader's sandbox process". That is already serious, and escaping the sandbox would be a further step that this report does not cover.
Fuzzing campaign
Fuzzing is automated testing by feeding a program large numbers of inputs, many of them malformed, and watching for crashes. A fuzzing campaign is a sustained run of this, often over days or weeks, against a particular target. The researchers here aimed a campaign at popular PDF readers. Fuzzing does not find vulnerabilities by itself; it finds crashes. A crash tells a human researcher that some input drove the program into a state its authors did not anticipate, and the researcher then works out whether that state can be controlled and exploited. That is the path this bug took.
CVE and advisory identifiers
A CVE (Common Vulnerabilities and Exposures) is a public identifier for a specific security flaw, of the form CVE-year-number. It exists so that a vendor, a researcher, a news article and a scanner all refer to the same flaw by the same name. This one is CVE-2023-21608.
An advisory is a short formal notice published about a flaw. It typically names the product, the affected versions, the type of flaw and the fix. The advisory for this issue is HI-2022-006, and the report links to it. The "HI" prefix is the publisher's own numbering scheme, separate from the CVE.
The Zero Day Initiative
The Zero Day Initiative (ZDI) is an organisation that buys vulnerability research from security researchers and passes the details to the affected vendor so the flaw can be fixed. "Zero day" refers to a flaw the vendor does not yet know about, so there are zero days of warning. In this case ZDI acquired both the vulnerability and the exploit.
With those terms in hand, the next section describes the exact software and settings the researchers used, and then the proof of concept itself.
Setup
Before looking at the crash, it helps to know exactly what software the researchers ran it on. Security findings are tied to versions: a bug that crashes one build of a program may be fixed in the next, and a crash that looks identical on two machines can come from different code if the builds differ. The report therefore lists its testbed, the fixed set of hardware and software used for the experiments, so that anyone repeating the work knows what to install.
The testbed listed in the report is:
- OS edition: Windows 10 Pro 20H2 19042.804
- Product: Adobe Acrobat Reader DC 2022.003.20258
- Product URL: https://get.adobe.com/reader/otherversions/
Each line deserves a short explanation.
Windows 10 Pro 20H2 19042.804 is the operating system. "Windows 10 Pro" is the edition, "20H2" is a release name (the second half-yearly update of 2020), and "19042.804" is the exact build number, down to the patch level. The build number matters because Windows itself changes between patches, and the way Windows hands out and reclaims memory can differ slightly between builds. A memory bug that behaves one way on one build can behave another way on the next.
Adobe Acrobat Reader DC 2022.003.20258 is the reader. The version string has three parts: 2022 is the year of the release line, 003 is the quarterly update within that line, and 20258 is the build. This is the version the researchers listed as their testbed, meaning the environment in which the bug was confirmed to exist.
The product URL points to Adobe's page for older versions of the reader. It is there so that a reader of the report can download the same build and reproduce the work. Vendors usually offer only the latest version on their main download page, so a page listing older versions is the practical way to get a specific build.
There is an important detail in the report that is easy to miss. The testbed lists 2022.003.20258, but the report then notes that all analysis and exploitation was performed on a different build: Adobe Acrobat Reader DC 2022.001.20085 x86. So the testbed list and the build actually used for the deep work are not the same. The report does not explain the difference or draw any conclusion from it; it simply states both. When you read crash addresses or offsets later in the report, they belong to 2022.001.20085 x86, not to the testbed build.
Why the 32-bit build matters
The build string ends in x86. That is the name of the family of processors and the instruction set that most desktop computers used before 64-bit became standard, and it is also the name used for a 32-bit build of a program, meaning a build compiled to run in a 32-bit address space.
An address space is the range of memory addresses a program can use. In a 32-bit program, an address is 32 bits long, which gives a maximum of about 4 gigabytes of addressable memory, and in practice the usable range is smaller. In a 64-bit program, addresses are 64 bits long, which allows vastly more memory. That sounds like a pure advantage for 64-bit, and for performance it mostly is, but for exploitation it changes the game in a way that matters here.
The exploit in this report depends on predictable addresses: the attacker needs to place controlled data at an address they can guess in advance, so that when the program later uses a freed pointer, that pointer lands on the attacker's data. In a 32-bit address space, there are few enough possible addresses that spraying lots of data fills a large fraction of the space, and a guessed address is likely to hit. In a 64-bit address space, there are so many possible addresses that spraying cannot cover a meaningful fraction, and guessing becomes impractical. The report says this explicitly later, when it explains why the 64-bit version was not exploited. For now, the point is that the choice of the x86 build is not incidental: the whole exploitation strategy is built around it.
Page-heap
The next setting is page-heap. To understand it, you need to know what a heap is.
A program's memory is divided into regions. One region holds the program's code, another holds global data, and another, called the stack, holds the short-lived data of function calls. The heap is the region where the program asks the operating system for blocks of memory at runtime, whenever it needs to store something whose size is not known in advance. When the program is done with a block, it gives it back, and the allocator, the part of the system that manages the heap, can hand that block to someone else later.
Normally, when a block is freed, the allocator marks it as available but leaves its contents in place. If a buggy program keeps using a freed block, nothing obviously goes wrong: the old data is still there, the program reads it, and the bug stays hidden. That is exactly what makes use-after-free bugs hard to find. The program appears to work, and the flaw only shows up when the allocator happens to reuse the block for something else, at which point the program reads or writes the wrong data and may crash in a confusing place.
Page-heap is a debugging feature that changes this behaviour. When page-heap is enabled for a process, every allocation is placed on its own memory page, the smallest unit of memory the operating system manages, and when the block is freed, the page is marked as inaccessible or filled with a recognisable pattern. Any later access to the freed block then faults immediately, and the debugger stops at the exact instruction that touched it. The everyday comparison: normally, when you throw a letter in the bin, it stays in the bin and you could still fish it out; with page-heap, the bin is sealed and alarmed, and the moment you reach in, the alarm goes off.
The report says page-heap is enabled for AcroRd32.exe. The "32" in the name is the same 32-bit as in x86. Enabling page-heap for that process means every allocation the reader makes is tracked this way, so a use-after-free in the reader faults at the moment of the bad access rather than silently reading stale data.
Page-heap is a diagnostic tool, not a security feature. It does not make the program safer; it makes bugs visible. The report uses it to get a clean crash and a clean stack trace, and later it also uses the non-page-heap behaviour, because the exploit needs the allocator to reuse the freed block with attacker-controlled data, which page-heap prevents. Both views matter, and the report switches between them.
Opening crash.pdf
With page-heap enabled, the researchers open a file called crash.pdf in Acrobat Adobe Reader DC. That file is the proof of concept: a PDF document containing the field and the JavaScript that triggers the bug. Opening it is the whole trigger. There is no special command line, no debugger action needed to cause the crash; the document itself does the work as soon as the reader processes it.
The name crash.pdf is descriptive: it is the file that crashes the reader. The report does not include the file itself in the text, but it does include the two pieces that make it up, the PDF object that defines the field and the JavaScript that drives the bug, and those are shown in the next section.
The reason for opening the file under a debugger rather than just double-clicking it is that a crash on its own tells you very little. Windows will show a dialog saying the program stopped working, and that is all. A debugger is a tool that runs a program under close observation, letting you pause it, inspect its memory and registers, and see exactly which instruction failed and what the call stack looked like at that moment. The report uses WinDbg, Microsoft's debugger for Windows, and the outputs you will see later are WinDbg command results. Without the debugger, the crash would be a dead end; with it, the crash becomes a map of what went wrong inside the reader.
That map is what the next section starts to read.
The proof of concept
A proof of concept, usually shortened to PoC, is the smallest piece of work that demonstrates a bug is real. It is not an exploit: it does not try to take over the program or run code. It just makes the program do the wrong thing, in this case crash, in a way that can be repeated on demand. For a memory bug, a good PoC is worth a great deal, because it turns a vague suspicion into a concrete, reproducible event that can be studied in a debugger.
The PoC here has two parts. The first is a small piece of PDF that defines a form field. The second is a block of JavaScript that manipulates that field and triggers the bug. Both are shown in full in the report, and both are explained line by line below.
The PDF object
The report describes the test case as containing a static text field named testField embedded inside a PDF document. The PDF object that defines it is:
5 0 obj << /Type /Annot /Subtype /Widget /T (testField) /FT /Tx /Rect [0 0 0 0] >>
This is one line of PDF syntax, and it is worth reading slowly because every part has a meaning.
5 0 objstarts the definition of object number 5. PDF files are built from numbered objects, and this is the fifth one in the file. The number is how other parts of the file refer to this object.<<and>>open and close a dictionary, which is PDF's name for a set of key and value pairs, like a small table. Everything between them describes the object./Type /Annotsays the object is an annotation. An annotation is something attached to a page that is not part of the page's printed content: a comment, a link, a form field, a stamp./Subtype /Widgetnarrows it down: this annotation is a widget, which is PDF's term for the on-screen control that represents a form field. So this object is the visible control for a field./T (testField)gives the field its name,testField. The/Tkey stands for title, and the value in parentheses is the name that scripts use to find the field. This is the name that appears in the JavaScript asthis.getField("testField")./FT /Txsets the field type to text./FTstands for field type, and/Txmeans text, so this is a text box rather than a checkbox or a list./Rect [0 0 0 0]gives the field's rectangle, the area on the page it occupies, as four numbers: left, bottom, right and top. All four are zero, so the field has no visible size. It exists in the document's structure but takes up no space on the page, which is convenient for a PoC: the document looks like a blank page, and the field is there only for the script to use.
The report does not show the rest of the PDF, only this object and the JavaScript. That is enough to understand the trigger, because the bug does not depend on anything else in the document.
The JavaScript
The report then gives the document-level JavaScript that triggers the bug:
var testField = this.getField("testField");
testField.richText = true;
testField.setAction("Calculate", "calculateCallback()");
try { this.resetForm(); } catch (e) {}
try { this.resetForm(); } catch (e) {} // bug is triggered during this resetForm call
function calculateCallback()
{
event.__defineGetter__("target", getterFunc);
event.richValue = this;
}
function getterFunc()
{
try { Object.defineProperty(testField, "textFont", { value: this }); } catch(e) { }
}
This is JavaScript, the same language that runs in web pages. In a PDF, document-level JavaScript runs when the document is opened, in a context where this refers to the document object. The document object is the reader's handle on the PDF: it has methods for finding fields, resetting forms, printing, and much more. The script is short, but each line does something specific, and the order matters.
Line 1: finding the field
var testField = this.getField("testField");
var testField declares a variable, a named storage slot, called testField. this is the document object. this.getField("testField") asks the document for the field whose name is testField, which is the field defined by the PDF object above. The result, the reader's internal object representing that field, is stored in the variable.
Why this line: everything that follows needs a handle on the field. The script cannot refer to the field by name later without asking for it once and keeping the result. This is the same pattern as looking up a contact in an address book and writing down the number, rather than looking it up again every time you want to call.
Line 2: turning on rich text
testField.richText = true;
richText is a property of the field. Setting it to true tells the reader that this field holds rich text, meaning text with formatting such as bold, italic, font changes and colours, rather than plain characters. Rich text is stored in a structured form, not as a simple string, and that structure is what makes the richValue property meaningful later.
Why this line: the bug is in the handling of richValue, and richValue only carries structured content when the field is a rich text field. Without this line, the reader would treat the field's value as plain text and the code path that contains the bug would not be reached.
Line 3: registering the Calculate handler
testField.setAction("Calculate", "calculateCallback()");
setAction attaches an action to the field. The first argument, "Calculate", names the event the action responds to: the Calculate event, which the reader fires when it needs to recalculate the field's value. The second argument, "calculateCallback()", is the JavaScript to run when that event fires. It is given as a string, a piece of text containing a function call, and the reader will evaluate that string when the event happens.
Why this line: the bug is triggered from inside a Calculate handler. Without a handler registered, resetForm would have nothing to run, and the bug would never be reached. The handler is named calculateCallback, and the function of that name is defined further down in the script.
Lines 5 and 6: the two resetForm calls
try { this.resetForm(); } catch (e) {}
try { this.resetForm(); } catch (e) {} // bug is triggered during this resetForm call
this.resetForm() calls the document's resetForm method, which resets form fields to their default values. As explained earlier, that method also runs the Calculate action on every field that has one, so each call runs calculateCallback.
The calls are wrapped in try { ... } catch (e) { }. A try/catch block is JavaScript's way of handling errors. The code in the try part runs normally. If it throws an exception, meaning it hits an error and stops, control jumps to the catch part instead of the whole script aborting. The catch (e) receives the error object in a variable named e, and the empty braces {} mean "do nothing with it". So the script says: try to reset the form, and if that fails, ignore the failure and carry on.
Why the try/catch: the researchers expect these calls to throw. The bug itself involves an exception being raised inside the reader, and the script needs to survive that exception so that the second call can happen. If the first call's exception were allowed to propagate, the script would stop and the second call would never run.
Why two calls: this is the single most important detail in the PoC, and the report's root cause analysis explains it. The first call installs state that the second call depends on. Specifically, during the first call, getterFunc runs and redefines the field's textFont property in a way that makes it non-configurable, meaning it can no longer be redefined. During the second call, getterFunc runs again and tries the same redefinition, which now fails and raises an exception. That exception diverts the reader down a different code path, the one that frees the internal objects while they are still in use. So the first call is setup and the second call is the trigger. The comment in the code marks the second line as the one where the bug fires.
The Calculate handler
function calculateCallback()
{
event.__defineGetter__("target", getterFunc);
event.richValue = this;
}
function calculateCallback() defines a function, a named block of code that can be called later. This is the function whose name was passed to setAction on line 3, so it runs whenever the Calculate event fires, which is during each resetForm call.
Inside the function, event is a variable the reader provides automatically when a Calculate handler runs. It is the event object, describing the event: which field it concerns, what kind of event it is, and so on. The script does not declare it; the reader puts it there.
The first line inside the function:
event.__defineGetter__("target", getterFunc);
__defineGetter__ is a method that exists on JavaScript objects. It takes a property name and a function, and it installs that function as a getter for the property. A getter is a function that runs whenever someone reads the property, instead of the property simply returning a stored value. So after this line, whenever anything reads event.target, JavaScript does not return a stored value; it calls getterFunc and uses whatever that function returns.
Why this line: the reader's own code reads event.target during the aggregation that follows. By replacing target with a getter, the script arranges for its own function, getterFunc, to run at that exact moment, in the middle of the reader's internal work. This is the re-entry: the reader is walking through the event object's properties, and one of those properties now runs attacker-supplied code.
The second line inside the function:
event.richValue = this;
This assigns the document object, this, to the event's richValue property. As explained earlier, richValue is the field's value in rich form, and assigning to it makes the reader convert the assigned value into its internal representation. Because the assigned value is the document object, a large, complex object with many properties and methods, the conversion becomes a recursive walk over all of them. That walk is where the CAgg objects are created, and where the bug eventually fires.
Why this line: it starts the aggregation. Without an assignment to richValue, the reader would have nothing to convert and the vulnerable code would not run. The choice of this, the document object, is deliberate: it is a big object with many properties, so the walk is long and the window for the getter to run is wide.
The getter
function getterFunc()
{
try { Object.defineProperty(testField, "textFont", { value: this }); } catch(e) { }
}
function getterFunc() defines the function that was installed as the getter for event.target. It runs whenever the reader reads event.target during the aggregation.
Inside, Object.defineProperty(testField, "textFont", { value: this }) is a standard JavaScript function that defines or redefines a property on an object. It takes three arguments: the object, here testField; the property name, here "textFont"; and a descriptor object describing the property. The descriptor here is { value: this }, which says the property's value should be the document object.
textFont is the field's font property, the one that says which typeface the field's text uses. Redefining it to be the document object is nonsense from a formatting point of view: a font is not a document. But the point is not to produce a sensible font. The point is to change the property in a way that has side effects inside the reader, and to do it at a moment when the reader is in the middle of its own work.
The call is wrapped in try { ... } catch(e) { } for the same reason as the resetForm calls: the researchers expect it to fail on the second run, and they want the script to survive the failure. On the first resetForm, the redefinition succeeds. On the second, it fails because the property is now non-configurable, and the exception that results is what diverts the reader into the free path. The catch swallows the exception from the script's point of view, but by then the damage inside the reader has already been done.
What the PoC achieves
Put together, the PoC does the following, in order:
- It finds the field named
testField. - It makes the field a rich text field, so that
richValuecarries structured content. - It registers
calculateCallbackas the field's Calculate action. - It calls
resetFormfor the first time. The reader runscalculateCallback, which installsgetterFuncas the getter forevent.targetand assigns the document object toevent.richValue. The reader begins walking the document object's properties, and when it readstarget,getterFuncruns and redefinestextFontwith the document object as its value, making the property non-configurable. - It calls
resetFormfor the second time. The reader runscalculateCallbackagain, installs the getter again, and assigns the document object torichValueagain. The walk begins again, and when it readstarget,getterFuncruns again and tries to redefinetextFont. This time the redefinition fails because the property is non-configurable, and the exception diverts the reader into the code path that frees the internalCAggobjects while the walk is still in progress. - The walk continues using a pointer to a
CAggthat has just been freed, and the reader crashes.
The PoC stops at step 6. It produces a crash, nothing more. Turning that crash into code execution is the work of the rest of the report, and it starts with reading the crash in a debugger.
Why this shape of PoC is useful
A PoC that crashes reliably is the foundation of everything that follows. It gives the researchers a fixed point to study: every time they run it, the same thing happens, and they can set breakpoints, inspect memory and step through the code at their leisure. It also gives them a way to check their understanding. If they think the bug is caused by the non-configurable property, they can change the PoC to make the property configurable and see whether the crash goes away. If they think the free happens during the second call, they can remove the second call and see whether the crash disappears. The PoC is a tool for asking the reader questions, and the answers shape the root cause analysis.
The next section reads the crash itself: what the debugger shows when the PoC runs, and what each part of that output means.
Finding it
The stack trace
A crash on its own tells you almost nothing. The debugger stops, shows you a register dump, and that is it: one instruction failed, at one address, and you have no idea how the program got there. The stack trace is what turns that single moment into a story. It is a list of the functions that were running when the crash happened, from the innermost (the one that failed) outwards to the outermost (the one that started the whole chain of calls).
To understand why a stack trace exists at all, you need to know what the stack is. Every time a program calls a function, it needs somewhere to keep that function's local variables and the address it should return to when the function finishes. It puts that information on the stack, a region of memory that grows and shrinks as functions are called and return. When function A calls function B, and B calls C, the stack holds three layers, one per function, each pointing back to the one below it. A stack trace walks those layers and prints the name of each function, so you can see the chain of calls that led to the crash. The everyday comparison: a stack trace is like the list of people who passed a message along before it arrived at the wrong desk. Each layer says "I was running, and I called the one above me".
The report captures the stack trace with the WinDbg command kb, which stands for "call stack with arguments". The output is long, and it is printed as a single block of text. Here it is exactly as the report gives it:
That is a lot of text, so it is worth explaining how to read it before explaining what it says.
Each line is one frame, one layer of the stack. The number at the start of the line, 00, 01, 02 and so on, is the frame index. Frame 00 is the innermost, the function that was actually running when the crash happened. Frame 01 is the function that called it, frame 02 the function that called that, and so on outwards. The last line, frame 28, is the outermost function in the chain.
After the index come several columns of numbers. ChildEBP is a pointer into the stack, the address of the frame's own data. RetAddr is the return address, the address the program will jump back to when this function finishes. Args to Child are the arguments that were passed to the function in the frame above. None of these numbers matter for understanding the bug, but they are what the debugger uses to walk from one frame to the next, and they are printed because they help when you are stepping through the code yourself.
The last column is the important one. It gives the module and the function that the frame belongs to, plus an offset. The module is the name before the exclamation mark: AcroForm, EScript, AcroRd32. Each of those is a separate file loaded into the reader's memory. AcroForm is the module that handles forms, EScript is the module that handles JavaScript, and AcroRd32 is the main reader executable. The function name comes after the exclamation mark, and the +0xe or +0x30 after it is the offset into that function, telling you roughly how far into the function's code the program was. The offset is useful because it tells you the program was not at the very start of the function but somewhere inside it.
There is also a warning in the middle of the output:
WARNING: Stack unwind information not available. Following frames may be wrong.
This is the debugger being honest. To walk the stack reliably, it needs unwind information, a table that tells it how each function lays out its frame. Some functions are compiled without that table, or the table is not available for that build, so the debugger has to guess for the frames after the warning. The frames before the warning are reliable; the ones after it are probably right but could be off by a frame. In this trace the warning appears after frame 03, so frames 04 onwards are the ones the debugger is less sure about. That does not stop the trace from being useful, because the pattern is clear enough to read.
The report tells you to read the trace from the bottom up, and that is the right way to do it. The bottom of the stack is where the story starts: the outermost function is the one that began the whole chain of calls. Reading upwards, each frame is a function called by the one below it, until you reach the crash at the top. So let us start at frame 28 and work upwards.
Frame 28: resetFormHandler
AcroForm!resetFormHandler is the function that handles the resetForm call from JavaScript. When the script calls this.resetForm(), the reader's JavaScript engine hands control to this handler, which is the entry point into the form-resetting code. The +0x5fc offset says the program was well inside the function, which makes sense: the handler has already done some work and is now calling into the next layer.
Why this frame matters: it confirms that the crash happened during a resetForm call, exactly as the PoC intends. If the trace had started somewhere else, the PoC would not be doing what the researchers thought.
Frame 27: ResetForm
AcroForm!ResetForm is the function that does the actual resetting. The signature in the trace, (_t_PDDoc *, OPAQUE_64_BITS, unsigned short), tells you what it takes as arguments: a pointer to a document structure, a flag, and a small integer. The handler in frame 28 called this function to do the work. The +0x477 offset says the program was deep inside it.
Why this frame matters: it shows the reset is in progress. The function has not finished; it is still working through the fields.
Frame 26: AFPDCalculateFields
AcroForm!AFPDCalculateFields is the function that calculates the values of all the fields. As explained earlier, resetForm runs the Calculate action on every field that has one, and this is the function that drives that. It is the "for each field, run its Calculate action" loop.
Why this frame matters: it shows that the reset has reached the stage where it runs Calculate handlers. That is the stage the PoC needs, because the bug is triggered from inside a Calculate handler.
Frame 25: AFPDCalculateFields__internal
AcroForm!AFPDCalculateFields__internal is the internal worker behind the function in frame 26. The public function does some setup and then calls this one to do the per-field work. The __internal suffix is a naming convention: it marks a function that is not meant to be called from outside the module.
Why this frame matters: it is one more layer of the same operation, and it shows the program is still inside the field-calculation loop.
Frame 24: AFCalculateNthFieldEntry_x
24 04f6b03c 6c543270 1f2c0bd0 5135cfa0 00000000 AcroForm!AFCalculateNthFieldEntry_x+0x4b8
AcroForm!AFCalculateNthFieldEntry_x is the function that calculates one specific field, the "nth" field, meaning the one at a particular position in the list. The _x suffix is another naming convention, marking a variant of the function. This is the function that actually runs the Calculate action for the field the loop has reached.
Why this frame matters: this is the point where the reader stops doing its own bookkeeping and starts running the document's JavaScript. The next frame up is the JavaScript execution.
Frame 23: AcroRd32!DllCanUnloadNow+0xa479f
23 04f6af58 6c543fd4 1f2c0bd0 00000000 49cf4fc0 AcroRd32!DllCanUnloadNow+0xa479f
This frame is labelled AcroRd32!DllCanUnloadNow+0xa479f, which looks odd. DllCanUnloadNow is a standard Windows function that a module exports to say whether it can be unloaded from memory. It has nothing to do with running JavaScript. The +0xa479f offset is enormous, far larger than the function itself, which means the debugger has no symbol for the function that is actually running here and has picked the nearest exported name it knows. The real function is some internal part of the reader executable that sits between the form code and the JavaScript engine.
Why this frame matters: it is a bridge. The form code in AcroForm has called into the reader executable, which is about to call into the JavaScript engine. The misleading name is a reminder that debugger output is only as good as the symbols available, and that a strange-looking frame name often means "the debugger does not know what this is".
Frame 22: ESExecuteScriptWithEvent
22 04f6af30 692fcbdf 1f2c0bd0 390b4fb8 49cf4fc0 EScript!ESExecuteScriptWithEvent+0x4a3
EScript!ESExecuteScriptWithEvent is the function that runs a piece of JavaScript in response to an event. The event here is the Calculate event. This is the handover point: the form code says "run this script for this event", and this function takes over.
Why this frame matters: it marks the boundary between the reader's native code and the JavaScript engine. Everything above this frame is JavaScript execution; everything below is the reader's own form handling.
Frames 21 to 15: the JavaScript engine
These seven frames are all inside EScript, the JavaScript engine module. Their names are a mix of readable and unreadable. AESEvaluateScript and ESExecScript are named functions; the sub_100389D2 style names are functions the debugger has no symbol for, so it has invented a name from the function's address. The sub_ prefix means "subroutine at this address".
Reading them in order from the bottom up: ESExecScript is the entry point that runs a script, AESEvaluateScript is a wrapper around it, and the sub_ functions are the internal machinery of the JavaScript engine as it parses and starts to execute the script. Frame 15, EScript!sub_1003F620, is the last one before the engine calls back into the reader's form code, which is the next frame up.
Why these frames matter: they show that the crash happened while JavaScript was running, not while the reader was parsing the PDF. The script is the thing that drove the reader into the bug.
Frame 14: SetRichValueEventProp
14 04f6a4c8 6bddf79b 48cf2fb8 45230ff0 47cf6ff0 AcroForm!SetRichValueEventProp+0x1f5
AcroForm!SetRichValueEventProp is the function that handles the assignment to event.richValue. When the script executes event.richValue = this, the JavaScript engine calls into this function to store the value. As the report explains, this is where the aggregation starts: the function takes the assigned value, which is the document object, and begins converting it into the reader's internal representation.
Why this frame matters: this is the function named in the report's root cause analysis as the place where the aggregation begins. Everything above it in the trace is the consequence of this function's work.
Frame 13: ESValToCAggWrapper
13 04f6a46c 6c513b35 04f6afa8 47cf6ff0 00000000 AcroForm!ESValToCAggWrapper+0x1e
AcroForm!ESValToCAggWrapper is a thin wrapper around the conversion function. "ESVal" means a value from the JavaScript engine (EScript value), and "CAgg" is the reader's aggregate type. So the name means "convert an EScript value into a CAgg". The wrapper does some setup and then calls the real conversion function, which is the next frame up.
Why this frame matters: it confirms the direction of the conversion. The reader is taking a JavaScript value and turning it into its own internal type, which is exactly the operation that creates the CAgg objects.
Frame 12: ESValToCAgg
12 04f6a42c 6c552aea 04f6afa8 47cf6ff0 00000000 AcroForm!ESValToCAgg(CAgg &, _s_ESValRec *, unsigned short)+0xd6
AcroForm!ESValToCAgg is the real conversion function. Its signature, (CAgg &, _s_ESValRec *, unsigned short), says it takes a reference to a CAgg to fill in, a pointer to the source value, and a small integer. This is the function that does the work of turning one JavaScript value into one CAgg.
Why this frame matters: it is the first of the repeating group. The conversion of a single property happens here, and then the function calls back into the enumeration to handle the property's own contents, which is the next frame up.
Frames 11 to 8: the first repetition of the four-frame group
Here the pattern starts to repeat. Frame 11, ESValToCAgg_internal, is the internal worker behind the conversion. Frame 10 is another of those misleading AcroRd32!DllCanUnloadNow frames, a bridge between the form code and the JavaScript engine. Frame 09, EScript!ESObjectEnumWrapper, is a wrapper around the enumeration function. Frame 08, EScript!ESObjectEnum, is the enumeration function itself: the one that walks an object's properties and calls a callback for each one.
Why this group matters: it is the recursion. ESValToCAgg converted one property, and to do so it had to enumerate that property's own contents, which meant calling ESObjectEnum again. Each level of the recursion adds another group of frames.
Frames 7 to 4: the second repetition
07 04f6a228 6bdfd922 503d4fb8 45970ff0 46ed4ff0 AcroForm!EScript_ESObjectEnum_CallbackProc+0x36
06 04f6a20c 6c552a56 420fefd0 46ed4ff0 00000000 AcroForm!ESValToCAgg(CAgg &, _s_ESValRec *, unsigned short)+0xd6
05 04f6a1e4 6c552c3f 420fefd0 43a38fb8 00000000 AcroForm!ESValToCAgg_internal+0x447
04 04f6a19c 6c55298c 43a38fb8 6c552a20 04f6a1c8 AcroRd32!DllCanUnloadNow+0xa6553
The group repeats, but with a new frame at the top: AcroForm!EScript_ESObjectEnum_CallbackProc. This is the callback that the enumeration calls for each property. It receives the property's details from the JavaScript engine and converts them into a CAgg. The report names this function as the one that keeps using the freed pointer.
Why this group matters: it shows the callback running at a deeper level of the recursion. The enumeration has descended into a property, and the callback is now converting that property's contents.
Frames 3 to 0: the innermost group and the crash
03 04f6a184 692fe993 43a38fb8 6c552a20 04f6a1c8 EScript!ESObjectEnumWrapper+0x13
02 04f6a16c 6bdfd803 43a38fb8 6c552a20 04f6a1c8 EScript!ESObjectEnum+0xc3
01 04f6a118 6bdfd922 43a38fb8 527e4ff0 408bcff0 AcroForm!EScript_ESObjectEnum_CallbackProc+0x30
00 04f6a0fc 6c552a50 00001742 408bcff0 00000000 AcroForm!CAgg::operator[](unsigned short)+0xe
The pattern repeats one more time, and then frame 00 is the crash itself: AcroForm!CAgg::operator[](unsigned short)+0xe. This is the function that the register dump showed faulting. It was called by the callback in frame 01, which was called by the enumeration in frame 02, and so on.
Why this frame matters: it is the innermost point, the function that touched the freed memory. The +0xe offset matches the faulting instruction from the register dump, which is how you know the two outputs describe the same event.
What the whole trace says
Read as a story, the trace says this:
- The script called
resetForm, which enteredresetFormHandler(frame 28) and thenResetForm(frame 27). - The reset started calculating fields, through
AFPDCalculateFields(frames 26 and 25) andAFCalculateNthFieldEntry_x(frame 24). - That reached the JavaScript engine through
ESExecuteScriptWithEvent(frame 22), and the engine ran the Calculate handler (frames 21 to 15). - The handler assigned to
event.richValue, which enteredSetRichValueEventProp(frame 14) and started the conversion intoCAggobjects (frames 13 and 12). - The conversion enumerated the document object's properties, and for each property it called back into the form code (frames 11 to 8), which converted that property (frames 7 to 4), which enumerated its properties in turn (frames 3 to 1), until the innermost conversion called
CAgg::operator[](frame 0) and crashed.
The repeating groups of four frames are the signature of the recursion. Each group is one level of the walk: enumerate a property, call the callback, convert the property, descend into its contents. The report notes that the callback function is recursive, so the problem repeats at every level, and the stack trace shows exactly that: the same four frames, over and over, getting deeper until the crash.
There is one more thing the trace tells you, and it is the clue the report draws attention to. The crash is in AcroForm, the form-handling module, not in EScript, the JavaScript engine. If the bug were in the JavaScript engine, the innermost frame would be an EScript function. The form code is the part that fails, which points the researchers at the conversion and lifetime handling of CAgg objects rather than at the script engine. That is why the next step is to ask what state the memory at the faulting address is in, which is the subject of the next section.
Verifying the free
The stack trace tells you where the crash happened, but not why. The faulting instruction was a read from the address in the edi register, and the register dump showed that address as 420fefd0. The next question is what that address is. Is it a valid block of memory that happens to contain nonsense? Is it memory that was never allocated at all? Or is it memory that was allocated, used, and then given back?
WinDbg has an extension for exactly this question. The command !ext.heap -p -a @edi asks the page-heap extension to look up the address currently held in edi and report what the heap knows about it. The -p flag means "use page-heap information", and -a means "analyse this address". The @edi is WinDbg's way of writing "the value of the edi register". The report gives the output exactly as follows:
0:000> !ext.heap -p -a @edi address 420fefd0 found in _DPH_HEAP_ROOT @ 7831000 in free-ed allocation ( DPH_HEAP_BLOCK: VirtAddr VirtSize) 372134ac: 420fe000 2000 6e44ab02 verifier!AVrfDebugPageHeapFree+0x000000c2 770af766 ntdll!RtlDebugFreeHeap+0x0000003e 770668ae ntdll!RtlpFreeHeap+0x0004e0ce 770562ed ntdll!RtlpFreeHeapInternal+0x00000783 77018786 ntdll!RtlFreeHeap+0x00000046 755d3c9b ucrtbase!_free_base+0x0000001b 755d3c68 ucrtbase!free+0x00000018 6c2e7a56 AcroForm!operator delete(void *)+0x0000000b 6c555f05 AcroForm!sub_20AD5ECD+0x00000038 6c555e5f AcroForm!sub_20AD5E3B+0x00000024 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e1b AcroForm!sub_20AD5DE9+0x00000032 6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0 6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7 6c5576c0 AcroForm!CAgg::convert(CAgg::CAggType)+0x00000045 6c556d10 AcroForm!sub_20AD6CDD+0x00000033 6c555efd AcroForm!sub_20AD5ECD+0x00000030 6c555e5f AcroForm!sub_20AD5E3B+0x00000024 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e54 AcroForm!sub_20AD5E3B+0x00000019 6c555e1b AcroForm!sub_20AD5DE9+0x00000032 6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0 6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7 6c55766d AcroForm!sub_20AD75F2+0x0000007b 6c551b9e AcroForm!CAggConvertToESValType(CAgg &)+0x0000001f 6c551be0 AcroForm!CAggToESVal(_s_ESValRec *, CAgg &)+0x0000003d 6c5131ce AcroForm!GetRichValueEventProp+0x0000011e 6bdde176 EScript!sub_1003DF10+0x00000266 6bde306d EScript!sub_10042FE8+0x00000085 6bdb50fd EScript!sub_10014B57+0x000005a6 6bdb4b4a EScript!sub_10014B17+0x00000033 6bdddcd2 EScript!sub_1003DC6A+0x00000068
This output has two parts, and both matter.
The first part: what the address is
The first line of the output is the answer to the question:
address 420fefd0 found in _DPH_HEAP_ROOT @ 7831000 in free-ed allocation
Read it piece by piece.
address 420fefd0is the address that was looked up, the one fromedi.found in _DPH_HEAP_ROOT @ 7831000says the address belongs to a page-heap root, a bookkeeping structure that the page-heap system keeps for the process. The_DPH_prefix stands for Debug Page Heap, which is the internal name of the page-heap feature. The@ 7831000is the address of that bookkeeping structure, which is not important for understanding the bug.in free-ed allocationis the key phrase. It says the address lies inside a block of memory that was allocated at some point and has since been freed. The odd spelling "free-ed" is how the page-heap extension writes it, to distinguish "this block is currently free" from the word "freed" used in other contexts. In plain words: the memory the reader is trying to read is memory the reader has already given back.
The next line gives the details of the block:
( DPH_HEAP_BLOCK: VirtAddr VirtSize) 372134ac: 420fe000 2000
This is a small table with one row. DPH_HEAP_BLOCK is the identifier of the block's bookkeeping entry, 372134ac. VirtAddr is the starting address of the block, 420fe000. VirtSize is its size, 2000 in hexadecimal, which is 8192 bytes. The address that faulted, 420fefd0, sits inside that range: it is greater than 420fe000 and less than 420fe000 + 2000. So the faulting address is not some random number; it is a specific offset inside a specific block that the reader allocated and then freed.
Why this matters: it confirms the hypothesis from the stack trace. The crash is not a wild pointer into unmapped memory, and it is not a simple null dereference. It is a read from a block that the reader itself freed earlier. That is the definition of a use-after-free, and the page-heap extension has just named it.
The second part: who freed it
The rest of the output is a free stack, the stack trace captured at the moment the block was freed. It is printed in the same format as the crash stack trace, innermost frame first, and it answers the question "which code gave this memory back?".
The top of the free stack is the page-heap machinery itself:
6e44ab02 verifier!AVrfDebugPageHeapFree+0x000000c2
770af766 ntdll!RtlDebugFreeHeap+0x0000003e
770668ae ntdll!RtlpFreeHeap+0x0004e0ce
770562ed ntdll!RtlpFreeHeapInternal+0x00000783
77018786 ntdll!RtlFreeHeap+0x00000046
755d3c9b ucrtbase!_free_base+0x0000001b
755d3c68 ucrtbase!free+0x00000018
These frames are the plumbing of memory management. verifier!AVrfDebugPageHeapFree is the page-heap verifier recording the free. ntdll!RtlDebugFreeHeap, ntdll!RtlpFreeHeap, ntdll!RtlpFreeHeapInternal and ntdll!RtlFreeHeap are the Windows heap manager's internal functions, in ntdll, the low-level Windows library. ucrtbase!_free_base and ucrtbase!free are the C runtime's free function, the standard library call that a program uses to give memory back. So the chain is: some code called free, which went down through the C runtime and into the Windows heap manager, which handed the block back to the page-heap verifier.
None of that tells you which code called free. For that, you keep reading down the stack, past the plumbing and into the reader's own modules:
6c2e7a56 AcroForm!operator delete(void *)+0x0000000b
6c555f05 AcroForm!sub_20AD5ECD+0x00000038
6c555e5f AcroForm!sub_20AD5E3B+0x00000024
6c555e54 AcroForm!sub_20AD5E3B+0x00000019
6c555e1b AcroForm!sub_20AD5DE9+0x00000032
6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0
6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7
6c5576c0 AcroForm!CAgg::convert(CAgg::CAggType)+0x00000045
6c556d10 AcroForm!sub_20AD6CDD+0x00000033
6c555efd AcroForm!sub_20AD5ECD+0x00000030
6c555e5f AcroForm!sub_20AD5E3B+0x00000024
6c555e54 AcroForm!sub_20AD5E3B+0x00000019
6c555e54 AcroForm!sub_20AD5E3B+0x00000019
6c555e1b AcroForm!sub_20AD5DE9+0x00000032
6c557abf AcroForm!CAgg::convertASAtommap(bool (&)[27])+0x000002e0
6c557559 AcroForm!CAgg::convert(bool (&)[27])+0x000000e7
6c55766d AcroForm!sub_20AD75F2+0x0000007b
6c551b9e AcroForm!CAggConvertToESValType(CAgg &)+0x0000001f
6c551be0 AcroForm!CAggToESVal(_s_ESValRec *, CAgg &)+0x0000003d
6c5131ce AcroForm!GetRichValueEventProp+0x0000011e
Read from the bottom up, this is the story of the free.
AcroForm!GetRichValueEventProp is the function that handles reading the richValue property. It is the counterpart of SetRichValueEventProp from the crash stack: that one handled the assignment, this one handles the read. The report's root cause analysis identifies this function as the place where the free path runs. So the free begins here, in the same richValue handling that is currently enumerating properties.
AcroForm!CAggToESVal is the function that converts a CAgg back into a JavaScript value. Its signature, (_s_ESValRec *, CAgg &), says it takes a destination value and a reference to a CAgg. The name is the reverse of ESValToCAgg from the crash stack: that one went from JavaScript to CAgg, this one goes from CAgg to JavaScript. The conversion is happening in the middle of the enumeration, which is why the free is so dangerous: the enumeration is still using the CAgg objects that this conversion is about to release.
AcroForm!CAggConvertToESValType is a helper that works out which JavaScript type a CAgg should become. It is part of the same conversion.
AcroForm!sub_20AD75F2 is an unnamed function, one the debugger has no symbol for. It sits between the conversion helper and the CAgg::convert calls.
AcroForm!CAgg::convert(bool (&)[27]) is a method on CAgg that converts the aggregate from one internal form to another. The argument, bool (&)[27], is a reference to an array of 27 booleans, which is a set of flags telling the conversion which types to consider. The 27 is not a magic number for the bug; it is the number of aggregate types the reader knows about.
AcroForm!CAgg::convertASAtommap(bool (&)[27]) is a more specific conversion, one that deals with an atom map. An atom is a small integer that stands for a string. The reader uses atoms to identify property names efficiently: instead of comparing strings like "textFont" every time, it converts the string to an atom once and compares integers thereafter. An atom map is a table that maps atoms to values. Converting a CAgg that contains an atom map means walking that map and converting each entry, and that is where the actual delete calls happen.
The frames between CAgg::convert and operator delete repeat in a pattern:
AcroForm!sub_20AD6CDD
AcroForm!sub_20AD5ECD
AcroForm!sub_20AD5E3B
AcroForm!sub_20AD5E3B
AcroForm!sub_20AD5DE9
AcroForm!CAgg::convertASAtommap
AcroForm!CAgg::convert
This is the recursion again, but this time on the free side. CAgg::convert calls convertASAtommap, which walks the map and for each entry calls back into CAgg::convert for the entry's value, which calls convertASAtommap again, and so on. Each level eventually reaches sub_20AD5DE9, sub_20AD5E3B, sub_20AD5ECD and finally AcroForm!operator delete(void *), the C++ operator that frees an object. So the free is not a single call; it is a recursive teardown of the whole aggregate structure, freeing every CAgg and every map inside it.
AcroForm!operator delete(void *) is the C++ delete operator. In C++, when an object is created with new, it is destroyed with delete, which calls the object's destructor and then gives its memory back. This frame is the point where the CAgg object's memory is actually released, and it is the frame immediately above ucrtbase!free in the stack. So the chain is complete: GetRichValueEventProp decided to convert a CAgg back to a JavaScript value, the conversion walked the aggregate recursively, and the teardown at the end called operator delete, which called free, which handed the block back to the heap.
The bottom of the free stack is the JavaScript engine:
6bdde176 EScript!sub_1003DF10+0x00000266
6bde306d EScript!sub_10042FE8+0x00000085
6bdb50fd EScript!sub_10014B57+0x000005a6
6bdb4b4a EScript!sub_10014B17+0x00000033
6bdddcd2 EScript!sub_1003DC6A+0x00000068
These are unnamed functions inside EScript, the JavaScript engine. They are the engine's own machinery for reading a property: the engine asked for richValue, the reader's property handler ran, and the free happened inside that handler. The engine is not at fault; it simply asked a question, and the answer involved freeing memory the engine was still using.
What the two outputs together prove
Put the crash stack and the free stack side by side, and the bug becomes clear.
The crash stack showed the reader enumerating the document object's properties, converting each one into a CAgg, and crashing in CAgg::operator[] when it tried to use one of those CAgg objects. The free stack shows that the same richValue handling, in GetRichValueEventProp, freed those very CAgg objects through CAggToESVal and the recursive CAgg::convert teardown. The block that faulted, 420fefd0, is one of the freed CAgg objects, and the page-heap extension confirms it is in a free-ed allocation.
So the sequence is:
- The script assigns the document object to
event.richValue. - The reader starts enumerating the document object's properties, creating a
CAggfor each one. - During the enumeration, something causes the reader to take the free path in
GetRichValueEventProp. - That path converts the
CAggobjects back to JavaScript values, and the conversion's teardown frees everyCAggand every map built so far. - The enumeration continues, still holding pointers to the
CAggobjects it created. - The next use of one of those pointers, in
CAgg::operator[], reads freed memory and crashes.
The report's conclusion is exactly this: the same richValue handling that is enumerating properties also frees the CAgg objects, and the enumeration keeps using a pointer to one of them afterwards. That is a use-after-free, and the crash is the first visible symptom of it.
Why this matters for the rest of the work: knowing that the freed block is a CAgg object tells the researchers what they need to control. If they can arrange for the freed block to be filled with data of their choosing before the enumeration uses it again, then the reader will read their data instead of its own. That is the next problem, and it is the subject of the heap grooming section.
Root cause analysis
The crash and the free stack tell you what happened: a CAgg object was freed and then used. They do not tell you why the reader took the free path at that particular moment, or which part of the script caused it. That is the job of the root cause analysis, and it is the part of the report that turns a crash into an understanding.
The report starts with four observations about the PoC. Each one is a fact about the script that the researchers established by experiment, and together they explain the trigger:
- The bug occurs during the second call to the
resetForm. resetForminvokes calculate events on all fields if aCalculatehandler is defined.- In the
Calculatehandler, theeventobject'stargetproperty is overridden with a user-defined functiongetterFunc. - Inside this
getterFuncfunction, thetextFontproperty of the field is redefined with the value of thedocobject.
The first observation is the one that took the most work to establish. A single resetForm call does not crash. The script has to call it twice, and the second call is the one that fires. That is unusual: most bugs fire on the first attempt, and a bug that needs two attempts is a bug that depends on state left behind by the first. The researchers must have discovered this by trying the obvious thing, a single call, seeing no crash, and then adding a second call to see whether the state from the first mattered.
The second observation explains why the Calculate handler runs at all. resetForm is not a function that runs arbitrary script; it is a function that resets fields, and as a side effect of resetting them it recalculates them, which means running their Calculate actions. The script does not need to call calculateCallback directly. It only needs to register it as the field's Calculate action, and resetForm will call it.
The third observation is the re-entry trick. The event object is provided by the reader, and its target property normally holds a reference to the field the event concerns. By replacing that property with a getter, the script arranges for its own function to run whenever the reader reads target. The reader reads target during the aggregation, so the script's function runs in the middle of the reader's own work.
The fourth observation is what the getter does. It redefines the field's textFont property, the property that says which font the field's text uses, and sets its value to the document object. That is a nonsensical value for a font, but the point is not the value. The point is the side effect: redefining a property through Object.defineProperty makes it non-configurable by default, meaning it can no longer be redefined or deleted. That side effect is what makes the second resetForm different from the first.
The report then states where the crash happens: when event.richValue = this is executed in the Calculate handler. That is the assignment that starts the aggregation, and the aggregation is where the CAgg objects are created and freed.
The call hierarchy
To show how the crash connects to the script, the report gives a simplified call hierarchy. It is not a debugger output; it is a hand-drawn map of the calls, with the script's own actions marked:
AcroForm!ResetForm | this.resetForm() AcroForm!AFPDCalculateFields AcroForm!AFCalculateNthFieldEntry AcroForm!AFCalculateNthFieldEntry AcroForm!AFCalculateNthFieldEntry |- user defined callback is triggered. | field Calculate handler invoked AcroForm!SetRichValueEventProp | event.richValue = this .. some form of aggregation starts on richValue .. AcroForm!EScript_ESObjectEnum_CallbackProc AcroForm!CAgg::operator[](unsigned short)
Read from the top down, this is the same path the stack trace showed, but written as a diagram rather than as frames.
AcroForm!ResetFormis the reader's reset function, entered when the script callsthis.resetForm().AcroForm!AFPDCalculateFieldsis the function that calculates all the fields.AcroForm!AFCalculateNthFieldEntryappears three times, once for each level of the field-calculation loop. The repetition is the reader working through the fields one by one.- The line
|- user defined callback is triggered.marks the point where the reader stops doing its own work and runs the document's JavaScript. The vertical bar and arrow are the report's way of showing that this is a branch into script. | field Calculate handler invokedmarks the handler itself,calculateCallback.AcroForm!SetRichValueEventPropis where the handler'sevent.richValue = thisassignment lands.- The line
.. some form of aggregation starts on richValue ..marks the start of the conversion, the walk over the document object's properties. AcroForm!EScript_ESObjectEnum_CallbackProcis the callback that runs for each property during the walk.AcroForm!CAgg::operator[](unsigned short)is the function that crashes.
The diagram is useful because it shows the two halves of the bug in one picture. The top half is the reader's own code, running a reset. The middle is the script, running because the reset invoked it. The bottom half is the reader's code again, converting the script's value, and crashing. The bug lives at the boundary between the middle and the bottom: the script's value is being converted, and the conversion goes wrong.
The recursive enumeration
The report explains what happens inside SetRichValueEventProp. The aggregation starts there, and it enumerates the assigned object, which is the current doc object. The properties and methods of doc are enumerated recursively using EScript!ESObjectEnum, which accepts a callback where enumerated property details are passed from EScript to AcroForm. The AcroForm!EScript_ESObjectEnum_CallbackProc callback is triggered for every property being enumerated.
Two concepts need explaining here, because they are used throughout the rest of the report.
Recursion is when a function calls itself, directly or indirectly. Imagine a set of nested boxes, each containing smaller boxes. To list everything inside, you open the outer box, list what is directly inside it, and for each box you find, you open that box and repeat the process. You do not need a separate procedure for each level of nesting; you need one procedure that says "list the contents of this box, and for each box inside, do the same". That is recursion. In this bug, the document object contains properties, some of which are themselves objects with properties, which contain more objects, and so on. The enumeration walks that tree by calling itself at each level.
A callback is a function that you hand to another function, to be called later. Imagine hiring a plumber and giving her your phone number so she can call you when she finds the leak. You are not calling her; she is calling you, at a time she chooses, using the number you gave her. In programming, a callback is the same idea: you pass a function to another function, and that other function calls it when it has something to report. Here, EScript!ESObjectEnum is the enumeration function, and AcroForm!EScript_ESObjectEnum_CallbackProc is the callback it calls for each property it finds. The JavaScript engine does the walking; the form code does the converting.
The recursion and the callback together mean that the form code's callback runs many times, once per property, at every level of the tree. Each run creates a CAgg for the property it is handling. That is why the stack trace showed the same four frames over and over: each repetition is one level of the tree, one callback invocation, one CAgg created.
The std::map and the atom ids
The CAgg objects are held in containers called std::map<unsigned short, CAgg>. To understand why that matters, you need to know what a std::map is.
A std::map is a data structure from the C++ standard library. It stores key and value pairs, and it keeps them sorted by key, so that looking up a value by its key is fast. The everyday comparison is a phone book: you look up a name (the key) and get a number (the value), and the book is sorted by name so you can find the entry quickly. Internally, most implementations of std::map use a balanced binary tree, a tree-shaped structure where each node has a key, a value, and pointers to a left child and a right child, arranged so that the left child's key is smaller and the right child's key is larger. That arrangement is what makes lookups fast, and it is also what makes the map's internal pointers interesting to an attacker: if you can corrupt them, you can make the map read or write somewhere it should not.
The key type here is unsigned short, a 16-bit integer, and the value type is CAgg. So each map is a sorted table that maps a small integer to a CAgg object. The small integer is an atom id.
The reader deals with property names like "textFont", "richValue" and "target" constantly, and comparing strings character by character is slow. So the reader converts each string to an atom once, using a function the report calls ASAtomFromString, and thereafter compares integers. The atom id is the integer. An atom map is a table that maps atom ids to values, and in this bug the values are CAgg objects. So when the report says a CAgg is held in a std::map<unsigned short, CAgg>, it means the CAgg is stored in a table keyed by the atom id of a property name.
Why this matters: the map's internal tree is a structure full of pointers, and the code that inserts into the map writes through those pointers. If an attacker can control the map's pointers, they can control where those writes go. That is the seed of the exploitation, and the report returns to it shortly.
The crash in lower_bound
With page-heap enabled, the report says, the crash occurs in a function called std::map<unsigned short,CAgg>::lower_bound when it dereferences this, which is a std::map object in the current context. The report gives the function's code:
DWORD *__thiscall std::map<unsigned short,CAgg>::lower_bound(TREE_VAL *this, _DWORD *a2, unsigned __int16 *a3)
{
TREE_NODE *Myhead; // eax
TREE_NODE *Parent; // ecx
unsigned __int16 v5; // si
int v6; // eax
Myhead = this->_Myhead; // crash location - page-heaps enabled
Parent = this->_Myhead->_Parent;
...
}
This is C++, the language Acrobat Reader is written in. The __thiscall in the signature is a calling convention, a rule about how arguments are passed to the function; it tells you that this is passed in a register rather than on the stack. The this parameter is the object the function is a method of, here a std::map. The other two parameters, a2 and a3, are a pointer and a pointer to a 16-bit key.
lower_bound is a standard map operation. It finds the first entry in the map whose key is not less than the key you give it. In a phone book, it is like finding the first name that comes at or after "Smith". The map does this by walking its tree from the root downwards, comparing keys as it goes. To start that walk, it needs the root of the tree, which it gets from this->_Myhead, the map's header node.
The line marked as the crash location is:
This reads the _Myhead field from the map object. If this points to freed memory, then this->_Myhead reads from freed memory, and with page-heap enabled that read faults immediately. The next line, Parent = this->_Myhead->_Parent;, would also fault, but the first line gets there first. So the crash is a read of a field inside a freed std::map object.
Why this matters: it tells you that the map object itself is the freed thing, not just the CAgg inside it. The map is part of the CAgg structure, so freeing the CAgg frees its map, and the map's _Myhead field is one of the bytes that the reader later tries to read.
The caller: operator[]
The report then looks at who called lower_bound. It is std::map<unsigned short,CAgg>::operator[], the function that inserts a value into the map. The report gives its code:
int __thiscall std::map<unsigned short,CAgg>::operator[](TREE_VAL *this, int a2, unsigned __int16 *pSomeID)
{
...
std::map<unsigned short,CAgg>::lower_bound(this, v8, pSomeID); // Crashing path when page-heap is enabled
v4 = v9;
if ( sub_208E95F2(v9, pSomeID) )
{
...
}
else
{
if ( this->_Mysize == 0x38E38E3 )
Throw_tree_length_error();
...
*(_DWORD *)a2 = std::map<unsigned short,CAgg>::insert(this, v8[0], (int)v8[1], Parent);
...
}
return result;
}
operator[] is the square-bracket operator. In C++, when you write map[key], the compiler calls operator[] on the map with the key as an argument. For a std::map, operator[] does something slightly surprising: if the key is already in the map, it returns the existing value; if the key is not in the map, it inserts a new entry with that key and a default-constructed value, and returns the new value. So map[key] can create an entry.
The function starts by calling lower_bound to find where the key belongs in the sorted order. That is the call marked as the crashing path when page-heap is enabled: the map is freed, so lower_bound faults on the first read.
If lower_bound succeeds, the function checks whether the key was found, using a helper the report calls sub_208E95F2. If the key was found, it takes the first branch, which the report elides with .... If the key was not found, it takes the second branch, which is the interesting one.
The second branch first checks whether the map has reached its maximum size, 0x38E38E3, and throws a length error if so. That is a safety check, and it is not the bug. Then it calls std::map<unsigned short,CAgg>::insert to add the new entry, and stores the result through the pointer a2. The *(_DWORD *)a2 = ... line writes a 32-bit value to the address in a2. That is a write through a pointer, and the report notes that the insert function allows arbitrary writes.
Why this matters: the insert path is where the map's tree is modified, and modifying a tree means writing through pointers. If the map is corrupted, those writes go wherever the corrupted pointers point. That is the primitive the exploit needs.
The insert and the arbitrary write
The report gives the insert function's code:
Heap grooming
Why groom the heap at all
The free stack proved that the reader releases a CAgg object and then keeps using a pointer to it. On its own, that is a crash. To turn it into something an attacker can steer, the freed block has to be refilled with data the attacker chooses before the reader touches it again. If the reader reads its own stale data, it crashes or behaves unpredictably. If it reads the attacker's data, the attacker decides what the reader sees.
That refilling is called heap grooming. The word is borrowed from gardening: you do not plant a single seed and hope, you prepare the soil, clear a space, and put things where you want them. In memory terms, you make a series of allocations and frees so that the allocator's free lists end up in a known state, and then you allocate blocks of a chosen size and content so that they land in the space you have prepared. The everyday comparison is a car park. If you want a particular space to be free when you arrive, you can drive around and leave at the right moments so that the space is empty just as you pull in. Heap grooming is the same: you arrange allocations and frees so that the block the reader is about to reuse is one you have filled.
The report is explicit that the grooming happens before the use-after-free is triggered. That ordering matters. The reader frees the CAgg during the second resetForm, and the enumeration then uses the freed pointer almost immediately. There is no pause in which to react. So the attacker cannot wait for the free and then fill the block; the filler has to already be in place, waiting in the allocator's free lists, so that the moment the CAgg is freed, the next allocation of the same size takes that block and fills it with the attacker's data. The report notes this directly: the grooming was done before the UaF was triggered, and it says it will come back to that point later.
The tool for this is a JavaScript function called groomLFH. The name is made of two parts. LFH stands for Low Fragmentation Heap, a Windows allocator mode that groups allocations of similar sizes into buckets so that blocks of the same size are reused for each other. If you allocate many blocks of one size, they end up in the same LFH bucket, and when one is freed, the next allocation of that size is likely to take it. That predictability is exactly what grooming needs. The groom part is the verb: the function grooms the heap.
The function is given in the report as follows:
var blockRefs = [];
function groomLFH(size, count) {
log("[+] Grooming LFH blocks of size: " + size + " count: " + count);
const code =
"%u4141%u4242%u4343%u4444%u4545%u4646%u4747%u4848%u4949%u4a4a%u4b4b%u4c4c%u4d4d%u4e4e%u4f4f%u5050%u4141%u4242%u5353%u5454%u5555%u5656%u5757%u5858%u5959%u5a5a%u5b5b%u5c5c%u5d5d%u5e5e%u5f5f%u6060%u6161%u6262%u6363%u6464%u6565%u6666%u6767%u6868%u6969%u6a6a%u6b6b%u6c6c%u6d6d%u6e6e%u6f6f%u7070%u7171%u7272%u7373%u7474%u7575%u7676%u7777%u7878%u7979%u7a7a%u7b7b%u7c7c%u7d7d%u7e7e%u7f7f%u8080%u8181%u8282%u8383%u8484";
const string = unescape(code);
for (var i = 0; i < count; i++) {
blockRefs.push(string.substr(0, (size - 2) / 2).toUpperCase());
}
for (var i = 0; i < blockRefs.length; i += 2) {
blockRefs[i] = null;
delete blockRefs[i];
}
}
groomLFH(68, 4000);
This is JavaScript, the same language as the PoC, and it is worth reading line by line because every line has a purpose.
The array of references
var blockRefs = [];
var blockRefs = [] declares a variable and gives it an empty array. An array is an ordered list of values. The square brackets with nothing between them mean "a list with no items yet". The array is declared outside the function, at the top level of the script, so that it stays alive for as long as the script runs. That is deliberate: the strings the function creates must not be garbage-collected, because if they were, the memory they occupy would be freed and the grooming would be undone. Keeping a reference to each string in a global array keeps it alive.
Why this line: the grooming only works if the filler blocks stay allocated. A local variable inside the function would be discarded when the function returns, and the strings would become eligible for garbage collection. A global array holds them for the lifetime of the script.
The log line
log("[+] Grooming LFH blocks of size: " + size + " count: " + count);
log is a function the exploit defines elsewhere to print progress messages. The + operator joins strings together, so this line prints a message that includes the size and count passed to the function. The [+] prefix is a convention in exploit logs meaning "this step succeeded" or "this step is starting". The line does nothing to the heap; it is there so that when the exploit runs, the log shows what grooming was done, which helps when something goes wrong.
Why this line: exploit development involves many runs, and a log that records the parameters of each step makes it possible to compare a working run with a failing one. The report's exploit log, shown later, includes exactly this message.
Building the filler string
const code =
"%u4141%u4242%u4343%u4444%u4545%u4646%u4747%u4848%u4949%u4a4a%u4b4b%u4c4c%u4d4d%u4e4e%u4f4f%u5050%u4141%u4242%u5353%u5454%u5555%u5656%u5757%u5858%u5959%u5a5a%u5b5b%u5c5c%u5d5d%u5e5e%u5f5f%u6060%u6161%u6262%u6363%u6464%u6565%u6666%u6767%u6868%u6969%u6a6a%u6b6b%u6c6c%u6d6d%u6e6e%u6f6f%u7070%u7171%u7272%u7373%u7474%u7575%u7676%u7777%u7878%u7979%u7a7a%u7b7b%u7c7c%u7d7d%u7e7e%u7f7f%u8080%u8181%u8282%u8383%u8484";
const code declares a constant, a variable that will not be reassigned, and gives it a long string. The string is made of sequences of the form %uXXXX, where XXXX is four hexadecimal digits. Hexadecimal is a way of writing numbers using sixteen symbols, 0 to 9 and a to f, instead of the ten of ordinary decimal. It is used in computing because each hexadecimal digit maps exactly to four binary bits, so a four-digit hex number maps to sixteen bits, which is two bytes. The %u prefix is a convention from JavaScript's unescape function, which interprets %uXXXX as a single character whose code is XXXX.
So %u4141 means "the character whose code is 0x4141". The value 0x41 is the ASCII code for the capital letter A, so 0x4141 is the two-byte sequence AA. The next, %u4242, is BB, then %u4343 is CC, and so on. The string is a sequence of two-byte pairs, each pair being the same letter repeated: AA, BB, CC, DD, and so on up the alphabet and into the higher byte values.
Why this line: the filler needs to be recognisable. When the exploit crashes, the debugger shows the contents of the memory that was used, and if the memory is full of AA BB CC DD patterns, the researcher can tell at a glance that the crash is reading the groomed filler and not something else. The pattern is a magic marker, a known value placed in memory so that it can be found later. The report uses magic markers again when locating the ArrayBuffer spray.
There is a subtlety in the sequence. Most of the pairs run in order, but two pairs are out of place: after %u5050 comes %u4141%u4242, and then %u5353. So the sequence is ... PP AA BB SS ... rather than ... PP QQ RR SS .... That is not an accident. The report later shows a second version of this string, used when corrupting the ArrayBuffer length, in which the out-of-place pair is %u0058%u2000 instead. The position of the odd pair is the position where the exploit needs a specific value, and the rest of the string is padding to reach that position. In the grooming version, the odd pair is AA BB, which is just a marker; in the corruption version, it is a value chosen to overwrite the length field. The report does not spell this out, but the two strings side by side make it clear.
Turning the escapes into characters
const string = unescape(code);
unescape is a JavaScript function that takes a string containing %uXXXX sequences and returns a new string in which each sequence has been replaced by the corresponding character. So unescape("%u4141%u4242") returns a two-character string, AA followed by BB. The result is stored in string.
Why this line: the %uXXXX form is a convenient way to write the pattern in source code, but the string that actually gets allocated must contain the raw bytes. unescape performs that conversion. The report's use of unescape is a common trick in browser and PDF exploits, because it lets the author write arbitrary byte values in a readable form.
Allocating the filler blocks
for (var i = 0; i < count; i++) {
blockRefs.push(string.substr(0, (size - 2) / 2).toUpperCase());
}
This is a loop. for (var i = 0; i < count; i++) runs the body count times, with i going from 0 up to count - 1. Inside the loop, string.substr(0, (size - 2) / 2) takes a substring of string, starting at position 0 and of a given length. The length is (size - 2) / 2.
The arithmetic needs explaining. size is the desired size of the allocated block in bytes. The string is made of two-byte characters, so a substring of n characters occupies 2n bytes. The expression (size - 2) / 2 gives the number of characters needed to occupy size - 2 bytes. Why size - 2 rather than size? Because the string object itself has a small header, and the total allocation is the header plus the characters. The exact reason for the 2 is not stated in the report; what matters is that the researchers tuned it so that the allocation lands in the right size class.
.toUpperCase() converts the substring to upper case. Since the substring is already made of upper-case letters and other byte values, this looks redundant. Its purpose is to force the JavaScript engine to create a new string rather than reusing an existing one. JavaScript engines often intern strings, meaning they keep a single copy of each distinct string and hand out references to it. If the engine interned the filler, all 4000 allocations would point to the same block, and the grooming would allocate one block instead of 4000. Calling toUpperCase produces a string that the engine has not seen before, so it allocates fresh memory for each one.
blockRefs.push(...) adds the new string to the end of the array. So after the loop, blockRefs holds count strings, each of which occupies a block of roughly size bytes.
Why this loop: it fills the LFH bucket for the chosen size with attacker-controlled blocks. The strings are the filler. Their content is the AA BB CC DD pattern, and their size is chosen to match the object the reader is about to free.
Freeing every other block
for (var i = 0; i < blockRefs.length; i += 2) {
blockRefs[i] = null;
delete blockRefs[i];
}
This second loop walks the array with a step of 2, so it visits indices 0, 2, 4, 6 and so on. For each, it sets the array entry to null and then deletes it. Setting to null removes the reference to the string; delete removes the array slot itself. Together they mean the script no longer holds a reference to that string, so the JavaScript engine's garbage collector can free it.
The garbage collector is the part of the engine that reclaims memory for objects the program can no longer reach. Once the only reference to a string is gone, the string becomes eligible for collection, and its memory is returned to the allocator. So this loop frees every second filler block, leaving a pattern of alternating allocated and free blocks in the LFH bucket.
Why this loop: this is the heart of the grooming. By freeing every second block, the researchers create a row of holes of exactly the right size, interleaved with blocks that are still allocated. When the reader later frees the CAgg, the allocator has a hole of the matching size ready, and the next allocation of that size will take it. More importantly, the holes are surrounded by filler blocks whose contents are known, so when the reader reads past the end of a freed block, it reads the AA BB CC DD pattern rather than random data. That is what makes the crash controllable: the report's next output shows the crash reading 42424141, which is the AA BB pattern from the filler.
The call
groomLFH(68, 4000);
This calls the function with size = 68 and count = 4000. So the exploit creates 4000 strings, each occupying a block of about 68 bytes, and then frees every second one, leaving 2000 holes of that size.
Why 68: the report says the crashing object size was initially found by brute forcing. Brute forcing means trying many possibilities systematically until one works. The researchers did not know in advance which size the freed CAgg would be, so they tried a range of sizes, ran the exploit with each, and watched which one produced a controlled crash. Size 68 is the one that worked. The number is not derived from a formula in the report; it is an empirical result.
Why 4000: the count has to be large enough to fill the LFH bucket and to make it likely that one of the holes is the one the freed CAgg lands in. Too few, and the bucket is not saturated; too many, and the exploit becomes slow and memory-hungry. 4000 is the value the researchers settled on.
What the grooming achieves
After groomLFH(68, 4000) runs, the heap contains 2000 free blocks of about 68 bytes, each surrounded by allocated blocks filled with the AA BB CC DD pattern. When the reader frees the CAgg during the second resetForm, the allocator has a free block of the matching size, and the next allocation of that size takes it. The reader's later use of the freed pointer then reads whatever the new allocation put there.
The report's next output shows the result. With the grooming in place, the crash changes to a fault on a controlled value:
eax=04b7a854 ebx=04b7a8b4 ecx=42424141 edx=4e4e4d4d esi=6921ef50 edi=42424141 eip=6c3695af esp=04b7a838 ebp=04b7a838 iopl=0 nv up ei pl nz ac po nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010212 AcroForm!CAgg::operator[](unsigned short)+0x3: 6c3695af 8b01 mov eax,dword ptr [ecx] ds:002b:42424141=????????
Compare this with the original crash. The faulting instruction is still in AcroForm!CAgg::operator[](unsigned short), but the offset is now +0x3 rather than +0xe, and the registers hold recognisable values. ecx and edi both contain 42424141, and edx contains 4e4e4d4d. Those are the filler pattern: 41 is A, 42 is B, 4d is M, 4e is N. The value 42424141 is the bytes AA BB read as a 32-bit little-endian integer, and 4e4e4d4d is MM NN. The reader is dereferencing a pointer built from the filler, which means the freed CAgg has been replaced by attacker-controlled data.
The report says: in the crashing function, we can see that the user-controlled value is being dereferenced. The crash is no longer a random fault; it is a fault on a value the attacker chose, which means the attacker can choose where the reader reads and writes next.
Confirming the allocation source
The report then verifies where the controlled block came from, using the page-heap extension again:
0:015> !ext.heap -p -a 36f76fb8 address 36f76fb8 found in _DPH_HEAP_ROOT @ 9801000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 36f51924: 36f76fb8 48 - 36f76000 2000 6fb1a8b0 verifier!AVrfDebugPageHeapAllocate+0x00000240 76fbef0e ntdll!RtlDebugAllocateHeap+0x00000039 76f26150 ntdll!RtlpAllocateHeap+0x000000f0 76f257fe ntdll!RtlpAllocateHeapInternal+0x000003ee 76f253fe ntdll!RtlAllocateHeap+0x0000003e 75d00166 ucrtbase!_malloc_base+0x00000026 6aaaee40 AcroForm!operator new(unsigned int)+0x0000001a 6acf7044 AcroForm!sub_20AA701F+0x00000025 6ad25a56 AcroForm!sub_20AD5A43+0x00000013 6ad25fba AcroForm!std::map<unsigned short,CAgg>::operator[](unsigned short const&)+0x00000057 6ad26bc5 AcroForm!CAgg::operator[](unsigned short)+0x0000003a 6ad22a50 AcroForm!EScript_ESObjectEnum_CallbackProc+0x00000030 ... 6ace3b35 AcroForm!SetRichValueEventProp+0x000001f5 ...
This output is the same format as the earlier !ext.heap output, but the answer is different. The address 36f76fb8 is found in busy allocation, meaning it is currently allocated, not free. The block's UserSize is 48 in hexadecimal, which is 72 bytes, close to the 68 the grooming targeted; the difference is the allocator's rounding and header. The allocation stack, read from the bottom up, shows the block was allocated by AcroForm!SetRichValueEventProp, through EScript_ESObjectEnum_CallbackProc, CAgg::operator[], std::map<unsigned short,CAgg>::operator[], sub_20AD5A43, sub_20AA701F and AcroForm!operator new. So this is a CAgg allocated during the enumeration, exactly the kind of object the bug frees.
Why this matters: it confirms that the block the reader is now using is a CAgg allocated during the aggregation, and that its memory is in the busy state, meaning it is live. The grooming has placed controlled data in the freed block, and the reader has allocated a new CAgg over it. The next step is to understand how the reader's own string handling reallocates the freed buffer with the attacker's content, which is the subject of the next part of the report.
The string conversion that refills the block
The report then explains why the sprayed strings are used during the aggregation. Inside CAggToESVal, when the object type is a string, the following code runs, creating a new string from the CAgg:
int __usercall CAggToESVal@<eax>(bool (*a1)[27]@<ebx>, wchar_t *a2, CAgg *a3)
{
...
else
{
m_str = (_EStrRec **)CAgg::toEStr(a3, a1);
if ( *m_str )
v14 = EStrCopyImpl(*m_str);
else
v14 = 0;
if ( EStrGetEncoding((MayBeString *)v14) )
EStrSetEncoding(v14, 2);
v15 = dword_21472158;
Bytes = EStrGetBytes((MayBeString *)v14);
result = (*((int (__cdecl **)(wchar_t *, int))v15 + 31))(a2, Bytes); // ESValSetString
if ( v14 )
return EStrDelete(v14);
}
}
This is C++ again. CAggToESVal converts a CAgg into a JavaScript value. The else branch handles the case where the CAgg holds a string. CAgg::toEStr extracts the string from the CAgg. EStrCopyImpl makes a copy of it. EStrGetEncoding and EStrSetEncoding deal with the string's character encoding, setting it to 2 if it has one. EStrGetBytes gets the raw bytes of the string. Then the function calls through a function pointer, (*((int (__cdecl **)(wchar_t *, int))v15 + 31)), with the destination and the bytes. The comment identifies this call as ESValSetString, the function that creates a new JavaScript string from the bytes. Finally, EStrDelete frees the temporary copy.
Why this matters: the sprayed strings are the CAgg objects being converted. When the reader converts one of them back into a JavaScript string, it calls ESValSetString, which allocates a new buffer and copies the string's content into it. That allocation is the moment when the freed CAgg block can be refilled with the attacker's data.
The report then shows the function that ESValSetString calls, sub_1003EBD2:
char **__usercall sub_1003EBD2@<eax>(__int128 a1@<xmm0>, int a2, wchar_t *a3)
{
...
sub_1003E853((int *)a2);
if ( a3
&& strlen_0(a3, 0x7FFFFFFFu, 0) > 1
&& (*(_BYTE *)a3 == 0xFE && *((_BYTE *)a3 + 1) == 0xFF || *(_BYTE *)a3 == 0xFF && *((_BYTE *)a3 + 1) == 0xFE) )
{
v24 = 0;
v22 = 0x7FFFFFFF;
_mm_lfence();
v3 = miStrlen(a3, v22, v24);
v4 = JS_malloc_Wrapper(*(_DWORD *)a2, v3); // reallocate freed buffer again when string length is 0x48
Block = (char *)v4;
if ( v4 )
{
v25 = v3;
v23 = (char *)v4;
v21 = (char *)(a3 + 1);
_mm_lfence();
swab(v21, v23, v25);
return JS_NewUCString(a1, *(_DWORD **)a2, Block, v3 / 2 - 1);
}
return 0;
}
...
}
This function creates a new string from a byte buffer. The if condition checks that the buffer is not null, that its length is greater than 1, and that it starts with a byte order mark: either 0xFE 0xFF or 0xFF 0xFE. A byte order mark is a special sequence at the start of a text buffer that says which byte order the text uses. The check is there because the function is handling a wide-character string, and the byte order mark tells it how to interpret the bytes.
Inside the if, miStrlen measures the string's length. Then JS_malloc_Wrapper(*(_DWORD *)a2, v3) allocates a buffer of that length. The comment in the report is the key line: // reallocate freed buffer again when string length is 0x48. So when the string's length is 0x48, which is 72 bytes, the allocation lands in the same size class as the freed CAgg, and the allocator hands back the freed block. swab swaps the byte order of the string, and JS_NewUCString creates the JavaScript string.
Why this matters: this is the mechanism that refills the freed block. The sprayed strings are converted back to JavaScript strings during the aggregation, and each conversion allocates a buffer of the string's length. When the length matches the freed CAgg's size, the allocation takes the freed block and fills it with the string's content, which is the attacker's AA BB CC DD pattern. The report says: JS_malloc_Wrapper will reallocate the freed CAgg buffer when processing a large number of strings, allowing the researchers to reallocate the buffer with user-controlled data. When this sprayed buffer is later used in the CAgg::* functions, it causes a crash while dereferencing user-controlled data.
So the grooming and the string conversion work together. The grooming creates the holes and the filler. The string conversion, triggered by the aggregation itself, allocates into those holes and fills them with the filler's content. The reader then uses the freed CAgg pointer, which now points into the filler, and the crash shows the AA BB pattern. That is the controlled crash the report shows, and it is the foundation for the next stage: turning the controlled crash into a controlled read and write.
The controlled crash
The grooming changes the crash, and the change is the whole point of the exercise. Before grooming, the reader faulted on an address that was simply not mapped, and the debugger could say nothing more than "this memory does not exist". After grooming, the reader faults on a value the attacker chose, and that is a completely different situation: it means the freed block has been refilled with the attacker's data, and the reader is now reading that data as if it were its own.
The report shows the crash after grooming as follows:
eax=04b7a854 ebx=04b7a8b4 ecx=42424141 edx=4e4e4d4d esi=6921ef50 edi=42424141 eip=6c3695af esp=04b7a838 ebp=04b7a838 iopl=0 nv up ei pl nz ac po nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010212 AcroForm!CAgg::operator[](unsigned short)+0x3: 6c3695af 8b01 mov eax,dword ptr [ecx] ds:002b:42424141=????????
This is the same kind of register dump you saw in the first crash, so the format should be familiar. Each name on the left is a register, a small storage slot inside the processor itself. Registers are the fastest memory a computer has, and a program uses them to hold the values it is working on right now. When a program crashes, the debugger prints the registers so you can see exactly what the processor was holding at the moment of the fault.
Reading the dump from left to right:
eax=04b7a854is the general-purpose registereax, holding a number that looks like an address. It is not the one that matters here.ebx=04b7a8b4is another general-purpose register, also holding something address-like.ecx=42424141is the registerecx, and its value is the interesting one.42424141is not a plausible address in this process. It is the bytes41 41 42 42, which in the ASCII character encoding areA A B B. That is the filler pattern from the grooming, read as a 32-bit number.edx=4e4e4d4dis the registeredx, holding4d 4d 4e 4e, which isM M N N. Again, the filler pattern.esi=6921ef50is a register holding what looks like a real address inside a module. It is not the faulting one.edi=42424141is the registeredi, and it holds the sameA A B Bvalue asecx. Two registers holding the same filler value is a strong hint that the program loaded that value from the groomed memory and is now using it as a pointer.eip=6c3695afis the instruction pointer, the register that says which instruction the processor was trying to execute. It points intoAcroForm, the form-handling module.- The remaining registers (
esp,ebp, the segment registerscs,ss,ds,es,fs,gs, and the flags registerefl) describe the stack and the processor's state. They are printed for completeness but are not needed to understand the bug.
The line after the registers is the fault itself:
AcroForm!CAgg::operator[](unsigned short)+0x3: 6c3695af 8b01 mov eax,dword ptr [ecx] ds:002b:42424141=????????
Read it in pieces.
AcroForm!CAgg::operator[](unsigned short)+0x3says the faulting code is inside theCAgg::operator[]function, at an offset of0x3from the start of the function. Compare this with the first crash, which was at+0xe. The offset has changed, which means the program took a slightly different path through the function this time. That makes sense: the memory it is working with is different, so it gets further before it fails.6c3695afis the address of the instruction, matchingeip.8b01is the machine code of the instruction, two bytes long.mov eax,dword ptr [ecx]is the instruction written in assembly language, the human-readable form of machine code. It says: take the value inecx, treat it as an address, read a 32-bit value (dword ptr) from that address, and put the result ineax. In plain words: "go to the address inecxand fetch what is there".ds:002b:42424141=????????is the debugger's attempt to show what is at that address. Theds:002bpart names the memory segment, which is a detail of how the processor addresses memory. The42424141is the address being read, taken fromecx. The????????means the debugger could not read anything there: the address is not mapped, so the read failed and the processor raised an access violation.
So the fault is a read from the address 42424141, which is the filler pattern, not a real address. The program took a value out of the groomed memory, put it in ecx, and then tried to use it as a pointer. That is exactly what the grooming was designed to achieve.
Why this is a step forward, not just a different crash: in the first crash, the reader was dereferencing an address that came from its own freed bookkeeping, and the attacker had no say in it. Here, the address comes from the attacker's filler. The attacker chose the bytes 41 41 42 42, and the reader is now using them as a pointer. If the attacker chooses different bytes, the reader will use a different address. That is control, and control is what turns a crash into an exploit. The report puts it plainly: in the crashing function, we can see that the user-controlled value is being dereferenced.
There is a second observation hidden in the dump. The faulting instruction is mov eax,dword ptr [ecx], a read, not a write. The reader is trying to read from the attacker-chosen address. A read alone does not let an attacker change anything; it only lets them see what is there, and in this case it does not even succeed, because the address is unmapped. The next stage of the work is to choose an address that is mapped and that contains something useful, so that the read succeeds and the reader's behaviour becomes predictable. That is what the ArrayBuffer spray later provides: a large region of memory at a known address, filled with attacker-chosen content, so that when the reader dereferences the filler value, it lands on data the attacker prepared.
Confirming where the controlled block came from
A controlled crash is only useful if you know which allocation produced it. The filler pattern could, in principle, have come from anywhere: a string the script created, a buffer the reader allocated, or some leftover data from an earlier part of the process. The report settles the question with the page-heap extension, the same tool used earlier to prove the free:
0:015> !ext.heap -p -a 36f76fb8 address 36f76fb8 found in _DPH_HEAP_ROOT @ 9801000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 36f51924: 36f76fb8 48 - 36f76000 2000 6fb1a8b0 verifier!AVrfDebugPageHeapAllocate+0x00000240 76fbef0e ntdll!RtlDebugAllocateHeap+0x00000039 76f26150 ntdll!RtlpAllocateHeap+0x000000f0 76f257fe ntdll!RtlpAllocateHeapInternal+0x000003ee 76f253fe ntdll!RtlAllocateHeap+0x0000003e 75d00166 ucrtbase!_malloc_base+0x00000026 6aaaee40 AcroForm!operator new(unsigned int)+0x0000001a 6acf7044 AcroForm!sub_20AA701F+0x00000025 6ad25a56 AcroForm!sub_20AD5A43+0x00000013 6ad25fba AcroForm!std::map<unsigned short,CAgg>::operator[](unsigned short const&)+0x00000057 6ad26bc5 AcroForm!CAgg::operator[](unsigned short)+0x0000003a 6ad22a50 AcroForm!EScript_ESObjectEnum_CallbackProc+0x00000030 ... 6ace3b35 AcroForm!SetRichValueEventProp+0x000001f5 ...
The command is the same one used before: !ext.heap -p -a 36f76fb8 asks the page-heap extension to look up the address 36f76fb8 and report what the heap knows about it. The address is different from the one in the earlier lookup, because this is a different run and a different block, but the format of the answer is the same.
The first line gives the verdict:
address 36f76fb8 found in _DPH_HEAP_ROOT @ 9801000 in busy allocation
The phrase to notice is in busy allocation. Earlier, the lookup said in free-ed allocation, meaning the block had been given back. Now it says busy, meaning the block is currently allocated and in use. So the address the reader is working with is not a freed block this time; it is a live allocation. That is a change in the story, and it needs explaining.
The next line gives the block's details:
( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 36f51924: 36f76fb8 48 - 36f76000 2000
UserAddr is 36f76fb8, the address that was looked up. UserSize is 48 in hexadecimal, which is 72 bytes in decimal. VirtAddr is 36f76000, the start of the page the block sits on, and VirtSize is 2000 hexadecimal, 8192 bytes, the size of the page. So the block is 72 bytes of user-visible memory inside an 8-kilobyte page. The 72 bytes is close to the 68 the grooming targeted; the difference is the allocator's rounding and the small header it keeps in front of each block.
The rest of the output is the allocation stack, the stack trace captured at the moment the block was allocated. It is printed innermost frame first, the same way as the free stack earlier, and it answers the question "which code created this block?".
The top frames are the page-heap and Windows heap machinery, the same plumbing seen in the free stack:
6fb1a8b0 verifier!AVrfDebugPageHeapAllocate+0x00000240
76fbef0e ntdll!RtlDebugAllocateHeap+0x00000039
76f26150 ntdll!RtlpAllocateHeap+0x000000f0
76f257fe ntdll!RtlpAllocateHeapInternal+0x000003ee
76f253fe ntdll!RtlAllocateHeap+0x0000003e
75d00166 ucrtbase!_malloc_base+0x00000026
verifier!AVrfDebugPageHeapAllocate is the page-heap verifier recording the allocation. The ntdll!Rtl...AllocateHeap frames are the Windows heap manager's internal functions. ucrtbase!_malloc_base is the C runtime's malloc, the standard library call a program uses to ask for memory. So the chain is: some code called malloc, which went down into the Windows heap manager, which handed the block to the page-heap verifier. That is the mirror image of the free stack, which went through free instead of malloc.
The frames below that are the reader's own code, and they are the ones that matter:
6aaaee40 AcroForm!operator new(unsigned int)+0x0000001a
6acf7044 AcroForm!sub_20AA701F+0x00000025
6ad25a56 AcroForm!sub_20AD5A43+0x00000013
6ad25fba AcroForm!std::map<unsigned short,CAgg>::operator[](unsigned short const&)+0x00000057
6ad26bc5 AcroForm!CAgg::operator[](unsigned short)+0x0000003a
6ad22a50 AcroForm!EScript_ESObjectEnum_CallbackProc+0x00000030
...
6ace3b35 AcroForm!SetRichValueEventProp+0x000001f5
...
Read from the bottom up, this is the story of the allocation.
AcroForm!SetRichValueEventProp is the function that handles the assignment to event.richValue, the same function that appeared in the crash stack and in the free stack. It is where the aggregation begins. So the block was allocated during the aggregation, which is exactly the phase of the exploit the researchers are interested in.
AcroForm!EScript_ESObjectEnum_CallbackProc is the callback that runs for each property during the enumeration. It is the function the report names as the one that keeps using the freed pointer. Here it is on the allocation side: it is the function that asked for the block.
AcroForm!CAgg::operator[](unsigned short) is the function that crashed in both crash dumps. Here it is not crashing; it is calling down into the map code to insert a value. The +0x3a offset is different from the crash offsets, which makes sense: this is a different point in the function, the point where it allocates rather than the point where it dereferences.
AcroForm!std::map<unsigned short,CAgg>::operator[](unsigned short const&) is the map's square-bracket operator, the function that inserts a value into the map. It is the same function that appeared in the root cause analysis, the one that calls lower_bound and then insert.
AcroForm!sub_20AD5A43 and AcroForm!sub_20AA701F are unnamed functions, helpers inside the map insertion path. The debugger has no symbols for them, so it names them by address.
AcroForm!operator new(unsigned int) is the C++ new operator, the counterpart of operator delete. In C++, when you create an object with new, the compiler calls this operator to get memory for it. This frame is the point where the CAgg object's memory is actually requested, and it is the frame immediately above ucrtbase!_malloc_base in the stack. So the chain is complete: the enumeration callback asked for a CAgg, the map insertion path called operator new, which called malloc, which got the block from the heap.
Why this matters: it confirms that the block the reader is now using is a CAgg allocated during the aggregation, by the same code path that the bug involves. The block is live, not freed, which means the reader has allocated a new CAgg over the memory that was previously freed. The grooming placed the filler in the freed block, the reader's own string conversion refilled it with attacker content, and then the reader allocated a new CAgg on top of it. The new CAgg's fields are now whatever the attacker's filler put there, and when the reader uses those fields as pointers, it dereferences the filler pattern.
The two outputs together tell a complete story. The crash dump shows the reader dereferencing 42424141, the filler pattern, which proves the attacker controls the value being used as a pointer. The allocation stack shows that the block holding that value was allocated by the enumeration callback through the map insertion path, which proves the controlled value is sitting in a CAgg that the reader itself created during the aggregation. The attacker has not just corrupted some random memory; they have corrupted the reader's own bookkeeping, at the exact place the bug touches it.
That is the foundation for everything that follows. A controlled crash on a value the attacker chooses is not yet code execution, but it is the first step. The next problem is to make the chosen value point at memory the attacker controls and can read, so that the reader's dereference succeeds and returns something useful. That is what the ArrayBuffer spray provides, and it is the subject of the next section.
Why the sprayed strings come back as fresh allocations
The grooming section so far has explained how the filler gets into the heap and how the crash becomes controlled. There is one more piece of the mechanism to explain, and it is the piece that makes the whole thing work: the reader itself, in the middle of the aggregation, allocates fresh buffers and copies the sprayed string content into them. The attacker does not need a separate step to refill the freed CAgg; the reader's own string handling does it.
The report explains this by looking at what happens inside CAggToESVal when the object type is a string. CAggToESVal is the function that converts a CAgg back into a JavaScript value, the reverse of ESValToCAgg. When the CAgg holds a string, the function takes the following path:
int __usercall CAggToESVal@<eax>(bool (*a1)[27]@<ebx>, wchar_t *a2, CAgg *a3)
{
...
else
{
m_str = (_EStrRec **)CAgg::toEStr(a3, a1);
if ( *m_str )
v14 = EStrCopyImpl(*m_str);
else
v14 = 0;
if ( EStrGetEncoding((MayBeString *)v14) )
EStrSetEncoding(v14, 2);
v15 = dword_21472158;
Bytes = EStrGetBytes((MayBeString *)v14);
result = (*((int (__cdecl **)(wchar_t *, int))v15 + 31))(a2, Bytes); // ESValSetString
if ( v14 )
return EStrDelete(v14);
}
}
This is C++, and the signature at the top tells you what the function takes and returns. __usercall is a calling convention, a rule about how arguments are passed; the @<eax> part says the return value comes back in the eax register. The parameters are a1, a pointer to an array of 27 booleans (the same set of type flags seen in CAgg::convert), a2, a pointer to a wide-character string that is the destination, and a3, the CAgg being converted.
The else branch is the one that handles strings. Read it line by line.
m_str = (_EStrRec **)CAgg::toEStr(a3, a1);
The name is short for "to EStr", where EStr is the reader's internal string type. The result is cast to a pointer to a pointer to _EStrRec, a structure that describes a string. So m_str is a handle on the string inside the CAgg.
if ( *m_str )
v14 = EStrCopyImpl(*m_str);
else
v14 = 0;
If the string handle is not null, EStrCopyImpl makes a copy of the string and stores it in v14. If the handle is null, v14 is set to 0. The copy matters: the function is about to hand the string's bytes to the JavaScript engine, and it does not want the engine to hold a pointer into the CAgg's own memory, because that memory may be freed. So it works on a copy.
if ( EStrGetEncoding((MayBeString *)v14) )
EStrSetEncoding(v14, 2);
EStrGetEncoding asks the copy what character encoding it uses. If it has one, EStrSetEncoding(v14, 2) sets it to 2. Character encoding is the rule that maps bytes to characters: the same byte can mean different letters depending on whether the text is ASCII, UTF-8, UTF-16 and so on. Setting the encoding to 2 tells the rest of the code how to interpret the bytes.
v15 = dword_21472158;
Bytes = EStrGetBytes((MayBeString *)v14);
dword_21472158 is a