[virglrenderer-devel] [PATCH] vrend_renderer: Check the shader terminator

Po-Hsien Wang pwang at chromium.org
Tue Aug 14 10:32:27 UTC 2018


1) In the decode phase, increase the shader header size by 1 as 
   the shader has to be at least contains one terminate character.
2) Before calling tgsi_text_translate, check the last 4 bytes of
   shader contains the terminating character.

TEST=WebGLAquarium
---
 src/virgl_protocol.h | 2 +-
 src/vrend_renderer.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/virgl_protocol.h b/src/virgl_protocol.h
index dd1a4ee..ade213c 100644
--- a/src/virgl_protocol.h
+++ b/src/virgl_protocol.h
@@ -214,7 +214,7 @@ enum virgl_context_cmd {
 #define VIRGL_OBJ_CLEAR_STENCIL 8
 
 /* shader object */
-#define VIRGL_OBJ_SHADER_HDR_SIZE(nso) (5 + ((nso) ? (2 * nso) + 4 : 0))
+#define VIRGL_OBJ_SHADER_HDR_SIZE(nso) (6 + ((nso) ? (2 * nso) + 4 : 0))
 #define VIRGL_OBJ_SHADER_HANDLE 1
 #define VIRGL_OBJ_SHADER_TYPE 2
 #define VIRGL_OBJ_SHADER_OFFSET 3
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 57f3a1b..e7238d9 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -3027,7 +3027,11 @@ int vrend_create_shader(struct vrend_context *ctx,
 
       if (vrend_dump_shaders)
          fprintf(stderr,"shader\n%s\n", shd_text);
-      if (!tgsi_text_translate((const char *)shd_text, tokens, num_tokens + 10)) {
+
+      int last_chunk_offset = sel->buf_offset ? sel->buf_offset : pkt_length * 4;
+      if (!memchr(shd_text + last_chunk_offset - 4, '\0', 4) ||
+          !tgsi_text_translate((const char *)shd_text, tokens, num_tokens + 10)) {
+         fprintf(stderr, "not valid\n");
          free(tokens);
          ret = EINVAL;
          goto error;
-- 
2.18.0.597.ga71716f1ad-goog



More information about the virglrenderer-devel mailing list