| ... | ... | @@ -1015,7 +1015,8 @@ fn initEhFrameRecords(self: *Object, allocator: Allocator, sect_id: u8, file: Fi |
| 1015 | 1015 | const sect = slice.items(.header)[sect_id]; |
| 1016 | 1016 | const relocs = slice.items(.relocs)[sect_id]; |
| 1017 | 1017 | |
| 1018 | | try self.eh_frame_data.resize(allocator, sect.size); |
| 1018 | const size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 1019 | try self.eh_frame_data.resize(allocator, size); |
| 1019 | 1020 | const amt = try file.preadAll(self.eh_frame_data.items, sect.offset + self.offset); |
| 1020 | 1021 | if (amt != self.eh_frame_data.items.len) return error.InputOutput; |
| 1021 | 1022 | |
| ... | ... | @@ -1116,7 +1117,8 @@ fn initUnwindRecords(self: *Object, allocator: Allocator, sect_id: u8, file: Fil |
| 1116 | 1117 | }; |
| 1117 | 1118 | |
| 1118 | 1119 | const header = self.sections.items(.header)[sect_id]; |
| 1119 | | const data = try allocator.alloc(u8, header.size); |
| 1120 | const size = math.cast(usize, header.size) orelse return error.Overflow; |
| 1121 | const data = try allocator.alloc(u8, size); |
| 1120 | 1122 | defer allocator.free(data); |
| 1121 | 1123 | const amt = try file.preadAll(data, header.offset + self.offset); |
| 1122 | 1124 | if (amt != data.len) return error.InputOutput; |
| ... | ... | @@ -1346,7 +1348,8 @@ fn parseDebugInfo(self: *Object, macho_file: *MachO) !void { |
| 1346 | 1348 | const file = macho_file.getFileHandle(self.file_handle); |
| 1347 | 1349 | const debug_info = blk: { |
| 1348 | 1350 | const sect = slice.items(.header)[debug_info_index.?]; |
| 1349 | | const data = try gpa.alloc(u8, sect.size); |
| 1351 | const size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 1352 | const data = try gpa.alloc(u8, size); |
| 1350 | 1353 | const amt = try file.preadAll(data, sect.offset + self.offset); |
| 1351 | 1354 | if (amt != data.len) return error.InputOutput; |
| 1352 | 1355 | break :blk data; |
| ... | ... | @@ -1354,7 +1357,8 @@ fn parseDebugInfo(self: *Object, macho_file: *MachO) !void { |
| 1354 | 1357 | defer gpa.free(debug_info); |
| 1355 | 1358 | const debug_abbrev = blk: { |
| 1356 | 1359 | const sect = slice.items(.header)[debug_abbrev_index.?]; |
| 1357 | | const data = try gpa.alloc(u8, sect.size); |
| 1360 | const size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 1361 | const data = try gpa.alloc(u8, size); |
| 1358 | 1362 | const amt = try file.preadAll(data, sect.offset + self.offset); |
| 1359 | 1363 | if (amt != data.len) return error.InputOutput; |
| 1360 | 1364 | break :blk data; |
| ... | ... | @@ -1362,7 +1366,8 @@ fn parseDebugInfo(self: *Object, macho_file: *MachO) !void { |
| 1362 | 1366 | defer gpa.free(debug_abbrev); |
| 1363 | 1367 | const debug_str = if (debug_str_index) |sid| blk: { |
| 1364 | 1368 | const sect = slice.items(.header)[sid]; |
| 1365 | | const data = try gpa.alloc(u8, sect.size); |
| 1369 | const size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 1370 | const data = try gpa.alloc(u8, size); |
| 1366 | 1371 | const amt = try file.preadAll(data, sect.offset + self.offset); |
| 1367 | 1372 | if (amt != data.len) return error.InputOutput; |
| 1368 | 1373 | break :blk data; |
| ... | ... | @@ -1864,7 +1869,8 @@ pub fn writeAtoms(self: *Object, macho_file: *MachO) !void { |
| 1864 | 1869 | |
| 1865 | 1870 | for (headers, 0..) |header, n_sect| { |
| 1866 | 1871 | if (header.isZerofill()) continue; |
| 1867 | | const data = try gpa.alloc(u8, header.size); |
| 1872 | const size = math.cast(usize, header.size) orelse return error.Overflow; |
| 1873 | const data = try gpa.alloc(u8, size); |
| 1868 | 1874 | const amt = try file.preadAll(data, header.offset + self.offset); |
| 1869 | 1875 | if (amt != data.len) return error.InputOutput; |
| 1870 | 1876 | sections_data[n_sect] = data; |
| ... | ... | @@ -1874,11 +1880,13 @@ pub fn writeAtoms(self: *Object, macho_file: *MachO) !void { |
| 1874 | 1880 | if (!atom.flags.alive) continue; |
| 1875 | 1881 | const sect = atom.getInputSection(macho_file); |
| 1876 | 1882 | if (sect.isZerofill()) continue; |
| 1877 | | const off = atom.value; |
| 1883 | const value = math.cast(usize, atom.value) orelse return error.Overflow; |
| 1884 | const off = math.cast(usize, atom.off) orelse return error.Overflow; |
| 1885 | const size = math.cast(usize, atom.size) orelse return error.Overflow; |
| 1878 | 1886 | const buffer = macho_file.sections.items(.out)[atom.out_n_sect].items; |
| 1879 | 1887 | const data = sections_data[atom.n_sect]; |
| 1880 | | @memcpy(buffer[off..][0..atom.size], data[atom.off..][0..atom.size]); |
| 1881 | | try atom.resolveRelocs(macho_file, buffer[off..][0..atom.size]); |
| 1888 | @memcpy(buffer[value..][0..size], data[off..][0..size]); |
| 1889 | try atom.resolveRelocs(macho_file, buffer[value..][0..size]); |
| 1882 | 1890 | } |
| 1883 | 1891 | } |
| 1884 | 1892 | |
| ... | ... | @@ -1900,7 +1908,8 @@ pub fn writeAtomsRelocatable(self: *Object, macho_file: *MachO) !void { |
| 1900 | 1908 | |
| 1901 | 1909 | for (headers, 0..) |header, n_sect| { |
| 1902 | 1910 | if (header.isZerofill()) continue; |
| 1903 | | const data = try gpa.alloc(u8, header.size); |
| 1911 | const size = math.cast(usize, header.size) orelse return error.Overflow; |
| 1912 | const data = try gpa.alloc(u8, size); |
| 1904 | 1913 | const amt = try file.preadAll(data, header.offset + self.offset); |
| 1905 | 1914 | if (amt != data.len) return error.InputOutput; |
| 1906 | 1915 | sections_data[n_sect] = data; |
| ... | ... | @@ -1910,13 +1919,15 @@ pub fn writeAtomsRelocatable(self: *Object, macho_file: *MachO) !void { |
| 1910 | 1919 | if (!atom.flags.alive) continue; |
| 1911 | 1920 | const sect = atom.getInputSection(macho_file); |
| 1912 | 1921 | if (sect.isZerofill()) continue; |
| 1913 | | const off = atom.value; |
| 1922 | const value = math.cast(usize, atom.value) orelse return error.Overflow; |
| 1923 | const off = math.cast(usize, atom.off) orelse return error.Overflow; |
| 1924 | const size = math.cast(usize, atom.size) orelse return error.Overflow; |
| 1914 | 1925 | const buffer = macho_file.sections.items(.out)[atom.out_n_sect].items; |
| 1915 | 1926 | const data = sections_data[atom.n_sect]; |
| 1916 | | @memcpy(buffer[off..][0..atom.size], data[atom.off..][0..atom.size]); |
| 1927 | @memcpy(buffer[value..][0..size], data[off..][0..size]); |
| 1917 | 1928 | const relocs = macho_file.sections.items(.relocs)[atom.out_n_sect].items; |
| 1918 | 1929 | const extra = atom.getExtra(macho_file); |
| 1919 | | try atom.writeRelocs(macho_file, buffer[off..][0..atom.size], relocs[extra.rel_out_index..][0..extra.rel_out_count]); |
| 1930 | try atom.writeRelocs(macho_file, buffer[value..][0..size], relocs[extra.rel_out_index..][0..extra.rel_out_count]); |
| 1920 | 1931 | } |
| 1921 | 1932 | } |
| 1922 | 1933 | |
| ... | ... | @@ -2812,7 +2823,8 @@ const x86_64 = struct { |
| 2812 | 2823 | } |
| 2813 | 2824 | const relocs = @as([*]align(1) const macho.relocation_info, @ptrCast(relocs_buffer.ptr))[0..sect.nreloc]; |
| 2814 | 2825 | |
| 2815 | | const code = try gpa.alloc(u8, sect.size); |
| 2826 | const sect_size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 2827 | const code = try gpa.alloc(u8, sect_size); |
| 2816 | 2828 | defer gpa.free(code); |
| 2817 | 2829 | { |
| 2818 | 2830 | const amt = try handle.preadAll(code, sect.offset + self.offset); |
| ... | ... | @@ -2984,7 +2996,8 @@ const aarch64 = struct { |
| 2984 | 2996 | } |
| 2985 | 2997 | const relocs = @as([*]align(1) const macho.relocation_info, @ptrCast(relocs_buffer.ptr))[0..sect.nreloc]; |
| 2986 | 2998 | |
| 2987 | | const code = try gpa.alloc(u8, sect.size); |
| 2999 | const sect_size = math.cast(usize, sect.size) orelse return error.Overflow; |
| 3000 | const code = try gpa.alloc(u8, sect_size); |
| 2988 | 3001 | defer gpa.free(code); |
| 2989 | 3002 | { |
| 2990 | 3003 | const amt = try handle.preadAll(code, sect.offset + self.offset); |