From 1eaee1649a567abd41d66c19506642ba506ed972 Mon Sep 17 00:00:00 2001 From: Sunday Clement Date: Fri, 30 May 2025 14:52:19 -0400 Subject: [PATCH] rocr: Fix Unintended Sign Extension ehdr->e_shentshize and ehdr->e_shnum are both 16-bit unsigned integers and so their types get implicitly promoted to signed int automatically during the multiplication, they must be explicitly cast into a larger unsigned type, otherwise if the signed product is large enough the value is sign extended resulting in incorrect values. Signed-off-by: Sunday Clement [ROCm/ROCR-Runtime commit: d00ca2e9b791fb5ae7e334513a8cc27b47b4c1d8] --- .../runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp index 87d3407a16..2e63ea35e8 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_elf_image.cpp @@ -1738,7 +1738,7 @@ namespace elf { } uint64_t max_offset = ehdr->e_shoff; - uint64_t total_size = max_offset + ehdr->e_shentsize * ehdr->e_shnum; + uint64_t total_size = max_offset + static_cast(ehdr->e_shentsize) * static_cast(ehdr->e_shnum); for (uint16_t i = 0; i < ehdr->e_shnum; ++i) { uint64_t cur_offset = static_cast(shdr[i].sh_offset);