From 058c7db80b074fa52aaa504329ee69cf25a516e3 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 11 Dec 2020 23:04:32 -0800 Subject: Software: Fix out of bounds accesses in CopyRegion Fixes issue 11393. The problem is that left and top make no sense for a width by height array; they only make sense in a larger array where from which a smaller part is extracted. Thus, the overall size of the array is provided to CopyRegion in addition to the sub-region. EncodeXFB already handles the extraction, so CopyRegion's only use there is to resize the image (and thus no sub-region is provided). --- Source/Core/VideoBackends/Software/SWTexture.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'Source/Core/VideoBackends/Software/SWTexture.cpp') diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index 466da1efd5..eda833c56f 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -56,15 +56,10 @@ void SWRenderer::ScaleTexture(AbstractFramebuffer* dst_framebuffer, const SWTexture* software_source_texture = static_cast(src_texture); SWTexture* software_dest_texture = static_cast(dst_framebuffer->GetColorAttachment()); - std::vector source_pixels; - source_pixels.resize(src_rect.GetHeight() * src_rect.GetWidth() * 4); - memcpy(source_pixels.data(), software_source_texture->GetData(), source_pixels.size()); - - std::vector destination_pixels; - destination_pixels.resize(dst_rect.GetHeight() * dst_rect.GetWidth() * 4); - - CopyRegion(source_pixels.data(), src_rect, destination_pixels.data(), dst_rect); - memcpy(software_dest_texture->GetData(), destination_pixels.data(), destination_pixels.size()); + CopyRegion(reinterpret_cast(software_source_texture->GetData()), src_rect, + src_texture->GetWidth(), src_texture->GetHeight(), + reinterpret_cast(software_dest_texture->GetData()), dst_rect, + dst_framebuffer->GetWidth(), dst_framebuffer->GetHeight()); } SWTexture::SWTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config) -- cgit v1.2.3