Skip to contentSkip to conversation

ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture

PATCH In review Marcel Apfelbaum 2 participants 2 messages May 7, 2019 – May 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture

From: HOU Qiming <[email protected]>

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.

[fixed malformed patch, rebase to master]

---

v3:
- Fixed contributor name (Philippe)

v2:
- fixed malformed patch
- rebased to master

 ui/console-gl.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
ui/console-gl.c +11 -7
index a56e1cd8eb..c1cb3bd673 100644
@@ -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,
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Marcel Apfelbaum

From: HOU Qiming <[email protected]>

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.

Added to UI patch queue.

thanks,
Gerd