From dc5460effd6b0015084b8b0eea22f7a3938dbf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Tue, 19 May 2015 13:45:22 -0300 Subject: [PATCH] (gl_raster_font) Fix invalid read when pushing vertices Calling both glsl shader->set_coords() or gl_coord_array_add() resulted in an invalid read when memcpy()ing coords->lut_tex_coord. --- gfx/drivers/gl_common.c | 2 +- gfx/drivers_font/gl_raster_font.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gfx/drivers/gl_common.c b/gfx/drivers/gl_common.c index 6e07c63f78..3588c89e83 100644 --- a/gfx/drivers/gl_common.c +++ b/gfx/drivers/gl_common.c @@ -199,7 +199,7 @@ bool gl_coord_array_add(gl_coord_array_t *ca, const gl_coords_t *coords, unsigne if (success) { - size_t base_size = coords->vertices * sizeof(GLfloat); + size_t base_size = count * sizeof(GLfloat); size_t offset = ca->coords.vertices; /* XXX: i wish we used interlaced arrays so we could call memcpy only once */ diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index edbdaf4e1e..8693212f19 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -29,6 +29,8 @@ font_color[ 4 * (6 * i + c) + 1] = color[1]; \ font_color[ 4 * (6 * i + c) + 2] = color[2]; \ font_color[ 4 * (6 * i + c) + 3] = color[3]; \ + font_lut_tex_coord[ 4 * (6 * i + c) + 0] = gl->coords.lut_tex_coord[0]; \ + font_lut_tex_coord[ 4 * (6 * i + c) + 1] = gl->coords.lut_tex_coord[1]; \ } while(0) #define MAX_MSG_LEN_CHUNK 64 @@ -181,6 +183,7 @@ static void gl_raster_font_render_message( GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK]; + GLfloat font_lut_tex_coord[2 * 6 * MAX_MSG_LEN_CHUNK]; struct gl_coords coords; gl_t *gl = font ? font->gl : NULL; @@ -246,7 +249,7 @@ static void gl_raster_font_render_message( coords.vertex = font_vertex; coords.color = font_color; coords.vertices = 6 * msg_len; - coords.lut_tex_coord = gl->coords.lut_tex_coord; + coords.lut_tex_coord = font_lut_tex_coord; if (font->block) gl_coord_array_add(&font->block->carr, &coords, coords.vertices);