From f908a695fdaeccbbff7ba22b73c120d5d0400304 Mon Sep 17 00:00:00 2001 From: Rakesh Roy Date: Thu, 7 Jul 2022 19:57:19 +0530 Subject: [PATCH] SWDEV-344168 - Fix hipMemsetAsync API crash - Make sure head_size is not crossing fill_size - Head size, aligned size & tail size together cannot cross fill size Change-Id: Ie7845d748e3698b245876b43c9e626d7ea7154f7 [ROCm/clr commit: 13ede1a17e784b9ded860d4c7d35038aac8d777a] --- projects/clr/rocclr/device/blit.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/clr/rocclr/device/blit.cpp b/projects/clr/rocclr/device/blit.cpp index 999b9be754..376d1996d5 100644 --- a/projects/clr/rocclr/device/blit.cpp +++ b/projects/clr/rocclr/device/blit.cpp @@ -732,9 +732,11 @@ bool HostBlitManager::FillBufferInfo::PackInfo(const device::Memory& memory, siz "address"); // 3. If given address is not aligned calculate head and tail size. - size_t head_size = (aligned_dst_addr - dst_addr); + size_t head_size = std::min(aligned_dst_addr - dst_addr, fill_size); size_t aligned_size = ((fill_size - head_size) / sizeof(size_t)) * sizeof(size_t); size_t tail_size = (fill_size - head_size) % sizeof(size_t); + guarantee((head_size + aligned_size + tail_size) <= fill_size, "Head size, aligned size & tail" + "size together cannot cross fill size"); // 4. Clear unwanted bytes from the pattern if the pattern size is < sizeof(size_t). uint64_t pattern = *(reinterpret_cast(const_cast(pattern_ptr)));