From 7a0ff8da57298467c3a062e11864f72c5cb2a03e Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Thu, 30 May 2019 19:34:53 +0300 Subject: [PATCH] vrend: Ensure non-zero stride and remove redundant check Ensure we can't create a texture resource with zero width, to guarantee that we get a non-zero stride, since either: 1. A non-zero stride was specified in the transfer request, or 2. We will calculate a stride based on texture width which we guarantee is not zero Signed-off-by: Alexandros Frantzis Reviewed-by: Chia-I Wu --- src/vrend_renderer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 21a0ddb..a924014 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -5977,7 +5977,9 @@ static int vrend_renderer_resource_allocate_texture(struct vrend_resource *gr, GLenum internalformat, glformat, gltype; struct vrend_texture *gt = (struct vrend_texture *)gr; struct pipe_resource *pr = &gr->base; - assert(pr->width0 > 0); + + if (pr->width0 == 0) + return EINVAL; bool format_can_texture_storage = has_feature(feat_texture_storage) && (tex_conv_table[pr->format].flags & VIRGL_TEXTURE_CAN_TEXTURE_STORAGE); @@ -6598,7 +6600,8 @@ static int vrend_renderer_transfer_write_iov(struct vrend_context *ctx, data = (char*)iov[0].iov_base + info->offset; } - if (stride && !need_temp) { + if (!need_temp) { + assert(stride); glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / elsize); glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, layer_stride / stride); } else