From b61d9a157b016e0f29b5e11ecf2bd20a92f2d53a Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Wed, 7 Apr 2021 20:30:55 +0100 Subject: [PATCH] Fix out-of-bounds reads on GL_BGRA colours --- GL/draw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GL/draw.c b/GL/draw.c index f9ac75c..1787db4 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -693,7 +693,8 @@ GL_FORCE_INLINE void _readNormalData(const GLuint first, const GLuint count, Ver } GL_FORCE_INLINE void _readDiffuseData(const GLuint first, const GLuint count, Vertex* output) { - const GLuint cstride = (DIFFUSE_POINTER.stride) ? DIFFUSE_POINTER.stride : DIFFUSE_POINTER.size * byte_size(DIFFUSE_POINTER.type); + const GLuint size = (DIFFUSE_POINTER.size == GL_BGRA) ? 4 : DIFFUSE_POINTER.size; + const GLuint cstride = (DIFFUSE_POINTER.stride) ? DIFFUSE_POINTER.stride : size * byte_size(DIFFUSE_POINTER.type); const GLubyte* cptr = ((GLubyte*) DIFFUSE_POINTER.ptr) + (first * cstride); ReadDiffuseFunc func = calcReadDiffuseFunc();