From 61632c08b560a3aecd0b8e13b6761fc2f8526d20 Mon Sep 17 00:00:00 2001 From: John Kesapides <46718829+JohnKesapidesARM@users.noreply.github.com> Date: Sun, 23 Feb 2020 12:16:12 +0000 Subject: [PATCH] Fix overflow in OpenCL 2.x CTS allocations tests (#610) Add size_t overflow contingency code for 32-bit platforms where max_width,max_height are 64k each. The code is modified to avoid the overflowing multiplication. Signed-off-by: John Kesapides --- test_conformance/allocations/allocation_functions.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test_conformance/allocations/allocation_functions.cpp b/test_conformance/allocations/allocation_functions.cpp index 7a309cd6..40f8604c 100644 --- a/test_conformance/allocations/allocation_functions.cpp +++ b/test_conformance/allocations/allocation_functions.cpp @@ -48,7 +48,10 @@ int find_good_image_size(cl_device_id device_id, size_t size_to_allocate, size_t num_pixels = size_to_allocate / (sizeof(cl_uint)*4); - if (num_pixels > (max_width*max_height)) { + // Use a 64-bit variable to avoid overflow in 32-bit architectures + long long unsigned max_pixels = (long long unsigned)max_width * max_height; + + if (num_pixels > max_pixels) { if(NULL != max_size) { *max_size = max_width * max_height * sizeof(cl_uint) * 4; }