diff options
author | Philipp Kerling <pkerling@casix.org> | 2018-12-21 11:15:43 +0100 |
---|---|---|
committer | Philipp Kerling <pkerling@casix.org> | 2018-12-21 15:16:04 +0100 |
commit | 9605e2ff352b0785c52ac135b35b1ed914b57e21 (patch) | |
tree | 6c357c79d08a441d9b2f19a6cbaf0d2866ce1275 | |
parent | f5df89eef0139fd7030d9b99dc9699d255cc19cd (diff) |
[guilib] Fix out-of-bounds vector access when "drawing" empty text
If the text to draw is empty, the vertex vector in CGUIFontTTFBase::
DrawTextInternal stays empty and is handed like that to the lib-specific
functions which might not handle that. Specifically, CGUIFontTTFGL::
CreateVertexBuffer accessed the vertex vector without bounds checking
(detected by `-D_GLIBCXX_ASSERTIONS`). As there is nothing to do for
drawing an empty text anyway, just bail out early.
Also add some extra checking to be safe in the future.
-rw-r--r-- | xbmc/guilib/GUIFontTTF.cpp | 5 | ||||
-rw-r--r-- | xbmc/guilib/GUIFontTTFGL.cpp | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/xbmc/guilib/GUIFontTTF.cpp b/xbmc/guilib/GUIFontTTF.cpp index acad2fcb76..906db44dad 100644 --- a/xbmc/guilib/GUIFontTTF.cpp +++ b/xbmc/guilib/GUIFontTTF.cpp @@ -352,6 +352,11 @@ void CGUIFontTTFBase::End() void CGUIFontTTFBase::DrawTextInternal(float x, float y, const std::vector<UTILS::Color> &colors, const vecText &text, uint32_t alignment, float maxPixelWidth, bool scrolling) { + if (text.empty()) + { + return; + } + Begin(); uint32_t rawAlignment = alignment; diff --git a/xbmc/guilib/GUIFontTTFGL.cpp b/xbmc/guilib/GUIFontTTFGL.cpp index db51eb4bdd..f87afae0af 100644 --- a/xbmc/guilib/GUIFontTTFGL.cpp +++ b/xbmc/guilib/GUIFontTTFGL.cpp @@ -23,6 +23,8 @@ #endif #include "rendering/MatrixGL.h" +#include <cassert> + // stuff for freetype #include <ft2build.h> #include FT_FREETYPE_H @@ -280,6 +282,9 @@ void CGUIFontTTFGL::LastEnd() CVertexBuffer CGUIFontTTFGL::CreateVertexBuffer(const std::vector<SVertex> &vertices) const { + assert(!vertices.empty()); + assert(vertices.size() % 4 == 0); + // Generate a unique buffer object name and put it in bufferHandle GLuint bufferHandle; glGenBuffers(1, &bufferHandle); @@ -288,7 +293,7 @@ CVertexBuffer CGUIFontTTFGL::CreateVertexBuffer(const std::vector<SVertex> &vert // Create a data store for the buffer object bound to the GL_ARRAY_BUFFER // binding point (i.e. our buffer object) and initialise it from the // specified client-side pointer - glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof (SVertex), &vertices[0], GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof (SVertex), vertices.data(), GL_STATIC_DRAW); // Unbind GL_ARRAY_BUFFER glBindBuffer(GL_ARRAY_BUFFER, 0); |