@@ -177,13 +177,17 @@ struct urEnqueueMemBufferCopyRectTest : uur::urQueueTest {
177
177
ur_mem_handle_t src_buffer = nullptr ;
178
178
ur_mem_handle_t dst_buffer = nullptr ;
179
179
std::vector<uint32_t > input;
180
+ ur_rect_region_t src_region{size, 1 , 1 };
181
+ ur_rect_offset_t src_origin{0 , 0 , 0 };
182
+ ur_rect_offset_t dst_origin{0 , 0 , 0 };
183
+ size_t src_row_pitch = size;
184
+ size_t src_slice_pitch = size;
185
+ const size_t dst_row_pitch = size;
186
+ size_t dst_slice_pitch = size;
180
187
};
181
188
UUR_INSTANTIATE_DEVICE_TEST_SUITE (urEnqueueMemBufferCopyRectTest);
182
189
183
190
TEST_P (urEnqueueMemBufferCopyRectTest, InvalidNullHandleQueue) {
184
- ur_rect_region_t src_region{size, 1 , 1 };
185
- ur_rect_offset_t src_origin{0 , 0 , 0 };
186
- ur_rect_offset_t dst_origin{0 , 0 , 0 };
187
191
ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_HANDLE,
188
192
urEnqueueMemBufferCopyRect (nullptr , src_buffer, dst_buffer,
189
193
src_origin, dst_origin,
@@ -192,9 +196,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleQueue) {
192
196
}
193
197
194
198
TEST_P (urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferSrc) {
195
- ur_rect_region_t src_region{size, 1 , 1 };
196
- ur_rect_offset_t src_origin{0 , 0 , 0 };
197
- ur_rect_offset_t dst_origin{0 , 0 , 0 };
198
199
ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_HANDLE,
199
200
urEnqueueMemBufferCopyRect (queue, nullptr , dst_buffer,
200
201
src_origin, dst_origin,
@@ -203,9 +204,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferSrc) {
203
204
}
204
205
205
206
TEST_P (urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferDst) {
206
- ur_rect_region_t src_region{size, 1 , 1 };
207
- ur_rect_offset_t src_origin{0 , 0 , 0 };
208
- ur_rect_offset_t dst_origin{0 , 0 , 0 };
209
207
ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_HANDLE,
210
208
urEnqueueMemBufferCopyRect (queue, src_buffer, nullptr ,
211
209
src_origin, dst_origin,
@@ -216,9 +214,6 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullHandleBufferDst) {
216
214
TEST_P (urEnqueueMemBufferCopyRectTest, InvalidNullPtrEventWaitList) {
217
215
UUR_KNOWN_FAILURE_ON (uur::NativeCPU{});
218
216
219
- ur_rect_region_t src_region{size, 1 , 1 };
220
- ur_rect_offset_t src_origin{0 , 0 , 0 };
221
- ur_rect_offset_t dst_origin{0 , 0 , 0 };
222
217
ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
223
218
queue, src_buffer, dst_buffer, src_origin, dst_origin,
224
219
src_region, size, size, size, size, 1 , nullptr , nullptr ),
@@ -242,6 +237,79 @@ TEST_P(urEnqueueMemBufferCopyRectTest, InvalidNullPtrEventWaitList) {
242
237
243
238
ASSERT_SUCCESS (urEventRelease (validEvent));
244
239
}
240
+ TEST_P (urEnqueueMemBufferCopyRectTest, InvalidSize) {
241
+ UUR_KNOWN_FAILURE_ON (uur::NativeCPU{});
242
+
243
+ // region.width == 0 || region.height == 0 || region.width == 0
244
+ src_region.width = 0 ;
245
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
246
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
247
+ src_region, src_row_pitch, src_slice_pitch,
248
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
249
+ UR_RESULT_ERROR_INVALID_SIZE);
250
+
251
+ // srcRowPitch != 0 && srcRowPitch < region.width
252
+ src_region.width = src_row_pitch + 1 ;
253
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
254
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
255
+ src_region, src_row_pitch, src_slice_pitch,
256
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
257
+ UR_RESULT_ERROR_INVALID_SIZE);
258
+
259
+ // dstRowPitch != 0 && dstRowPitch < region.width
260
+ src_region.width = dst_row_pitch + 1 ;
261
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
262
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
263
+ src_region, src_row_pitch, src_slice_pitch,
264
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
265
+ UR_RESULT_ERROR_INVALID_SIZE);
266
+
267
+ // srcSlicePitch != 0 && srcSlicePitch < region.height * (srcRowPitch != 0 ?
268
+ // srcRowPitch : region.width)
269
+ src_region.width = size;
270
+ src_row_pitch = 16 ;
271
+ src_slice_pitch = (src_region.height * src_row_pitch) - 1 ;
272
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
273
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
274
+ src_region, src_row_pitch, src_slice_pitch,
275
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
276
+ UR_RESULT_ERROR_INVALID_SIZE);
277
+
278
+ // srcSlicePitch != 0 && srcSlicePitch % (srcRowPitch != 0 ? srcRowPitch :
279
+ // region.width) != 0
280
+ src_slice_pitch = size + 1 ;
281
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
282
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
283
+ src_region, src_row_pitch, src_slice_pitch,
284
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
285
+ UR_RESULT_ERROR_INVALID_SIZE);
286
+
287
+ // dstSlicePitch != 0 && dstSlicePitch < region.height * (dstRowPitch != 0 ?
288
+ // dstRowPitch : region.width)
289
+ src_slice_pitch = size;
290
+ dst_slice_pitch = (src_region.height * src_slice_pitch) - 1 ;
291
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
292
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
293
+ src_region, src_row_pitch, src_slice_pitch,
294
+ dst_row_pitch, dst_slice_pitch, 0 , nullptr , nullptr ),
295
+ UR_RESULT_ERROR_INVALID_SIZE);
296
+
297
+ // If the combination of srcOrigin, region, srcRowPitch, and srcSlicePitch
298
+ // results in an out-of-bounds access.
299
+ src_origin = {std::numeric_limits<uint64_t >::max (), 1 , 1 };
300
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
301
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
302
+ src_region, size, size, size, size, 0 , nullptr , nullptr ),
303
+ UR_RESULT_ERROR_INVALID_SIZE);
304
+
305
+ // If the combination of dstOrigin, region, dstRowPitch, and dstSlicePitch
306
+ // results in an out-of-bounds access.
307
+ dst_origin = {std::numeric_limits<uint64_t >::max (), 1 , 1 };
308
+ ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
309
+ queue, src_buffer, dst_buffer, src_origin, dst_origin,
310
+ src_region, size, size, size, size, 0 , nullptr , nullptr ),
311
+ UR_RESULT_ERROR_INVALID_SIZE);
312
+ }
245
313
246
314
using urEnqueueMemBufferCopyRectMultiDeviceTest =
247
315
uur::urMultiDeviceMemBufferQueueTest;
@@ -281,17 +349,3 @@ TEST_P(urEnqueueMemBufferCopyRectMultiDeviceTest, CopyRectReadDifferentQueues) {
281
349
282
350
EXPECT_SUCCESS (urMemRelease (dst_buffer));
283
351
}
284
-
285
- TEST_P (urEnqueueMemBufferCopyRectTest, InvalidSize) {
286
- UUR_KNOWN_FAILURE_ON (uur::NativeCPU{});
287
-
288
- // out-of-bounds access with potential overflow
289
- ur_rect_region_t src_region{size, 1 , 1 };
290
- ur_rect_offset_t src_origin{std::numeric_limits<uint64_t >::max (), 1 , 1 };
291
- ur_rect_offset_t dst_origin{0 , 0 , 0 };
292
-
293
- ASSERT_EQ_RESULT (urEnqueueMemBufferCopyRect (
294
- queue, src_buffer, dst_buffer, src_origin, dst_origin,
295
- src_region, size, size, size, size, 0 , nullptr , nullptr ),
296
- UR_RESULT_ERROR_INVALID_SIZE);
297
- }
0 commit comments