From 416abdbc595c5f79e9f2557f9541b542bf0165af Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sun, 19 Feb 2023 19:36:32 -0400 Subject: [PATCH] love.graphics.copyBuffer: slightly more robust error handling. --- src/modules/graphics/Graphics.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index cfd915a49..098c886cc 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -1370,6 +1370,9 @@ void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, siz if (dest->isImmutable()) throw love::Exception("Cannot copy to an immutable buffer."); + if (sourceoffset % 4 != 0 || destoffset % 4 != 0 || size % 4 != 0) + throw love::Exception("Buffer copy source offset, destination offset, and size parameters must be multiples of 4 bytes."); + source->copyTo(dest, sourceoffset, destoffset, size); } @@ -1456,6 +1459,9 @@ void Graphics::copyTextureToBuffer(Texture *source, Buffer *dest, int slice, int Range destrange(destoffset, size); + if (destoffset % 4 != 0 || size % 4 != 0) + throw love::Exception("Buffer copy destination offset and computed byte size must be multiples of 4 bytes."); + if (destrange.getMax() >= dest->getSize()) throw love::Exception("Buffer copy destination offset and width/height doesn't fit within the destination Buffer."); @@ -1536,6 +1542,9 @@ void Graphics::copyBufferToTexture(Buffer *source, Texture *dest, size_t sourceo Range sourcerange(sourceoffset, size); + if (sourceoffset % 4 != 0 || size % 4 != 0) + throw love::Exception("Buffer copy source offset and computed byte size must be multiples of 4 bytes."); + if (sourcerange.getMax() >= source->getSize()) throw love::Exception("Buffer copy source offset and width/height doesn't fit within the source Buffer.");