From 01e9429c97c13e192e1ad64df3faad76feca7ac2 Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Tue, 28 Jun 2022 06:43:30 +0000 Subject: [PATCH] SWDEV-343168 - return invalidValue if totalsize is more than device's global memory. Change-Id: Ie052b9b75c9813d040fc23959df4146af98b96ed [ROCm/clr commit: 4aa1ffcc452f9cc80d5721e9072cb1e7b7ae2eab] --- projects/clr/hipamd/src/hip_memory.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 8ba165be65..968ff8e2dc 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -723,6 +723,11 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh const amd::Image::Format imageFormat(*image_format); + //avoid size_t overflow for pitch calculation + if (width * imageFormat.getElementSize() > (std::numeric_limits::max() - device->info().imagePitchAlignment_)) { + return hipErrorInvalidValue; + } + *pitch = amd::alignUp(width * imageFormat.getElementSize(), device->info().imagePitchAlignment_); size_t sizeBytes = *pitch * height * depth;