Skip to content

Commit 0094340

Browse files
committed
Fixed bounds checks to allow 0 offset, 0 buffer size
1 parent f269869 commit 0094340

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

kernels/common/buffer.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,21 @@ namespace embree
248248
/*! sets the buffer view */
249249
void set(const Ref<Buffer>& buffer_in, size_t offset_in, size_t stride_in, size_t num_in, RTCFormat format_in)
250250
{
251-
if (stride_in > 0xFFFFFFFFu)
251+
if (stride_in > 0xFFFFFFFFu) {
252252
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"stride too large");
253+
}
253254

254-
if (num_in > 0xFFFFFFFFu)
255+
if (num_in > 0xFFFFFFFFu) {
255256
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"item count too large");
257+
}
256258

257-
if (offset_in >= buffer_in->numBytes)
259+
if (offset_in > 0 && offset_in >= buffer_in->numBytes) {
258260
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "offset too large");
261+
}
259262

260-
if (stride_in * num_in > buffer_in->numBytes - offset_in)
263+
if (stride_in * num_in > buffer_in->numBytes - offset_in) {
261264
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "buffer range out of bounds");
265+
}
262266

263267
ptr_ofs = buffer_in->getHostPtr() + offset_in;
264268
dptr_ofs = buffer_in->getDevicePtr() + offset_in;

0 commit comments

Comments
 (0)