This is CVE-2026-86476, a heap buffer overflow I reported in GStreamer’s video library, libgstvideo, part of gst-plugins-base. A GstVideoMeta describes how the pixels of a video frame are laid out in memory. When that description arrives from a source you do not trust, nothing checks that it fits inside the buffer it claims to describe. That is the whole bug, and the rest of this post is where it lives and how far it goes.
A separate post covers how I found it, including the piece of the exploit chain I do not get credit for. This one is about the code.
At a glance
| Field | Value |
|---|---|
| Class | CWE-125 and CWE-787, reached through CWE-502 (deserialization of untrusted data) |
| Impact | Out-of-bounds read (confirmed), out-of-bounds write to code execution (demonstrated) |
| Component | libgstvideo: gstvideometa.c, video-frame.c |
| Trigger | A GstVideoMeta with fabricated plane strides, deserialized from a unixfd peer |
| Fault site | video_orc_convert_I420_BGRA, the videoconvert ORC kernel |
What a GstVideoMeta is for
A raw video frame is not a flat blob of pixels. It has planes. In I420, for instance, the Y, U, and V components sit in three separate regions, each with a stride (how many bytes one row takes, padding included) and an offset (where the plane starts inside the buffer). GstVideoMeta is the structure that records all of this so the next element in the pipeline knows how to read the frame.
Two things about that structure drive the bug.
First, the meta overrides the caps. When a frame is mapped, the geometry in the meta wins over the format negotiated in the pipeline. The meta is the source of truth.
Second, the meta can travel. On the unixfd path, a producer process serializes its buffers’ metas to a byte stream and a consumer process rebuilds them. If the peer is hostile, that byte stream is attacker input.
Put those together. You have a structure that decides how much memory a consumer reads, rebuilt from untrusted bytes, and the only thing between it and a heap overflow is validation. There is almost none.
Root cause: three checks that are not there
1. The meta branch of the frame map has no size check
gst_video_frame_map_id() in video-frame.c has two branches. The no-meta branch, lower down, ends with the check that counts:
/* no-meta branch */
if (frame->map[0].size < info->size)
goto invalid_size;
That line says the memory you handed me is at least as large as the format says it should be. The meta branch, taken whenever a GstVideoMeta is present, never does the equivalent:
if (meta) {
g_return_val_if_fail (info->finfo->format == meta->format, FALSE);
g_return_val_if_fail (info->width <= meta->width, FALSE);
g_return_val_if_fail (info->height <= meta->height, FALSE);
g_return_val_if_fail (info->finfo->n_planes == meta->n_planes, FALSE);
frame->info.width = meta->width; /* meta overrides caps */
frame->info.height = meta->height;
for (i = 0; i < meta->n_planes; i++) {
frame->info.offset[i] = meta->offset[i];
gst_video_meta_map (meta, i, &frame->map[i], &frame->data[i],
&frame->info.stride[i], flags);
}
}
The only constraints are info->width <= meta->width and info->height <= meta->height. Those are lower bounds. They stop the meta from being too small for the negotiated format. They do nothing to stop it from being enormous. Nothing here compares the plane geometry against the size of the real memory.
2. default_map() checks exactly one byte per plane
So where does the plane memory get resolved? In default_map() in gstvideometa.c, and this is the center of the whole thing:
offset = meta->offset[plane];
/* FIXME use plane size */
if (!gst_buffer_find_memory (buffer, offset, 1, &idx, &length, &skip))
goto no_memory;
if (!gst_buffer_map_range (buffer, idx, length, info, flags))
goto cannot_map;
*stride = meta->stride[plane];
*data = (guint8 *) info->data + skip;
Look at the size argument to gst_buffer_find_memory(). It is 1. The code proves that a single byte exists at the plane’s start offset and stops there. The stride is copied out as is, the height never enters the calculation, and the real extent of the plane, stride * height, is never compared against the allocation. There is even a FIXME use plane size sitting right above the one-byte check. Someone knew.
Set every plane offset to 0 and all three planes resolve to the same first byte. The one-byte check passes three times, and gst_video_frame_map() returns TRUE for a buffer whose backing is a handful of bytes.
3. The deserializer range-checks nothing
The first two make an in-process mistake exploitable. The third makes it reachable across a trust boundary. video_meta_deserialize() in gstvideometa.c rebuilds a GstVideoMeta from a byte stream and validates only three things:
- that the byte reader did not run out of input,
- that
n_planes <= GST_VIDEO_MAX_PLANES, - that
version != 0.
Offsets and strides are copied straight out of the stream, unchecked. Each stride is read as a signed gint32, so a negative stride is accepted and carried forward.
On the receiving side, gst_unix_fd_src_create() deserializes the metas first, against an empty buffer, and attaches the peer’s memory afterward. The stride the meta carries and the size of the memory that ends up backing the buffer are never compared. The meta is believed before the memory it describes even exists.
The overflow
Chain the three gaps.
A hostile peer serializes a GstVideoMeta for a 320x240 I420 frame but sets every plane stride to 1000000. The consumer deserializes it with no range check, attaches the small real memory, and maps the frame. default_map() is satisfied because the first byte of each plane exists. Then videoconvert has to produce output, so it reads each input plane for stride * height bytes, where stride is the attacker’s 1000000, and walks far past the real allocation.
That is the read. The write is the mirror image. gst_video_frame_copy_plane() does this:
if (PLANE_STRIDE (dinfo, plane) == PLANE_STRIDE (sinfo, plane)) {
memcpy (dp, sp, PLANE_STRIDE (dinfo, plane) * h); /* lying stride * height */
} else {
for (j = 0; j < h; j++) { memcpy (dp, sp, w); ... }
}
When a small buffer carrying the lying meta is the destination of such a copy, the memcpy writes stride * height bytes into a few bytes of backing. Heap overflow, write side.
Reproduction
The reproducer uses stock elements only. Two processes over a unix socket.
The sender is fakesrc ! capsfilter ! unixfdsink. It pushes a valid 320x240 I420 buffer with real strides 320/160/160, but attaches a GstVideoMeta whose plane strides are 1000000.
The receiver is unixfdsrc ! videoconvert ! capsfilter ! fakesink. The capsfilter forces I420 to BGRA so videoconvert cannot pass the buffer through untouched and has to read it by the meta strides.
Two runs that differ only in the strides the meta carries:
| Run | Meta strides | Result |
|---|---|---|
| 1 | 1000000 / 1000000 / 1000000 | out-of-bounds READ under ASan inside video_orc_convert_I420_BGRA |
| 2 | 320 / 160 / 160 (real layout) | normal completion, buffer reaches fakesink |
A receiver-side probe confirms the oversized strides survive the IPC round trip unchanged and reach videoconvert. Build GStreamer with -Db_sanitize=address and run 1 reports a heap-buffer-overflow READ at the point where the frame is read by the meta strides.
The honest boundary: crash versus write primitive
This is the part I want to be precise about, because it is easy to overstate.
The fully stock pipeline above gives you an out-of-bounds read that crashes the receiver. It is not, by itself, the heap-adjacent write that a real exploit wants. The reason is a detail of how unixfd moves non-FD buffers. unixfdsink copies them into shared memory, so on the receiver the pixel backing is an mmap’d memfd, and videoconvert reads it, by the lying stride, into a correctly sized output buffer. That is a crash and an information leak against a mapping boundary. Serious, but a read.
To show the write side is real, the PoC drives the same deserializer with the same untrusted bytes, but places the resulting meta on a small heap buffer so the copy’s destination is heap memory. Now the lying stride overflows a real heap allocation and you have the write. The point of the exercise is that one untrusted serialized GstVideoMeta is enough to reach memory corruption. The transport decides whether you land on a memfd boundary (read) or on the heap (write). It does not decide whether the bug exists.
From the write to code execution
With a heap write, the PoC does something GStreamer-flavoured rather than generic. It overwrites the function pointer that lives in the header of a neighbouring reference-counted object, the free field of a GstMiniObject, then triggers an unref so that forged pointer gets called. The command string is placed where it lands in the first argument register on that call, so the call becomes system("...").
[+] deserialized GstVideoMeta: ok (consumed=74)
[+] overwriting victim->free = 0x7fc16d043490 via OOB memcpy...
[+] victim->free now = 0x7fc16d043490
[+] triggering unref...
uid=1000(kali) gid=1000(kali) groups=... <-- system() ran "id"
That is code execution, not a crash. It assumes you can place the forged pointer, and placing it means knowing where system() is at runtime, which is the next problem.
The ASLR piece, and the credit that is not mine
To turn one leaked pointer into the runtime address of system() without dlsym and without reading /proc/self/maps, the chain resolves offsets statically. It goes from a leaked libgstreamer pointer back to the library base, through a GOT slot that is bound eagerly at load time (__cxa_finalize, picked on purpose: it is a function, so it is immune to copy relocations; it is not an IFUNC, so its offset is fixed; and it is a GLOB_DAT in .rela.dyn, so it resolves at load whether the binary is lazy or BIND_NOW), into libc, and from libc to system. It holds across ASLR runs.
Why __cxa_finalize and not the obvious choices
The slot you resolve through matters, and most of the obvious candidates fail for reasons worth writing down, because they are the same reasons any libc-base resolver has to think about.
stderr, stdout, and stdin are libc data symbols, so they are subject to copy relocations. If the host executable references one, its GOT slot points into the executable’s .bss, not into libc. Unreliable.
strcmp, memcpy, memset, strlen, and friends are IFUNCs. The GOT resolves to whichever implementation the CPU selected at load, at an offset that is not fixed across CPUs or builds. Unreliable.
The malloc and free JUMP_SLOTs inside libgstreamer stay at their PLT trampolines, because GStreamer allocates through glib’s g_malloc and g_free and never calls them through its own PLT. Unreliable, and lazy. __errno_location is a lazy JUMP_SLOT too, so it only works once it has already been called.
__cxa_finalize is a function, so copy relocations do not touch it. It is not an IFUNC, so its offset is fixed. It is a GLOB_DAT, so it is resolved eagerly regardless of lazy binding. Every gcc or clang built shared object references it for atexit and destructor teardown, so the slot is always present. That is why it is the one that works.
Fix direction
All three gaps want closing.
In default_map(), replace the one-byte gst_buffer_find_memory(..., 1, ...) with a real plane-size check against the stride * (plane height) extent, so a plane that does not fit fails to map. That is exactly what the FIXME asks for.
Give the meta branch of gst_video_frame_map_id() the same invalid_size check the no-meta branch already has.
In video_meta_deserialize(), range-check offsets and strides against the buffer, and reject negative strides instead of reading them signed and trusting them.
Any one of these alone breaks the chain. All three is the right answer for a structure that routinely crosses a trust boundary.
Who this touches
Any pipeline that accepts video buffers over unixfd from a process it does not fully trust is exposed. Sandboxed media decoders, portal-style split pipelines, and anything else that uses unixfdsrc to receive frames across a privilege or trust boundary. The meta is believed, the memory is attached afterward, and the mismatch is never checked. Until the plane-size validation lands, treat a unixfd peer as able to crash the consumer whenever it likes, and depending on how buffers get allocated downstream, as a candidate for worse.