| ... | ... | @@ -52,6 +52,27 @@ pub fn parse(self: *SharedObject, elf_file: *Elf) !void { |
| 52 | 52 | const reader = stream.reader(); |
| 53 | 53 | |
| 54 | 54 | self.header = try reader.readStruct(elf.Elf64_Ehdr); |
| 55 | |
| 56 | if (elf_file.base.options.target.cpu.arch != self.header.?.e_machine.toTargetCpuArch().?) { |
| 57 | try elf_file.reportParseError2( |
| 58 | self.index, |
| 59 | "invalid cpu architecture: {s}", |
| 60 | .{@tagName(self.header.?.e_machine.toTargetCpuArch().?)}, |
| 61 | ); |
| 62 | return error.InvalidCpuArch; |
| 63 | } |
| 64 | |
| 65 | if (self.data.len < self.header.?.e_shoff or |
| 66 | self.data.len < self.header.?.e_shoff + self.header.?.e_shnum * @sizeOf(elf.Elf64_Shdr)) |
| 67 | { |
| 68 | try elf_file.reportParseError2( |
| 69 | self.index, |
| 70 | "corrupted header: section header table extends past the end of file", |
| 71 | .{}, |
| 72 | ); |
| 73 | return error.LinkFail; |
| 74 | } |
| 75 | |
| 55 | 76 | const shoff = std.math.cast(usize, self.header.?.e_shoff) orelse return error.Overflow; |
| 56 | 77 | |
| 57 | 78 | const shdrs = @as( |
| ... | ... | @@ -61,6 +82,10 @@ pub fn parse(self: *SharedObject, elf_file: *Elf) !void { |
| 61 | 82 | try self.shdrs.ensureTotalCapacityPrecise(gpa, shdrs.len); |
| 62 | 83 | |
| 63 | 84 | for (shdrs, 0..) |shdr, i| { |
| 85 | if (self.data.len < shdr.sh_offset or self.data.len < shdr.sh_offset + shdr.sh_size) { |
| 86 | try elf_file.reportParseError2(self.index, "corrupted section header", .{}); |
| 87 | return error.LinkFail; |
| 88 | } |
| 64 | 89 | self.shdrs.appendAssumeCapacity(try ElfShdr.fromElf64Shdr(shdr)); |
| 65 | 90 | switch (shdr.sh_type) { |
| 66 | 91 | elf.SHT_DYNSYM => self.dynsym_sect_index = @as(u16, @intCast(i)), |