ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture
PATCH v2 1/1 ui/console: Precautionary glBindTexture and surface->texture validation in surface_gl_update_texture
From: HQM <[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.
---
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
@@ -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
Hi Marcel,
Quoted 8 lines · Marcel Apfelbaum
From: HQM <[email protected]>
In a GVT-g setup with dmabuf and GTK GUI, the current 2D texture at
surface_gl_update_textureis not necessarilysurface->texture. Adding a glBindTexture fixes related crashes and artifacts, and is generally more secure.Signed-off-by HQM <[email protected]>
This looks like an acronym, per
https://wiki.qemu.org/Contribute/SubmitAPatch#Patch_emails_must_include_a_Signed-off-by:_line
"Patch emails must include a Signed-off-by: line [...] Please use your real name to sign a patch (not an alias or acronym)."
Quoted 42 lines
Tested-by Marcel Apfelbaum<[email protected]>[fixed malformed patch, rebase to master]Signed-off-by Marcel Apfelbaum <[email protected]>---
v2:
- fixed malformed patch
- rebased to masterui/console-gl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)ui/console-gl.c +11
-7@@ -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,
My real name is "HOU Qiming". @Marcel Apfelbaum <[email protected]> can you incorporate that in your v2 patch? Thanks!
Qiming
Quoted 63 lines · Philippe Mathieu-Daudé
Hi Marcel,
Quoted 8 lines · Marcel Apfelbaum
From: HQM <[email protected]>
In a GVT-g setup with dmabuf and GTK GUI, the current 2D texture at
surface_gl_update_textureis not necessarilysurface->texture. Adding a glBindTexture fixes related crashes and artifacts, and is generally more secure.Signed-off-by HQM <[email protected]>This looks like an acronym, per
https://wiki.qemu.org/Contribute/SubmitAPatch#Patch_emails_must_include_a_Signed-off-by:_line
"Patch emails must include a Signed-off-by: line [...] Please use your real name to sign a patch (not an alias or acronym)."
Quoted 17 lines
Tested-by Marcel Apfelbaum<[email protected]>[fixed malformed patch, rebase to master]Signed-off-by Marcel Apfelbaum <[email protected]>---
v2:
- fixed malformed patch
- rebased to masterui/console-gl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)ui/console-gl.c +0
-0ui/console-gl.c void surface_gl_update_texture(QemuGLShader *gls, · line 96
Quoted 5 lines
ui/console-gl.c +0
-2@@ -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));Quoted 20 lines
ui/console-gl.c +11
-5-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,
Quoted 3 lines · Hou Qiming
My real name is "HOU Qiming". @Marcel Apfelbaum <mailto:[email protected]> can you incorporate that in your v2 patch? Thanks!
Thanks a lot Qiming :)
Quoted 67 lines
On Tue, May 7, 2019 at 2:25 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Marcel, On 5/7/19 7:49 AM, Marcel Apfelbaum wrote: > From: HQM <[email protected] <mailto:[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. > > Signed-off-by: HQM <[email protected] <mailto:[email protected]>> This looks like an acronym, per https://wiki.qemu.org/Contribute/SubmitAPatch#Patch_emails_must_include_a_Signed-off-by:_line "Patch emails must include a Signed-off-by: line [...] Please use your real name to sign a patch (not an alias or acronym)." > Tested-by: Marcel Apfelbaum<[email protected] <mailto:[email protected]>> > [fixed malformed patch, rebase to master] > Signed-off-by: Marcel Apfelbaum <[email protected] <mailto:[email protected]>> > --- > > v2: > - fixed malformed patch > - rebased to master > > 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 a56e1cd8eb..c1cb3bd673 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, >
Quoted 2 lines · Hou Qiming
My real name is "HOU Qiming". @Marcel Apfelbaum <mailto:[email protected]> can you incorporate that in your v2 patch? Thanks!
Sure thing,
Thanks,
Marcel
Quoted 70 lines
Qiming
On Tue, May 7, 2019 at 2:25 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Marcel, On 5/7/19 7:49 AM, Marcel Apfelbaum wrote: > From: HQM <[email protected] <mailto:[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. > > Signed-off-by: HQM <[email protected] <mailto:[email protected]>> This looks like an acronym, per https://wiki.qemu.org/Contribute/SubmitAPatch#Patch_emails_must_include_a_Signed-off-by:_line "Patch emails must include a Signed-off-by: line [...] Please use your real name to sign a patch (not an alias or acronym)." > Tested-by: Marcel Apfelbaum<[email protected] <mailto:[email protected]>> > [fixed malformed patch, rebase to master] > Signed-off-by: Marcel Apfelbaum <[email protected] <mailto:[email protected]>> > --- > > v2: > - fixed malformed patch > - rebased to master > > 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 a56e1cd8eb..c1cb3bd673 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, >