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 <Sunday.Clement@amd.com>
This commit is contained in:
committed by
Clement, Sunday
parent
9b3d15e68d
commit
d00ca2e9b7
@@ -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<uint64_t>(ehdr->e_shentsize) * static_cast<uint64_t>(ehdr->e_shnum);
|
||||
|
||||
for (uint16_t i = 0; i < ehdr->e_shnum; ++i) {
|
||||
uint64_t cur_offset = static_cast<uint64_t>(shdr[i].sh_offset);
|
||||
|
||||
Reference in New Issue
Block a user