summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2016-02-10 00:40:38 +0000
committerTomaž Vajngerl <quikee@gmail.com>2016-02-10 06:25:18 +0000
commit84ef3ad4b9c12ae1410a1a2f7e0557c432852675 (patch)
tree1469b11d9c96a4b0655e217cdb7eda8543cd36c8
parent48395acdae355a4c272cdbaf54131b3bcc96d63d (diff)
tdf#97700 - vcl: opengl - add asserts for horrible size mismatch.
We really need to be sure that our texture and its wrapper agree on the size of the texture, and particularly the buffer it is reading into to avoid DMA'ing junk over the heap. Add paranoid assertions, also add a canary at the end of the texture so we fail hard and fast in this case. Change-Id: Ibf4869fb5cba562aa117943ce0f2f3df21ca7036 Reviewed-on: https://gerrit.libreoffice.org/22252 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/opengl/salbmp.cxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 0896fd1a8070..61d7575b7448 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -36,6 +36,10 @@
#include "opengl/FixedTextureAtlas.hxx"
+#if OSL_DEBUG_LEVEL > 0
+# define CANARY "tex-canary"
+#endif
+
namespace
{
@@ -145,6 +149,9 @@ bool OpenGLSalBitmap::Create( const OpenGLTexture& rTex, long nX, long nY, long
mbDirtyTexture = false;
VCL_GL_INFO( "Created texture " << maTexture.Id() );
+ assert(mnWidth == maTexture.GetWidth() &&
+ mnHeight == maTexture.GetHeight());
+
return true;
}
@@ -256,7 +263,15 @@ bool OpenGLSalBitmap::AllocateUserData()
{
try
{
- maUserBuffer.reset( new sal_uInt8[static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight] );
+ size_t nToAllocate = static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight;
+#if OSL_DEBUG_LEVEL > 0
+ nToAllocate += sizeof(CANARY);
+#endif
+ maUserBuffer.reset( new sal_uInt8[nToAllocate] );
+#if OSL_DEBUG_LEVEL > 0
+ memcpy(maUserBuffer.get() + nToAllocate - sizeof(CANARY),
+ CANARY, sizeof(CANARY));
+#endif
alloc = true;
}
catch (const std::bad_alloc &) {}
@@ -532,7 +547,19 @@ bool OpenGLSalBitmap::ReadTexture()
{
determineTextureFormat(mnBits, nFormat, nType);
+ // if this fails we can read too much into pData
+ assert(mnWidth == maTexture.GetWidth() &&
+ mnHeight == maTexture.GetHeight());
+
maTexture.Read(nFormat, nType, pData);
+
+#if OSL_DEBUG_LEVEL > 0
+ // If we read over the end of pData we have a real hidden memory
+ // corruption problem !
+ size_t nCanary = static_cast<sal_uInt32>(mnBytesPerRow) * mnHeight;
+ assert(!memcmp(pData + nCanary, CANARY, sizeof (CANARY)));
+#endif
+
mnBufWidth = mnWidth;
mnBufHeight = mnHeight;
return true;