summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2016-02-10 00:06:32 +0000
committerMichael Meeks <michael.meeks@collabora.com>2016-02-10 00:43:49 +0000
commit13667e6576e3e5bc5b133764f77d71cef6c4687a (patch)
tree0d6175b808fec6b86e0a6f7d37ea69f0cc050f32
parentd323f2487d84fbd3909cd2166b98a2a875b71bf8 (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
-rw-r--r--vcl/opengl/salbmp.cxx27
1 files changed, 26 insertions, 1 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 2c3ef263678d..be5f8f0d2767 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -38,6 +38,10 @@
#include "opengl/FixedTextureAtlas.hxx"
+#if OSL_DEBUG_LEVEL > 0
+# define CANARY "tex-canary"
+#endif
+
namespace
{
@@ -147,6 +151,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;
}
@@ -258,7 +265,15 @@ bool OpenGLSalBitmap::AllocateUserData()
{
try
{
- mpUserBuffer = o3tl::make_shared_array<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
+ mpUserBuffer = o3tl::make_shared_array<sal_uInt8>(nToAllocate);
+#if OSL_DEBUG_LEVEL > 0
+ memcpy(mpUserBuffer.get() + nToAllocate - sizeof(CANARY),
+ CANARY, sizeof(CANARY));
+#endif
alloc = true;
}
catch (const std::bad_alloc &) {}
@@ -538,9 +553,19 @@ bool OpenGLSalBitmap::ReadTexture()
// help valgrind & drmemory rescue us - touch last and first bits.
pData[0] = 0;
pData[mnBits/8*mnWidth*mnHeight-1] = 0;
+ // if this fails we can read too much into pData
+ assert(mnWidth == maTexture.GetWidth() &&
+ mnHeight == maTexture.GetHeight());
#endif
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;