Commit 5b315f8a3a
Changed files (2)
src
link
src/link/MachO/InternalObject.zig
@@ -169,13 +169,16 @@ pub fn getAtomData(self: *const InternalObject, atom: Atom, buffer: []u8) !void
const slice = self.sections.slice();
const sect = slice.items(.header)[atom.n_sect];
const extra = slice.items(.extra)[atom.n_sect];
- const data = if (extra.is_objc_methname)
- self.objc_methnames.items[sect.offset..][0..sect.size]
- else if (extra.is_objc_selref)
+ const data = if (extra.is_objc_methname) blk: {
+ const size = std.math.cast(usize, sect.size) orelse return error.Overflow;
+ break :blk self.objc_methnames.items[sect.offset..][0..size];
+ } else if (extra.is_objc_selref)
&self.objc_selrefs
else
@panic("ref to non-existent section");
- @memcpy(buffer, data[atom.off..][0..atom.size]);
+ const off = std.math.cast(usize, atom.off) orelse return error.Overflow;
+ const size = std.math.cast(usize, atom.size) orelse return error.Overflow;
+ @memcpy(buffer, data[off..][0..size]);
}
pub fn getAtomRelocs(self: *const InternalObject, atom: Atom) []const Relocation {
src/link/MachO/Object.zig
@@ -1589,7 +1589,8 @@ fn getSectionData(self: *const Object, allocator: Allocator, index: u32) ![]u8 {
assert(index < slice.items(.header).len);
const sect = slice.items(.header)[index];
const offset = if (self.archive) |ar| ar.offset else 0;
- const buffer = try allocator.alloc(u8, sect.size);
+ const size = math.cast(usize, sect.size) orelse return error.Overflow;
+ const buffer = try allocator.alloc(u8, size);
errdefer allocator.free(buffer);
const amt = try self.file.preadAll(buffer, sect.offset + offset);
if (amt != buffer.len) return error.InputOutput;