Commit e5483b4ffc
Changed files (2)
src
link
src/link/Elf/Object.zig
@@ -945,7 +945,9 @@ fn preadShdrContentsAlloc(self: Object, allocator: Allocator, handle: std.fs.Fil
assert(index < self.shdrs.items.len);
const offset = if (self.archive) |ar| ar.offset else 0;
const shdr = self.shdrs.items[index];
- return Elf.preadAllAlloc(allocator, handle, offset + shdr.sh_offset, shdr.sh_size);
+ const sh_offset = math.cast(u64, shdr.sh_offset) orelse return error.Overflow;
+ const sh_size = math.cast(u64, shdr.sh_size) orelse return error.Overflow;
+ return Elf.preadAllAlloc(allocator, handle, offset + sh_offset, sh_size);
}
/// Caller owns the memory.
src/link/Elf.zig
@@ -5903,8 +5903,8 @@ fn fmtDumpState(
}
/// Caller owns the memory.
-pub fn preadAllAlloc(allocator: Allocator, handle: std.fs.File, offset: usize, size: usize) ![]u8 {
- const buffer = try allocator.alloc(u8, size);
+pub fn preadAllAlloc(allocator: Allocator, handle: std.fs.File, offset: u64, size: u64) ![]u8 {
+ const buffer = try allocator.alloc(u8, math.cast(usize, size) orelse return error.Overflow);
errdefer allocator.free(buffer);
const amt = try handle.preadAll(buffer, offset);
if (amt != size) return error.InputOutput;