>From 48d1f092a7960d711fb2c77ab8d3f9d0a0ca0d5c Mon Sep 17 00:00:00 2001 From: HQM <hqm03s...@gmail.com> Date: Mon, 6 May 2019 15:37:59 +0800 Subject: [PATCH] Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture
In a GVT-g setup with dmabuf and GTK GUI, the current 2D texture at surface_gl_update_texture is not necessarily surface->texture. Adding a glBindTexture fixes related crashes and artifacts, and is generally more secure. Signed-off-by: HQM <hqm03s...@gmail.com> --- ui/console-gl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/console-gl.c b/ui/console-gl.c index a56e1cd..c1cb3bd 100644 --- a/ui/console-gl.c +++ b/ui/console-gl.c @@ -92,13 +92,17 @@ void surface_gl_update_texture(QemuGLShader *gls, assert(gls); - glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, - surface_stride(surface) / surface_bytes_per_pixel(surface)); - glTexSubImage2D(GL_TEXTURE_2D, 0, - x, y, w, h, - surface->glformat, surface->gltype, - data + surface_stride(surface) * y - + surface_bytes_per_pixel(surface) * x); + if (surface->texture) { + glBindTexture(GL_TEXTURE_2D, surface->texture); + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, + surface_stride(surface) + / surface_bytes_per_pixel(surface)); + glTexSubImage2D(GL_TEXTURE_2D, 0, + x, y, w, h, + surface->glformat, surface->gltype, + data + surface_stride(surface) * y + + surface_bytes_per_pixel(surface) * x); + } } void surface_gl_render_texture(QemuGLShader *gls, -- 2.17.1