frontends/va: fix some coverity scan reported issues

Added some checks for NULL pointer dereferencing and loop bounds.
v2: Use ARRAY_SIZE instead of magic numbers (@jenatali)

Signed-off-by: Thong Thai <thong.thai@amd.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23598>
This commit is contained in:
Thong Thai
2023-06-12 10:38:25 -04:00
committed by Marge Bot
parent dc93f205c1
commit 7d3c29dc60
7 changed files with 26 additions and 8 deletions
+2 -2
View File
@@ -575,7 +575,7 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
return VA_STATUS_ERROR_OPERATION_FAILED;
}
for (i = 0; i < vaimage->num_planes; i++) {
for (i = 0; i < MIN2(vaimage->num_planes, 3); i++) {
data[i] = ((uint8_t*)img_buf->data) + vaimage->offsets[i];
pitches[i] = vaimage->pitches[i];
}
@@ -709,7 +709,7 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
return VA_STATUS_ERROR_OPERATION_FAILED;
}
for (i = 0; i < vaimage->num_planes; i++) {
for (i = 0; i < MIN2(vaimage->num_planes, 3); i++) {
data[i] = ((uint8_t*)img_buf->data) + vaimage->offsets[i];
pitches[i] = vaimage->pitches[i];
}
@@ -51,6 +51,9 @@ vlVaHandleVAEncPictureParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *cont
context->desc.h264enc.p_remain = context->desc.h264enc.gop_size - context->desc.h264enc.gop_cnt - context->desc.h264enc.i_remain;
coded_buf = handle_table_get(drv->htab, h264->coded_buf);
if (!coded_buf)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (!coded_buf->derived_surface.resource)
coded_buf->derived_surface.resource = pipe_buffer_create(drv->pipe->screen, PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STAGING, coded_buf->size);
@@ -53,6 +53,8 @@ vlVaHandleVAEncPictureParameterBufferTypeHEVC(vlVaDriver *drv, vlVaContext *cont
context->desc.h265enc.pic_order_cnt = h265->decoded_curr_pic.pic_order_cnt;
coded_buf = handle_table_get(drv->htab, h265->coded_buf);
if (!coded_buf)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (!coded_buf->derived_surface.resource)
coded_buf->derived_surface.resource = pipe_buffer_create(drv->pipe->screen, PIPE_BIND_VERTEX_BUFFER,
+8 -2
View File
@@ -38,7 +38,9 @@ void vlVaHandlePictureParameterBufferMJPEG(vlVaDriver *drv, vlVaContext *context
context->desc.mjpeg.picture_parameter.picture_width = mjpeg->picture_width;
context->desc.mjpeg.picture_parameter.picture_height = mjpeg->picture_height;
for (i = 0; i < mjpeg->num_components; ++i) {
STATIC_ASSERT(sizeof(mjpeg->components) ==
sizeof(context->desc.mjpeg.picture_parameter.components));
for (i = 0; i < MIN2(mjpeg->num_components, ARRAY_SIZE(mjpeg->components)); ++i) {
context->desc.mjpeg.picture_parameter.components[i].component_id =
mjpeg->components[i].component_id;
context->desc.mjpeg.picture_parameter.components[i].h_sampling_factor =
@@ -79,6 +81,8 @@ void vlVaHandleHuffmanTableBufferType(vlVaContext *context, vlVaBuffer *buf)
assert(buf->size >= sizeof(VASliceParameterBufferJPEGBaseline) && buf->num_elements == 1);
STATIC_ASSERT(sizeof(mjpeg->load_huffman_table) ==
sizeof(context->desc.mjpeg.huffman_table.load_huffman_table));
for (i = 0; i < 2; ++i) {
context->desc.mjpeg.huffman_table.load_huffman_table[i] = mjpeg->load_huffman_table[i];
@@ -107,7 +111,9 @@ void vlVaHandleSliceParameterBufferMJPEG(vlVaContext *context, vlVaBuffer *buf)
context->desc.mjpeg.slice_parameter.slice_horizontal_position = mjpeg->slice_horizontal_position;
context->desc.mjpeg.slice_parameter.slice_vertical_position = mjpeg->slice_vertical_position;
for (i = 0; i < mjpeg->num_components; ++i) {
STATIC_ASSERT(sizeof(mjpeg->components) ==
sizeof(context->desc.mjpeg.slice_parameter.components));
for (i = 0; i < MIN2(mjpeg->num_components, ARRAY_SIZE(mjpeg->components)); ++i) {
context->desc.mjpeg.slice_parameter.components[i].component_selector =
mjpeg->components[i].component_selector;
context->desc.mjpeg.slice_parameter.components[i].dc_table_selector =
+6 -3
View File
@@ -220,6 +220,8 @@ static VAStatus vlVaPostProcBlit(vlVaDriver *drv, vlVaContext *context,
vlVaSurface *surf;
surf = handle_table_get(drv->htab, context->target_id);
if (!surf)
return VA_STATUS_ERROR_INVALID_SURFACE;
surf->templat.interlaced = false;
dst->destroy(dst);
@@ -391,6 +393,10 @@ vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver *drv, vlVaContext *contex
src_surface = handle_table_get(drv->htab, param->surface);
dst_surface = handle_table_get(drv->htab, context->target_id);
if (!src_surface || !dst_surface)
return VA_STATUS_ERROR_INVALID_SURFACE;
if (!src_surface->buffer || !dst_surface->buffer)
return VA_STATUS_ERROR_INVALID_SURFACE;
pscreen = drv->vscreen->pscreen;
@@ -423,9 +429,6 @@ vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver *drv, vlVaContext *contex
return VA_STATUS_SUCCESS;
}
if (!src_surface || !src_surface->buffer)
return VA_STATUS_ERROR_INVALID_SURFACE;
src = src_surface->buffer;
dst = dst_surface->buffer;
+4
View File
@@ -236,6 +236,10 @@ vlVaAssociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture,
for (i = 0; i < num_surfaces; i++) {
surf = handle_table_get(drv->htab, target_surfaces[i]);
if (!surf) {
mtx_unlock(&drv->mutex);
return VA_STATUS_ERROR_INVALID_SURFACE;
}
util_dynarray_append(&surf->subpics, vlVaSubpicture *, sub);
}
mtx_unlock(&drv->mutex);
+1 -1
View File
@@ -1586,7 +1586,7 @@ vlVaExportSurfaceHandle(VADriverContextP ctx,
desc->width = surf->templat.width;
desc->height = surf->templat.height;
for (p = 0; p < VL_MAX_SURFACES; p++) {
for (p = 0; p < ARRAY_SIZE(desc->objects); p++) {
struct winsys_handle whandle;
struct pipe_resource *resource;
uint32_t drm_format;