freedreno: reject imports with bogus pitch
authorRob Clark <robdclark@gmail.com>
Sat, 3 Sep 2016 16:57:50 +0000 (12:57 -0400)
committerRob Clark <robdclark@gmail.com>
Wed, 7 Sep 2016 15:41:38 +0000 (11:41 -0400)
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/freedreno_screen.h

index 3cc6654b740c8a83b9b69b24c01291b4fe0b4197..1874271c86b618f71e8463722491095e45bef118 100644 (file)
@@ -898,15 +898,18 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
 
        util_range_init(&rsc->valid_buffer_range);
 
-       rsc->bo = fd_screen_bo_from_handle(pscreen, handle, &slice->pitch);
+       rsc->bo = fd_screen_bo_from_handle(pscreen, handle);
        if (!rsc->bo)
                goto fail;
 
        rsc->base.vtbl = &fd_resource_vtbl;
        rsc->cpp = util_format_get_blocksize(tmpl->format);
-       slice->pitch /= rsc->cpp;
+       slice->pitch = handle->stride / rsc->cpp;
        slice->offset = handle->offset;
 
+       if ((slice->pitch < align(prsc->width0, 32)) || (slice->pitch % 32))
+               goto fail;
+
        assert(rsc->cpp);
 
        return prsc;
index fbdd1e2bbde1dbd44f08ae7c7f0c2250b3ef4b73..598a81126e895d9184875cd1c22edb577220411c 100644 (file)
@@ -536,8 +536,7 @@ fd_screen_bo_get_handle(struct pipe_screen *pscreen,
 
 struct fd_bo *
 fd_screen_bo_from_handle(struct pipe_screen *pscreen,
-               struct winsys_handle *whandle,
-               unsigned *out_stride)
+               struct winsys_handle *whandle)
 {
        struct fd_screen *screen = fd_screen(pscreen);
        struct fd_bo *bo;
@@ -558,8 +557,6 @@ fd_screen_bo_from_handle(struct pipe_screen *pscreen,
                return NULL;
        }
 
-       *out_stride = whandle->stride;
-
        return bo;
 }
 
index c52c23b33f5cca5b5fd6833f4b601dcbb44abdb7..03ee90a55132bc83c2c167d736f5c3d45bbd89a9 100644 (file)
@@ -86,8 +86,7 @@ boolean fd_screen_bo_get_handle(struct pipe_screen *pscreen,
                unsigned stride,
                struct winsys_handle *whandle);
 struct fd_bo * fd_screen_bo_from_handle(struct pipe_screen *pscreen,
-               struct winsys_handle *whandle,
-               unsigned *out_stride);
+               struct winsys_handle *whandle);
 
 struct pipe_screen * fd_screen_create(struct fd_device *dev);