mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Fix possible size_t overflow in 32-bit builds. (#1131)
* Fix possible size_t overflow in 32-bit builds. Use cl_ulong temporary values for row/slice_pitch. Signed-off-by: John Kesapides <john.kesapides@arm.com> * Remove redundant casts Signed-off-by: John Kesapides <john.kesapides@arm.com>
This commit is contained in:
@@ -244,6 +244,9 @@ int test_get_image_info_2D_array(cl_device_id device, cl_context context,
|
|||||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||||
{
|
{
|
||||||
cl_ulong size;
|
cl_ulong size;
|
||||||
|
cl_ulong slicePitch;
|
||||||
|
cl_ulong rowPitch;
|
||||||
|
|
||||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||||
do
|
do
|
||||||
@@ -252,23 +255,26 @@ int test_get_image_info_2D_array(cl_device_id device, cl_context context,
|
|||||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||||
imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
|
imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
|
||||||
|
|
||||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
rowPitch = imageInfo.width * pixelSize;
|
||||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
slicePitch = rowPitch * imageInfo.height;
|
||||||
|
|
||||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||||
imageInfo.rowPitch += extraWidth;
|
rowPitch += extraWidth;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
extraWidth++;
|
extraWidth++;
|
||||||
imageInfo.rowPitch += extraWidth;
|
rowPitch += extraWidth;
|
||||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
} while ((rowPitch % pixelSize) != 0);
|
||||||
|
|
||||||
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
||||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
|
slicePitch = rowPitch * (imageInfo.height + extraHeight);
|
||||||
|
|
||||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
|
size = slicePitch * imageInfo.arraySize * 4 * 4;
|
||||||
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||||
|
|
||||||
|
imageInfo.slicePitch = slicePitch;
|
||||||
|
imageInfo.rowPitch = rowPitch;
|
||||||
|
|
||||||
if( gDebugTrace )
|
if( gDebugTrace )
|
||||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
|
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
|
||||||
int ret = test_get_2Dimage_array_info_single(
|
int ret = test_get_2Dimage_array_info_single(
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ int test_get_image_info_3D(cl_device_id device, cl_context context,
|
|||||||
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
|
||||||
{
|
{
|
||||||
cl_ulong size;
|
cl_ulong size;
|
||||||
|
cl_ulong slicePitch;
|
||||||
|
cl_ulong rowPitch;
|
||||||
|
|
||||||
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
// Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
|
||||||
// image, the result array, plus offset arrays, will fit in the global ram space
|
// image, the result array, plus offset arrays, will fit in the global ram space
|
||||||
do
|
do
|
||||||
@@ -113,23 +116,26 @@ int test_get_image_info_3D(cl_device_id device, cl_context context,
|
|||||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||||
imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
|
imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
|
||||||
|
|
||||||
imageInfo.rowPitch = imageInfo.width * pixelSize;
|
rowPitch = imageInfo.width * pixelSize;
|
||||||
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
|
slicePitch = imageInfo.rowPitch * imageInfo.height;
|
||||||
|
|
||||||
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
|
||||||
imageInfo.rowPitch += extraWidth;
|
rowPitch += extraWidth;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
extraWidth++;
|
extraWidth++;
|
||||||
imageInfo.rowPitch += extraWidth;
|
rowPitch += extraWidth;
|
||||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
} while ((rowPitch % pixelSize) != 0);
|
||||||
|
|
||||||
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
|
||||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
|
slicePitch = rowPitch * (imageInfo.height + extraHeight);
|
||||||
|
|
||||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
|
size = slicePitch * imageInfo.depth * 4 * 4;
|
||||||
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
} while( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||||
|
|
||||||
|
imageInfo.slicePitch = slicePitch;
|
||||||
|
imageInfo.rowPitch = rowPitch;
|
||||||
|
|
||||||
if( gDebugTrace )
|
if( gDebugTrace )
|
||||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
|
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
|
||||||
int ret = test_get_image_info_single(context, queue, &imageInfo,
|
int ret = test_get_image_info_single(context, queue, &imageInfo,
|
||||||
|
|||||||
Reference in New Issue
Block a user