Skip to content
Memory corruption Disclosed report Advanced CVE-2016-5296

Heap-buffer-overflow WRITE in rasterize_edges_1

A crafted SVG path stroke caused a heap buffer overflow write inside the pixman edge rasteriser used by Firefox's Cairo graphics layer. The crash report shows a multi-byte write far outside the allocated buffer, which an attacker could use to corrupt memory in the content process.

Abhishek Arya Follow

Originally disclosed on Mozilla

Critical View original
  • Fixed in 3 months
  • Paid in 60 days
  • Disclosed after 3 months
Text
Created attachment 8778096
Testcase

==13447==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6230000601a8 at pc 0x0000004bea3c bp 0x7ffeffd80c70 sp 0x7ffeffd80420
WRITE of size 4112 at 0x6230000601a8 thread T0 (Web Content)
SCARINESS: 55 (multi-byte-write-heap-buffer-overflow-far-from-bounds)
    #0 0x4bea3b in __asan_memset _asan_rtl_
    #1 0x7fd8de8e2b4c in rasterize_edges_1 gfx/cairo/libpixman/src/pixman-edge-imp.h:125:7
    #2 0x7fd8de8e2b4c in pixman_rasterize_edges_no_accessors gfx/cairo/libpixman/src/pixman-edge.c:351
    #3 0x7fd8de8e2b4c in _moz_pixman_rasterize_edges gfx/cairo/libpixman/src/pixman-edge.c:382
    #4 0x7fd8de99d824 in _moz_pixman_rasterize_trapezoid gfx/cairo/libpixman/src/pixman-trap.c:386:2
    #5 0x7fd8de7b1392 in _pixman_image_add_traps gfx/cairo/cairo/src/cairo-image-surface.c:2466:2
    #6 0x7fd8de7b0701 in _composite_traps gfx/cairo/cairo/src/cairo-image-surface.c:2516:5
    #7 0x7fd8de7b5b18 in _clip_and_composite gfx/cairo/cairo/src/cairo-image-surface.c:2359:15
    #8 0x7fd8de7b891f in _clip_and_composite_trapezoids gfx/cairo/cairo/src/cairo-image-surface.c:3258:12
    #9 0x7fd8de7b7d7d in _clip_and_composite_polygon gfx/cairo/cairo/src/cairo-image-surface.c:3625:15
    #10 0x7fd8de7a3ceb in _cairo_image_surface_stroke gfx/cairo/cairo/src/cairo-image-surface.c:3717:15
    #11 0x7fd8de81bce1 in _cairo_surface_stroke gfx/cairo/cairo/src/cairo-surface.c:2296:11
    #12 0x7fd8de796646 in _cairo_gstate_stroke gfx/cairo/cairo/src/cairo-gstate.c:1166:14
    #13 0x7fd8de83ea7d in _moz_cairo_stroke_preserve gfx/cairo/cairo/src/cairo.c:2430:14
    #14 0x7fd8d75bfbcf in mozilla::gfx::DrawTargetCairo::DrawPattern(mozilla::gfx::Pattern const&, mozilla::gfx::StrokeOptions const&, mozilla::gfx::DrawOptions const&, mozilla::gfx::DrawTargetCairo::DrawPatternType, bool) gfx/2d/DrawTargetCairo.cpp:1024:7
    #15 0x7fd8d75c4f81 in mozilla::gfx::DrawTargetCairo::Stroke(mozilla::gfx::Path const*, mozilla::gfx::Pattern const&, mozilla::gfx::StrokeOptions const&, mozilla::gfx::DrawOptions const&) gfx/2d/DrawTargetCairo.cpp:1255:3
    #16 0x7fd8dcd8bca6 in nsSVGPathGeometryFrame::Render(gfxContext*, unsigned int, gfxMatrix const&) layout/svg/nsSVGPathGeometryFrame.cpp:867:21
    #17 0x7fd8dcd8a20d in nsSVGPathGeometryFrame::PaintSVG(gfxContext&, gfxMatrix const&, mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const*) layout/svg/nsSVGPathGeometryFrame.cpp:293:5
    #18 0x7fd8dcd88726 in nsDisplaySVGPathGeometry::Paint(nsDisplayListBuilder*, nsRenderingContext*) layout/svg/nsSVGPathGeometryFrame.cpp:125:51
    #19 0x7fd8dc5f5f98 in mozilla::FrameLayerBuilder::PaintItems(nsTArray<mozilla::FrameLayerBuilder::ClippedDisplayItem>&, mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&, gfxContext*, nsRenderingContext*, nsDisplayListBuilder*, nsPresContext*, mozilla::gfx::IntPointTyped<mozilla::gfx::UnknownUnits> const&, float, float, int) layout/base/FrameLayerBuilder.cpp:5710:21
    #20 0x7fd8dc5f9433 in mozilla::FrameLayerBuilder::DrawPaintedLayer(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*) layout/base/FrameLayerBuilder.cpp:5885:19
    #21 0x7fd8d7940a51 in mozilla::layers::BasicPaintedLayer::PaintThebes(gfxContext*, mozilla::layers::Layer*, void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*) gfx/layers/basic/BasicPaintedLayer.cpp:95:9
    #22 0x7fd8d793b3ec in mozilla::layers::BasicLayerManager::PaintSelfOrChildren(mozilla::layers::PaintLayerContext&, gfxContext*) gfx/layers/basic/BasicLayerManager.cpp:714:13
    #23 0x7fd8d7939c49 in mozilla::layers::BasicLayerManager::PaintLayer(gfxContext*, mozilla::layers::Layer*, void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*) gfx/layers/basic/BasicLayerManager.cpp:883:5
    #24 0x7fd8d793b0b2 in mozilla::layers::BasicLayerManager::PaintSelfOrChildren(mozilla::layers::PaintLayerContext&, gfxContext*) gfx/layers/basic/BasicLayerManager.cpp:735:7
    #25 0x7fd8d7939c49 in mozilla::layers::BasicLayerManager::PaintLayer(gfxContext*, mozilla::layers::Layer*, void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*) gfx/layers/basic/BasicLayerManager.cpp:883:5
    #26 0x7fd8d7934f1d in mozilla::layers::BasicLayerManager::EndTransactionInternal(void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) gfx/layers/basic/BasicLayerManager.cpp:623:5
    #27 0x7fd8dc5f5fb6 in PaintInactiveLayer layout/base/FrameLayerBuilder.cpp:3605:12
    #28 0x7fd8dc5f5fb6 in mozilla::FrameLayerBuilder::PaintItems(nsTArray<mozilla::FrameLayerBuilder::ClippedDisplayItem>&, mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&, gfxContext*, nsRenderingContext*, nsDisplayListBuilder*, nsPresContext*, mozilla::gfx::IntPointTyped<mozilla::gfx::UnknownUnits> const&, float, float, int) layout/base/FrameLayerBuilder.cpp:5696
    #29 0x7fd8dc5f9433 in mozilla::FrameLayerBuilder::DrawPaintedLayer(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*) layout/base/FrameLayerBuilder.cpp:5885:19
    #30 0x7fd8d79536e2 in mozilla::layers::ClientPaintedLayer::PaintThebes() gfx/layers/client/ClientPaintedLayer.cpp:94:5
    #31 0x7fd8d795437d in mozilla::layers::ClientPaintedLayer::RenderLayerWithReadback(mozilla::layers::ReadbackProcessor*) gfx/layers/client/ClientPaintedLayer.cpp:148:3
    #32 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #33 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #34 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #35 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #36 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #37 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #38 0x7fd8d796dd8c in mozilla::layers::ClientContainerLayer::RenderLayer() gfx/layers/client/ClientContainerLayer.h:65:29
    #39 0x7fd8d794e89e in mozilla::layers::ClientLayerManager::EndTransactionInternal(void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) gfx/layers/client/ClientLayerManager.cpp:296:9
    #40 0x7fd8d794ee7c in mozilla::layers::ClientLayerManager::EndTransaction(void (*)(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) gfx/layers/client/ClientLayerManager.cpp:339:3
    #41 0x7fd8dc74a3db in nsDisplayList::PaintRoot(nsDisplayListBuilder*, nsRenderingContext*, unsigned int) layout/base/nsDisplayList.cpp:1927:17
    #42 0x7fd8dc7fb0d0 in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, nsDisplayListBuilderMode, nsLayoutUtils::PaintFrameFlags) layout/base/nsLayoutUtils.cpp:3606:10
    #43 0x7fd8dc8835ad in PresShell::Paint(nsView*, nsRegion const&, unsigned int) layout/base/nsPresShell.cpp:6636:5
    #44 0x7fd8dbe4bf5c in nsViewManager::ProcessPendingUpdatesPaint(nsIWidget*) view/nsViewManager.cpp:484:19
    #45 0x7fd8dbe4ad31 in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) view/nsViewManager.cpp:415:33
    #46 0x7fd8dbe4ecc9 in nsViewManager::ProcessPendingUpdates() view/nsViewManager.cpp:1119:5
    #47 0x7fd8dc57654f in nsRefreshDriver::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:1911:9
    #48 0x7fd8dc58109d in TickDriver layout/base/nsRefreshDriver.cpp:279:13
    #49 0x7fd8dc58109d in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) layout/base/nsRefreshDriver.cpp:251
    #50 0x7fd8dc580cf9 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:270:5
    #51 0x7fd8dc582c94 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyVsync(mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:430:9
    #52 0x7fd8dcf0c2c4 in mozilla::layout::VsyncChild::RecvNotify(mozilla::TimeStamp const&) layout/ipc/VsyncChild.cpp:64:16
    #53 0x7fd8d6823059 in mozilla::layout::PVsyncChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PVsyncChild.cpp:240:20
    #54 0x7fd8d62a1814 in mozilla::ipc::PBackgroundChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PBackgroundChild.cpp:2133:28
    #55 0x7fd8d61cd566 in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) ipc/glue/MessageChannel.cpp:1661:25
    #56 0x7fd8d61c9c87 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) ipc/glue/MessageChannel.cpp:1599:17
    #57 0x7fd8d61b6dff in mozilla::ipc::MessageChannel::OnMaybeDequeueOne() ipc/glue/MessageChannel.cpp:1566:5
    #58 0x7fd8d61e8152 in applyImpl<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:729:12
    #59 0x7fd8d61e8152 in apply<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:735
    #60 0x7fd8d61e8152 in mozilla::detail::RunnableMethodImpl<bool (mozilla::ipc::MessageChannel::*)(), false, true>::Run() objdir-ff-asan/dist/include/nsThreadUtils.h:764
    #61 0x7fd8d61e773f in Run objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:550:29
    #62 0x7fd8d61e773f in mozilla::ipc::MessageChannel::DequeueTask::Run() objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:569
    #63 0x7fd8d53e8802 in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1068:14
    #64 0x7fd8d54684d8 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/glue/nsThreadUtils.cpp:290:10
    #65 0x7fd8d61d4d51 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:100:21
    #66 0x7fd8d61478f0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
    #67 0x7fd8d61478f0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
    #68 0x7fd8d61478f0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
    #69 0x7fd8dbec0e2f in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27
    #70 0x7fd8ddfe49c7 in XRE_RunAppShell toolkit/xre/nsEmbedFunctions.cpp:851:22
    #71 0x7fd8d61478f0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
    #72 0x7fd8d61478f0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
    #73 0x7fd8d61478f0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
    #74 0x7fd8ddfe4088 in XRE_InitChildProcess toolkit/xre/nsEmbedFunctions.cpp:681:34
    #75 0x510ae1 in content_process_main ipc/contentproc/plugin-container.cpp:224:19
    #76 0x510ae1 in main browser/app/nsBrowserApp.cpp:357
    #77 0x7fd8ef154f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
AddressSanitizer can not describe address in more detail (wild memory access suspected).
SUMMARY: AddressSanitizer: heap-buffer-overflow (/mnt/scratch0/clusterfuzz/slave-bot/builds/linux_asan_firefox/custom/firefox/firefox-bin+0x4bea3b)
Shadow bytes around the buggy address:
  0x0c4680003fe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680003ff0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c4680004030: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
  0x0c4680004040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4680004080: 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==13447==ABORTING

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the edge rasteriser in pixman computed a span length from the trapezoid geometry without checking it against the destination buffer bounds, so a memset wrote past the allocation.

Impact

A malicious SVG could trigger a heap buffer overflow in the content process, potentially leading to memory corruption or code execution, though the report only demonstrates a crash under AddressSanitizer.

What the attacker needed

Victim opens a crafted SVG

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a browser draws a shape, it fills in pixels along the shape's edges. A bug in that drawing code let it write past the end of a memory buffer, which is like painting outside the canvas onto whatever is next to it. If an attacker controls the shape, they may be able to overwrite nearby memory and potentially run their own code.

What is Memory corruption?

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

More by Abhishek Arya

View all

130 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.