From cefc2a7baa9a4dba878352ebc3a5c92b63ed295a Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 10 Apr 2020 16:21:51 +0200 Subject: [PATCH] DiscIO: Fix edge case where blocks could get scrubbed accidentally If we start 31 KiB into a 32 KiB block and want to mark 2 KiB of data as used, we need to mark 2 blocks as used, not just 1. This problem is avoided when calling MarkAsUsed from MarkAsUsedE, since MarkAsUsedE aligns to 32 KiB on its own. Most calls to MarkAsUsed are from MarkAsUsedE, which is why this hasn't been a noticeable problem in the past. --- Source/Core/DiscIO/DiscScrubber.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp index 07d504d72a..706a2cd00d 100644 --- a/Source/Core/DiscIO/DiscScrubber.cpp +++ b/Source/Core/DiscIO/DiscScrubber.cpp @@ -58,8 +58,8 @@ bool DiscScrubber::CanBlockBeScrubbed(u64 offset) const void DiscScrubber::MarkAsUsed(u64 offset, u64 size) { - u64 current_offset = offset; - const u64 end_offset = current_offset + size; + u64 current_offset = Common::AlignDown(offset, CLUSTER_SIZE); + const u64 end_offset = offset + size; DEBUG_LOG(DISCIO, "Marking 0x%016" PRIx64 " - 0x%016" PRIx64 " as used", offset, end_offset);