
Write-up and exploit for a Windows Search heap buffer overflow (CVE-2026-50679) achieving local privilege escalation via CVIQuery vtable hijack and DLL loading.
In June this year I found this heap overflow in Windows Search, and I realized it was exploitable. I spent a few days working on it and managed to achieve LPE. When I submitted it, I was told that it was a duplicate :(. It was fixed in the July Patch Tuesday and tracked by Microsoft as CVE-2026-50679. Either way, the exploitation process was a lot of fun.
CPMExternalSearchResultIn (message 245) feeds an external search result into an existing query. Its body is three DWORDs followed by three UTF-16 strings, and each string is described by a length embedded in the body:
WSP_MESSAGE_HEADER 16 bytes
queryNameLength 4 bytes
currentRowsetIndex 4 bytes
remainingRowsetCount 4 bytes
queryName queryNameLength UTF-16 chars, null-terminated
rowset metadata rowsetMetadata, rowsetNameLength, sourceNameLength (12 bytes)
rowsetName rowsetNameLength UTF-16 chars, null-terminated
sourceName sourceNameLength UTF-16 chars, null-terminated
All three lengths come from the client. The transport knows how many bytes arrived, but nothing in the message format ties the declared lengths to that number.
Before a message reaches a handler, tquery!CProxyMessage::ValidateInputHeader checks the header. It verifies the message id, the reserved fields, the checksum, and the minimum message size for that id. But it does not check whether the strings lengths declared in the message exceed the size of the message buffer.
The message is then dispatched to tquery!CRequestServer::DoSetExternalRowset. The handler allocates a destination buffer from the outer message length and decodes the inline buffer into it:
__int64 __fastcall CRequestServer::DoSetExternalRowset(CRequestServer *this, unsigned int msgSize)
{
/* ... */
BYTE *buffer = (BYTE *)operator new[](https://github.com/h4urek/cve-2026-50679/blob/main/msgSize); /* outer message length */
CPMExternalSearchResultIn *decoded =
CPMExternalSearchResultIn::CPMExternalSearchResultIn(buffer, this + 0x270);
/* src = inline request buffer */
/* ... */
}
The constructor is where the embedded lengths are used:
CPMExternalSearchResultIn::CPMExternalSearchResultIn(BYTE *dst, BYTE *src)
{
/* dst: buffer sized by the outer message length */
/* src: per-connection inline request buffer */
/* ... */
DWORD queryNameLength = *(DWORD *)(src + 0x10);
*(DWORD *)(dst + 0x10) = queryNameLength;
*(DWORD *)(dst + 0x14) = *(DWORD *)(src + 0x14);
*(DWORD *)(dst + 0x18) = *(DWORD *)(src + 0x18);
memcpy(dst + 0x1c, src + 0x1c, 2 * (queryNameLength + 1));
DWORD rowsetNameLength = *(DWORD *)(src + 2 * queryNameLength + 0x22);
memcpy(dst + 2 * queryNameLength + 0x2a,
src + 2 * queryNameLength + 0x2a,
2 * (rowsetNameLength + 1));
DWORD sourceNameLength = *(DWORD *)(src + 2 * queryNameLength + 0x26);
memcpy(dst + 2 * queryNameLength + 2 * rowsetNameLength + 0x2c,
src + 2 * queryNameLength + 2 * rowsetNameLength + 0x2c,
2 * (sourceNameLength + 1));
/* ... */
}
The first copy is the obvious one. dst was allocated from the outer message length; the copy length comes from queryNameLength; nothing compares the two. The copy can be far larger than the allocation, and because its source is the inline buffer, it also runs past the bytes that actually arrived. The rest of the source is whatever the connection buffer held from earlier traffic.
The two later strings are worse. rowsetNameLength is read from src + 2 * queryNameLength + 0x22, an offset computed from the attacker-controlled queryNameLength, and sourceNameLength is read from a nearby offset. Both are outside the fixed part of the message, so the decoder reads whatever is there, treats it as a length, and copies again. One small message therefore produces several out-of-bounds reads and writes, and none of the lengths is ever compared with the destination allocation.
Exploiting this bug came down to a few questions: which object to corrupt and hijack the control flow, where to redirect that control flow, and how to get around the LFH heap.
After some reversing I found a suitable object to hijack: CVIQuery. CVIQuery is the server-side object behind an open query. When the client sends a query request, the server creates a corresponding CVIQuery object, and its first field is the object's vtable, so corrupting this object gives a vtable hijack.
The heap was the next obstacle. CVIQuery is allocated from the LFH heap, so I wanted to overcome LFH randomization by spraying a large number of these objects. The good part is that every query request creates one CVIQuery, which gives a convenient heap spray primitive. However, wsearch limits the maximum number of open requests to 4096, so the spray count is limited, but that was enough; it just takes a bit of luck :).
Finally I needed to decide where to redirect control flow. I did some searching but did not find a suitable technique, so I decided to find one myself. I soon found a DLL loaded by the wsearch service: dxcore.dll, and its DXCoreDriver::LoadDriverModule function looked very interesting:

This function dereferences this + 0x30 as a DLL path string and calls LoadLibraryW to load that DLL. So it is enough to overflow the CVIQuery and hijack its vtable, then keep overflowing to write the DLL path at CVIQuery + 0x30, and arbitrary DLL loading follows.
A very handy trick. By the way, when I built the exploit this function only existed in Insider builds, but I have noticed that it has recently appeared in release builds as well.