Skip to content
Memory corruption Disclosed report Advanced

Heap-buffer-overflow in mozilla::gfx::TiledRegionImpl::AddRect

A heap buffer overflow occurs in Firefox's TiledRegionImpl::AddRect when processing a crafted SVG file. An attacker could potentially cause a crash or execute arbitrary code by tricking a user into opening the malicious SVG.

Atte Kettunen Follow

Originally disclosed on Mozilla

  • Fixed in 19 days
  • Paid in 17 days
  • Disclosed after 19 days
Text
Created attachment 8767133
firefox-heap-buffer-overflow-mozillagfxTiledRegionImplAddRect.svg

Tested on:

OS: Ubuntu 14.04

Firefox: ASAN build from https://ftp.mozilla.org/pub/firefox/tinderbox-builds/mozilla-central-linux64-asan/1467364703/


ASAN-trace:

==24606==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000590080 at pc 0x7efcd8efde1a bp 0x7ffc5e1a03b0 sp 0x7ffc5e1a03a8
WRITE of size 8 at 0x619000590080 thread T0 (Web Content)
    #0 0x7efcd8efde19 in mozilla::gfx::TiledRegionImpl::AddRect(pixman_box32 const&)::$_0::operator()(nsTArray<pixman_box32>&, unsigned long&, mozilla::gfx::TileRange) const /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:291:26
    #1 0x7efcd8edb120 in ProcessIntersectedTiles<(lambda at /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:284:5), (lambda at /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:295:5), nsTArray<pixman_box32> > /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:231:11
    #2 0x7efcd8edb120 in mozilla::gfx::TiledRegionImpl::AddRect(pixman_box32 const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:283
    #3 0x7efcd916696a in mozilla::gfx::TiledRegion<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> >::Add(mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/mozilla/gfx/TiledRegion.h:122:12
    #4 0x7efcd915a953 in mozilla::layers::BasicPaintedLayer::InvalidateRegion(mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/layers/basic/BasicPaintedLayer.h:57:5
    #5 0x7efcddb8bcfe in InvalidatePostTransformRegion /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:1734:3
    #6 0x7efcddb8bcfe in mozilla::FrameLayerBuilder::ComputeGeometryChangeForItem(mozilla::FrameLayerBuilder::DisplayItemData*) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:4384
    #7 0x7efcddb8a29e in mozilla::FrameLayerBuilder::WillEndTransaction() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:1898:7
    #8 0x7efcddbafd18 in mozilla::FrameLayerBuilder::AddPaintedDisplayItem(mozilla::PaintedLayerData*, nsDisplayItem*, mozilla::DisplayItemClip const&, mozilla::ContainerState&, mozilla::LayerState, nsPoint const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:4480:7
    #9 0x7efcddb9571a in FinishPaintedLayerData<(lambda at /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:2745:50)> /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:3040:5
    #10 0x7efcddb9571a in mozilla::PaintedLayerDataNode::PopPaintedLayerData() /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/layout/base/FrameLayerBuilder.cpp:2745
.
.
.
0x619000590080 is located 0 bytes to the right of 1024-byte region [0x61900058fc80,0x619000590080)
allocated by thread T0 (Web Content) here:
    #0 0x4b553e in realloc /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:71:3
    #1 0x7efcd6bd646d in Realloc /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/nsTArray.h:169:12
    #2 0x7efcd6bd646d in nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/nsTArray-inl.h:183
    #3 0x7efcd8efd7dd in InsertSlotsAt<nsTArrayFallibleAllocator> /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/nsTArray-inl.h:286:3
    #4 0x7efcd8efd7dd in InsertElementsAt<nsTArrayFallibleAllocator> /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/nsTArray.h:1828
    #5 0x7efcd8efd7dd in InsertElementsAt /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/nsTArray.h:1849
    #6 0x7efcd8efd7dd in mozilla::gfx::TiledRegionImpl::AddRect(pixman_box32 const&)::$_0::operator()(nsTArray<pixman_box32>&, unsigned long&, mozilla::gfx::TileRange) const /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:285
    #7 0x7efcd8edb120 in ProcessIntersectedTiles<(lambda at /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:284:5), (lambda at /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:295:5), nsTArray<pixman_box32> > /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:231:11
    #8 0x7efcd8edb120 in mozilla::gfx::TiledRegionImpl::AddRect(pixman_box32 const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/src/TiledRegion.cpp:283
    #9 0x7efcd916696a in mozilla::gfx::TiledRegion<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> >::Add(mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/obj-firefox/dist/include/mozilla/gfx/TiledRegion.h:122:12
    #10 0x7efcd915a953 in mozilla::layers::BasicPaintedLayer::InvalidateRegion(mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&) /builds/slave/m-cen-l64-asan-ntly-0000000000/build/src/gfx/layers/basic/BasicPaintedLayer.h:57:5
.
.
.

The original report as published on Mozilla's Bugzilla, by Atte Kettunen. 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 an off-by-one or incorrect bounds check in the tile processing logic of TiledRegionImpl::AddRect, leading to a write beyond the allocated array.

Impact

A crafted SVG could cause a heap buffer overflow, potentially leading to a crash or arbitrary code execution.

What the attacker needed

Victim opens a malicious SVG file

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.

This is a memory corruption bug in Firefox's graphics code. When Firefox tries to draw a specially crafted SVG image, it writes data past the end of a memory buffer, which can crash the browser or let an attacker 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 Atte Kettunen

View all

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