File 0003-0d9a2c8-vrend-Check-resource-creation-more-thoroughly.patch of Package virglrenderer

commit 0d9a2c88dc3a70023541b3260b9f00c982abda16
Author: Gert Wollny <gert.wollny@collabora.com>
Date:   Thu Oct 10 09:42:25 2019 +0200

    vrend: Check resource creation more thoroughly
    
    While we are at it:
      - free memory if texture allocation fails
    
    Closes #144
    Closes #145
    Closes #146
    
    v2: Move the error string creation to extra patch (Emil)
    v3: Fix whitespace errors (Emil) and one logic error
    
    Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
    Reviewed-by: Emil Velikov <emil.velikov@collabora.com>

Index: virglrenderer-0.6.0/src/vrend_renderer.c
===================================================================
--- virglrenderer-0.6.0.orig/src/vrend_renderer.c
+++ virglrenderer-0.6.0/src/vrend_renderer.c
@@ -4105,15 +4105,18 @@ static int check_resource_valid(struct v
       /* buffer and rect textures can't have mipmaps */
       if (args->target == PIPE_BUFFER || args->target == PIPE_TEXTURE_RECT)
          return -1;
+
       if (args->last_level > (floor(log2(MAX2(args->width, args->height))) + 1))
          return -1;
+
    }
    if (args->flags != 0 && args->flags != VIRGL_RESOURCE_Y_0_TOP)
       return -1;
 
-   if (args->flags & VIRGL_RESOURCE_Y_0_TOP)
+   if (args->flags & VIRGL_RESOURCE_Y_0_TOP) {
       if (args->target != PIPE_TEXTURE_2D && args->target != PIPE_TEXTURE_RECT)
          return -1;
+   }
 
    /* array size for array textures only */
    if (args->target == PIPE_TEXTURE_CUBE) {
@@ -4157,6 +4160,39 @@ static int check_resource_valid(struct v
           args->target == PIPE_TEXTURE_1D_ARRAY) {
          if (args->height != 1 || args->depth != 1)
             return -1;
+         if (args->width > vrend_state.max_texture_2d_size) {
+            return -1;
+         }
+      }
+
+      if (args->target == PIPE_TEXTURE_2D ||
+          args->target == PIPE_TEXTURE_RECT ||
+          args->target == PIPE_TEXTURE_2D_ARRAY) {
+         if (args->width > vrend_state.max_texture_2d_size ||
+             args->height > vrend_state.max_texture_2d_size) {
+            return -1;
+         }
+      }
+
+      if (args->target == PIPE_TEXTURE_3D) {
+         if (args->width > vrend_state.max_texture_3d_size ||
+             args->height > vrend_state.max_texture_3d_size ||
+             args->depth > vrend_state.max_texture_3d_size) {
+            return -1;
+         }
+      }
+      if (args->target == PIPE_TEXTURE_2D_ARRAY ||
+          args->target == PIPE_TEXTURE_CUBE_ARRAY ||
+          args->target == PIPE_TEXTURE_1D_ARRAY) {
+      }
+      if (args->target == PIPE_TEXTURE_CUBE ||
+          args->target == PIPE_TEXTURE_CUBE_ARRAY) {
+         if (args->width != args->height) {
+            return -1;
+         }
+         if (args->width > vrend_state.max_texture_cube_size) {
+            return -1;
+         }
       }
    }
    return 0;
openSUSE Build Service is sponsored by