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).
This commit is contained in:
Pokechu22
2020-12-11 23:04:32 -08:00
parent 089250fde6
commit 058c7db80b
3 changed files with 43 additions and 32 deletions

View File

@ -56,15 +56,10 @@ void SWRenderer::ScaleTexture(AbstractFramebuffer* dst_framebuffer,
const SWTexture* software_source_texture = static_cast<const SWTexture*>(src_texture);
SWTexture* software_dest_texture = static_cast<SWTexture*>(dst_framebuffer->GetColorAttachment());
std::vector<Pixel> 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<Pixel> 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<const Pixel*>(software_source_texture->GetData()), src_rect,
src_texture->GetWidth(), src_texture->GetHeight(),
reinterpret_cast<Pixel*>(software_dest_texture->GetData()), dst_rect,
dst_framebuffer->GetWidth(), dst_framebuffer->GetHeight());
}
SWTexture::SWTexture(const TextureConfig& tex_config) : AbstractTexture(tex_config)