From 678c07a9efada2937b29006a00909a7557dacdf3 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:32:27 -0500 Subject: [PATCH] RR runtime: set_device checks the result of Map on the completion marker set_device mapped the 256-byte readback buffer used as the completion marker and ignored the result; a failed Map left the pointer null and the writes right after it dereferenced null. A failed Map now drops the device and returns WG_E_D3D_API, as the Model M runtime does. drop_device unmaps the marker only if it was mapped. Fixes #67 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/rr_f/runtime/src/rr_runtime.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clean/rr_f/runtime/src/rr_runtime.cpp b/clean/rr_f/runtime/src/rr_runtime.cpp index c642a468..18e73be3 100644 --- a/clean/rr_f/runtime/src/rr_runtime.cpp +++ b/clean/rr_f/runtime/src/rr_runtime.cpp @@ -1091,7 +1091,7 @@ void drop_device() { release(rt.rm_fence); if (rt.rm_ev) CloseHandle(rt.rm_ev), rt.rm_ev = nullptr; if (rt.rm_quit) CloseHandle(rt.rm_quit), rt.rm_quit = nullptr; - if (rt.marker) rt.marker->Unmap(0, nullptr); + if (rt.marker && rt.marker_map) rt.marker->Unmap(0, nullptr); // only a buffer that was mapped (set_device's Map can fail) rt.marker_map = nullptr; drop(rt.marker); release(rt.l); @@ -1264,7 +1264,11 @@ uint32_t set_device_locked(ID3D12Device* given) { { void* m = nullptr; D3D12_RANGE r{0, 256}; - rt.marker->Map(0, &r, &m); + // Issue #67: a failed Map leaves m null; the writes below would dereference it (the Model M runtime checks it too). + if (FAILED(rt.marker->Map(0, &r, &m)) || !m) { + drop_device(); + return WG_E_D3D_API; + } rt.marker_map = (volatile uint32_t*)m; *rt.marker_map = 0; rt.marker_map[2] = rt.marker_map[3] = 0;