From 66b6bae59689bba3f4928335eb3dafcfaf77ec0d Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 2 Sep 2023 11:01:38 +0300 Subject: [PATCH] Win32/File.cpp: Avoid potential race in concurrent writes Uninitialized data is better than overwritten data. Affects SPU Cache (unprotected writes). --- Utilities/File.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 4f0094d23d..4d1d9acd2a 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1303,12 +1303,12 @@ fs::file::file(const std::string& path, bs_t mode) DWORD nwritten = 0; OVERLAPPED ovl{}; - const u64 pos = m_pos; + const u64 pos = m_pos.fetch_add(size); ovl.Offset = DWORD(pos); ovl.OffsetHigh = DWORD(pos >> 32); ensure(WriteFile(m_handle, data, size, &nwritten, &ovl)); // "file::write" + ensure(nwritten == size); nwritten_sum += nwritten; - m_pos += nwritten; if (nwritten < size) {