diff --git a/host/platform/Windows/capture/D12/backend/dd.c b/host/platform/Windows/capture/D12/backend/dd.c index 3e654900..6a5bf372 100644 --- a/host/platform/Windows/capture/D12/backend/dd.c +++ b/host/platform/Windows/capture/D12/backend/dd.c @@ -78,6 +78,7 @@ typedef struct DDInstance void * shapeBuffer; unsigned shapeBufferSize; + unsigned shapeSize; } DDInstance; @@ -424,7 +425,7 @@ retry: &pointer, frameInfo.PointerShapeBufferSize, &postPointer); if (postPointer) - d12_updatePointer(&pointer, this->shapeBuffer, this->shapeBufferSize); + d12_updatePointer(&pointer, this->shapeBuffer, this->shapeSize); // if this was not a frame update, go back and try again if (frameInfo.LastPresentTime.QuadPart == 0) @@ -714,6 +715,13 @@ retry: return; } + if (!s || s > this->shapeBufferSize || !info.Height || !info.Pitch || + (size_t)info.Height > (size_t)s / info.Pitch) + { + DEBUG_ERROR("Desktop duplication returned an invalid pointer shape"); + return; + } + switch(info.Type) { case DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR: @@ -739,6 +747,7 @@ retry: pointer->pitch = info.Pitch; pointer->hx = info.HotSpot.x; pointer->hy = info.HotSpot.y; + this->shapeSize = s; *changed = true; } diff --git a/host/platform/Windows/capture/D12/d12.c b/host/platform/Windows/capture/D12/d12.c index fdf4feaa..fd462bdd 100644 --- a/host/platform/Windows/capture/D12/d12.c +++ b/host/platform/Windows/capture/D12/d12.c @@ -1613,9 +1613,13 @@ void d12_updatePointer(CapturePointer * pointer, void * shape, size_t shapeSize) DEBUG_ERROR("Failed to obtain a buffer for the pointer shape"); pointer->shapeUpdate = false; } - - size_t copySize = min(dstSize, shapeSize); - memcpy(dst, shape, copySize); + else if (!shape || !shapeSize || shapeSize > dstSize) + { + DEBUG_ERROR("Pointer shape does not fit in the destination buffer"); + pointer->shapeUpdate = false; + } + else + memcpy(dst, shape, shapeSize); } this->postPointerBufferFn(pointer);