| ... | ... | @@ -1205,12 +1205,14 @@ pub const Coff = struct { |
| 1205 | 1205 | return .{ .buffer = self.data[offset..][0..size] }; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | | pub fn getStrtab(self: *const Coff) ?Strtab { |
| 1208 | pub fn getStrtab(self: *const Coff) error{InvalidStrtabSize}!?Strtab { |
| 1209 | 1209 | const coff_header = self.getCoffHeader(); |
| 1210 | 1210 | if (coff_header.pointer_to_symbol_table == 0) return null; |
| 1211 | 1211 | |
| 1212 | 1212 | const offset = coff_header.pointer_to_symbol_table + Symbol.sizeOf() * coff_header.number_of_symbols; |
| 1213 | 1213 | const size = mem.readIntLittle(u32, self.data[offset..][0..4]); |
| 1214 | if ((offset + size) > self.data.len) return error.InvalidStrtabSize; |
| 1215 | |
| 1214 | 1216 | return Strtab{ .buffer = self.data[offset..][0..size] }; |
| 1215 | 1217 | } |
| 1216 | 1218 | |
| ... | ... | @@ -1235,9 +1237,9 @@ pub const Coff = struct { |
| 1235 | 1237 | return out_buff; |
| 1236 | 1238 | } |
| 1237 | 1239 | |
| 1238 | | pub fn getSectionName(self: *const Coff, sect_hdr: *align(1) const SectionHeader) []const u8 { |
| 1240 | pub fn getSectionName(self: *const Coff, sect_hdr: *align(1) const SectionHeader) error{InvalidStrtabSize}![]const u8 { |
| 1239 | 1241 | const name = sect_hdr.getName() orelse blk: { |
| 1240 | | const strtab = self.getStrtab().?; |
| 1242 | const strtab = (try self.getStrtab()).?; |
| 1241 | 1243 | const name_offset = sect_hdr.getNameOffset().?; |
| 1242 | 1244 | break :blk strtab.get(name_offset); |
| 1243 | 1245 | }; |
| ... | ... | @@ -1246,7 +1248,10 @@ pub const Coff = struct { |
| 1246 | 1248 | |
| 1247 | 1249 | pub fn getSectionByName(self: *const Coff, comptime name: []const u8) ?*align(1) const SectionHeader { |
| 1248 | 1250 | for (self.getSectionHeaders()) |*sect| { |
| 1249 | | if (mem.eql(u8, self.getSectionName(sect), name)) { |
| 1251 | const section_name = self.getSectionName(sect) catch |e| switch (e) { |
| 1252 | error.InvalidStrtabSize => continue, //ignore invalid(?) strtab entries - see also GitHub issue #15238 |
| 1253 | }; |
| 1254 | if (mem.eql(u8, section_name, name)) { |
| 1250 | 1255 | return sect; |
| 1251 | 1256 | } |
| 1252 | 1257 | } |