Skip to content

Commit 0830af8

Browse files
lucylqpytorchbot
authored andcommitted
Integer overflow in HierarchicalAllocator::get_offset_address()
Differential Revision: D78703809 Pull Request resolved: #12699 (cherry picked from commit 2065924)
1 parent a3345d2 commit 0830af8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

runtime/core/hierarchical_allocator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ class HierarchicalAllocator final {
6060
uint32_t memory_id,
6161
size_t offset_bytes,
6262
size_t size_bytes) {
63+
// Check for integer overflow in offset_bytes + size_bytes.
64+
ET_CHECK_OR_RETURN_ERROR(
65+
size_bytes <= SIZE_MAX - offset_bytes,
66+
InvalidArgument,
67+
"Integer overflow in offset_bytes (%" ET_PRIsize_t
68+
") + size_bytes (%" ET_PRIsize_t ")",
69+
offset_bytes,
70+
size_bytes);
71+
6372
ET_CHECK_OR_RETURN_ERROR(
6473
memory_id < buffers_.size(),
6574
InvalidArgument,
6675
"id %" PRIu32 " >= %" ET_PRIsize_t,
6776
memory_id,
6877
buffers_.size());
6978
Span<uint8_t> buffer = buffers_[memory_id];
79+
7080
ET_CHECK_OR_RETURN_ERROR(
7181
offset_bytes + size_bytes <= buffer.size(),
7282
MemoryAllocationFailed,

0 commit comments

Comments
 (0)