Skip to content

Commit f0dabf3

Browse files
committed
[cts] add integer overflow/bounds check tests for rect APIs
1 parent 09cb31a commit f0dabf3

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

test/conformance/enqueue/urEnqueueMemBufferCopyRect.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,16 @@ TEST_F(urEnqueueMemBufferCopyRectMultiDeviceTest, CopyRectReadDifferentQueues) {
261261

262262
EXPECT_SUCCESS(urMemRelease(dst_buffer));
263263
}
264+
265+
TEST_P(urEnqueueMemBufferCopyRectTest, InvalidSize) {
266+
// out-of-bounds access with potential overflow
267+
ur_rect_region_t src_region{size, 1, 1};
268+
ur_rect_offset_t src_origin{std::numeric_limits<uint64_t>::max(), 1, 1};
269+
ur_rect_offset_t dst_origin{0, 0, 0};
270+
271+
ASSERT_EQ_RESULT(urEnqueueMemBufferCopyRect(queue, src_buffer, dst_buffer,
272+
src_origin, dst_origin,
273+
src_region, size, size, size,
274+
size, 0, nullptr, nullptr),
275+
UR_RESULT_ERROR_INVALID_SIZE);
276+
}

test/conformance/enqueue/urEnqueueMemBufferReadRect.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,19 @@ TEST_F(urEnqueueMemBufferReadRectMultiDeviceTest, WriteReadDifferentQueues) {
203203
<< "Result on queue " << i << " did not match!";
204204
}
205205
}
206+
207+
TEST_P(urEnqueueMemBufferReadRectTest, InvalidSize) {
208+
std::vector<uint32_t> dst(count);
209+
// out-of-bounds access with potential overflow
210+
ur_rect_region_t region{size, 1, 1};
211+
ur_rect_offset_t buffer_offset{std::numeric_limits<uint64_t>::max(), 1, 1};
212+
// Creating an overflow in host_offsets leads to a crash because
213+
// the function doesn't do bounds checking of host buffers.
214+
ur_rect_offset_t host_offset{0, 0, 0};
215+
216+
ASSERT_EQ_RESULT(
217+
urEnqueueMemBufferReadRect(queue, buffer, true, buffer_offset,
218+
host_offset, region, size, size, size, size,
219+
dst.data(), 0, nullptr, nullptr),
220+
UR_RESULT_ERROR_INVALID_SIZE);
221+
}

test/conformance/enqueue/urEnqueueMemBufferWriteRect.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,21 @@ TEST_P(urEnqueueMemBufferWriteRectTest, InvalidNullPtrEventWaitList) {
184184
src.data(), 0, &validEvent, nullptr),
185185
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
186186
}
187+
188+
TEST_P(urEnqueueMemBufferWriteRectTest, InvalidSize) {
189+
std::vector<uint32_t> src(count);
190+
std::fill(src.begin(), src.end(), 1);
191+
192+
// out-of-bounds access with potential overflow
193+
ur_rect_region_t region{size, 1, 1};
194+
ur_rect_offset_t buffer_offset{std::numeric_limits<uint64_t>::max(), 1, 1};
195+
// Creating an overflow in host_offsets leads to a crash because
196+
// the function doesn't do bounds checking of host buffers.
197+
ur_rect_offset_t host_offset{0, 0, 0};
198+
199+
ASSERT_EQ_RESULT(
200+
urEnqueueMemBufferWriteRect(queue, buffer, true, buffer_offset,
201+
host_offset, region, size, size, size, size,
202+
src.data(), 0, nullptr, nullptr),
203+
UR_RESULT_ERROR_INVALID_SIZE);
204+
}

0 commit comments

Comments
 (0)