From 2374e48432e07ad324885219bcb563d0955c2639 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 3 Dec 2023 19:56:25 +0100 Subject: [PATCH] macho: fix possible integer overflow when calc atom and lsda offsets --- src/MachO/Object.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MachO/Object.zig b/src/MachO/Object.zig index 7ecd3a64..4a9aacdc 100644 --- a/src/MachO/Object.zig +++ b/src/MachO/Object.zig @@ -540,7 +540,7 @@ fn initUnwindRecords(self: *Object, sect_id: u8, macho_file: *MachO) !void { .local => { out.atom = self.findAtom(rec.rangeStart); const atom = out.getAtom(macho_file); - out.atom_offset = @intCast(atom.getInputAddress(macho_file) - rec.rangeStart); + out.atom_offset = @intCast(rec.rangeStart - atom.getInputAddress(macho_file)); }, }, 16 => { // personality function @@ -555,7 +555,7 @@ fn initUnwindRecords(self: *Object, sect_id: u8, macho_file: *MachO) !void { .local => { out.lsda = self.findAtom(rec.lsda); const atom = out.getLsdaAtom(macho_file).?; - out.lsda_offset = @intCast(atom.getInputAddress(macho_file) - rec.lsda); + out.lsda_offset = @intCast(rec.lsda - atom.getInputAddress(macho_file)); }, }, else => {},