vcl/opengl/salbmp.cxx | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
New commits: commit 84ef3ad4b9c12ae1410a1a2f7e0557c432852675 Author: Michael Meeks <[email protected]> Date: Wed Feb 10 00:40:38 2016 +0000 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 <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index 0896fd1..61d7575 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;
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
