Skip to content
Info disclosure Disclosed report Advanced CVE-2026-5733

WebGPU canvas toBlob/toDataURL leaks uninitialized heap on macOS (stride vs packed memcpy)

A WebGPU canvas snapshot routine copied pixel data with a flat memcpy that ignored the surface row stride, so row-padding bytes from an uninitialised malloc'd buffer were treated as pixels. An attacker could export a canvas via toBlob or toDataURL and read leftover heap contents embedded in the resulting image.

Inseo An Follow

Originally disclosed on Mozilla

  • Fixed in 15 days
  • Paid in 21 days
  • Disclosed after 15 days
Text
Created attachment 9551859
poc_webgpu_padding.html

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15

Steps to reproduce:

I was looking at how WebGPU canvas snapshots get exported and noticed that
gfxUtils::GetImageBuffer() does a flat memcpy of width*height*4 bytes from
a mapped DataSourceSurface, ignoring the surface stride. On macOS that stride
can be larger than width*4 (32-byte alignment in ComputeRGBStride), so the
flat copy picks up row-padding bytes as if they were pixels.

The interesting part: when the canvas uses alphaMode:"premultiplied", the
snapshot surface format is B8G8R8A8. That format doesn't trigger the
clearSurface path in Factory::CreateDataSourceSurfaceWithStride (line 945 —
clearSurface = aZero || format==B8G8R8X8, both false), so the backing comes
straight from malloc() with no zeroing. SwizzleData only writes width*4 bytes
per row into that surface, leaving the padding as whatever malloc returned.

Then GetImageBuffer flattens it and hands those bytes to the PNG/JPEG encoder,
and they end up in the blob/data URL returned to script.

Confirmed on Firefox 148.0.2 (aarch64) on macOS 14.4 (23E214).
Source analysis against mozilla-central at 150.0a1.

Steps:

1. macOS Firefox with WebGPU enabled (dom.webgpu.enabled = true)
2. Serve the attached PoC over https or localhost
3. Click "Run" — it creates a 1x64 WebGPU canvas with alphaMode:"premultiplied",
   renders solid green, exports via toBlob("image/png"), decodes the result,
   and compares pixels
4. On a vulnerable build most of the 64 decoded pixels won't be green — they're
   whatever was in the malloc'd surface padding

Width=1 is the worst case: stride=32, pixel data=4 bytes/row, so 28 out of
every 32 bytes are padding. The flat memcpy reads 256 bytes total (1*64*4)
which covers only 8 surface rows, meaning 224 of 256 bytes (87.5%) are
uninitialized heap.

Any width that isn't a multiple of 8 will leak some padding. An attacker can
vary the canvas dimensions and call toBlob() repeatedly to sample different
heap allocation sizes.


Actual results:

Exported image pixels don't match what was drawn. The non-pixel padding bytes
from the DataSourceSurface appear in the packed output because GetImageBuffer
ignores stride.

The allocation chain that leaves padding uninitialized:

  CanvasManagerChild::GetSnapshot (gfx/ipc/CanvasManagerChild.cpp:270-272)
    -> CreateDataSourceSurfaceWithStride(size, B8G8R8A8, stride, aZero=false)

  Factory.cpp:945
    -> clearSurface = false || (B8G8R8A8 == B8G8R8X8) = false

  SourceSurfaceRawData.cpp:83,89
    -> zeroMem = false
    -> AlignedArray::Realloc(bufLen, false) -> malloc()

  SwizzleData (Swizzle.cpp:759-767)
    -> copies width*4 bytes per row, skips padding

  gfxUtils::GetImageBuffer (gfxUtils.cpp:1519-1526)
    -> memcpy(imageBuffer.get(), map.mData, width * height * 4)
    -> ignores map.mStride, reads across row boundaries into padding


Expected results:

GetImageBuffer should respect the surface stride. There's already a
CopySurfaceDataToPackedArray() in gfx/2d/DataSurfaceHelpers.cpp:107 that
does row-by-row packing — using that instead of the flat memcpy would fix it.

As a belt-and-suspenders fix, passing aZero=true at CanvasManagerChild.cpp:272
would zero the surface backing so padding is at least zeroed even if another
consumer makes the same stride mistake.

The original report as published on Mozilla's Bugzilla, by Inseo An. 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 a flat memcpy in gfxUtils::GetImageBuffer that ignores the DataSourceSurface stride, combined with a non-zeroed B8G8R8A8 surface whose padding is never written by SwizzleData.

Impact

Exported canvas images could contain uninitialised heap bytes, potentially disclosing leftover memory contents to script; the report demonstrates the mismatch on macOS only.

What the attacker needed

MacOS Firefox with WebGPU enabled; victim loads attacker page; canvas width not a multiple of 8

The fix

GetImageBuffer should pack rows using the existing CopySurfaceDataToPackedArray helper, and as a secondary measure the snapshot surface should be allocated zeroed.

How it was found

  1. Enable WebGPU in Firefox on macOS and serve the proof-of-concept page over https or localhost.
  2. Click Run to create a 1x64 WebGPU canvas with premultiplied alpha and render solid green.
  3. Export the canvas with toBlob as PNG and decode the returned image.
  4. Compare the decoded pixels against the green that was drawn.

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.

Images in memory are often stored with a few extra bytes at the end of each row so rows line up neatly; these are called padding. The code that exported the canvas copied the whole block as if it were solid pixels, so the padding, which had never been written to, ended up in the saved image. Because that memory came from a fresh allocation, it could still hold data left over from other parts of the browser.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Inseo An

View all

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

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.