authorgravatar for SonnyBonds@noreply.codeberg.orgAnders Stenberg <SonnyBonds@noreply.codeberg.org> 2026-05-12 20:43:37+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-17 18:55:27+01:00
log9ba45527931e9e43a77d42a52b63a0203e029bd0
tree8ec8496adea59f0124adbad1c0eb01e246d28902
parent97fe49a80f1aa24ebd7101635367c31bfb563078
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: avoid overflow in shentsize * shnum calculations


1 files changed, 3 insertions(+), 3 deletions(-)

src/link/Elf2.zig+3-3
......@@ -2091,7 +2091,7 @@ fn initHeaders(
20912091 }
20922092
20932093 assert(elf.ni.shdr == try elf.mf.addLastChildNode(gpa, elf.ni.file, .{
2094 .size = elf.ehdrField(.shentsize) * elf.ehdrField(.shnum),
2094 .size = @as(u64, elf.ehdrField(.shentsize)) * @as(u64, elf.ehdrField(.shnum)),
20952095 .alignment = elf.mf.flags.block_size,
20962096 .moved = true,
20972097 .resized = true,
......@@ -3076,7 +3076,7 @@ fn loadObject(
30763076 if (ehdr.machine != elf.ehdrField(.machine))
30773077 return diags.failParse(path, "bad machine", .{});
30783078 if (ehdr.shoff == 0 or ehdr.shnum <= 1) return;
3079 if (ehdr.shoff + ehdr.shentsize * ehdr.shnum > fl.size)
3079 if (ehdr.shoff + @as(u64, ehdr.shentsize) * @as(u64, ehdr.shnum) > fl.size)
30803080 return diags.failParse(path, "bad section header location", .{});
30813081 if (ehdr.shentsize < @sizeOf(ElfN.Shdr))
30823082 return diags.failParse(path, "unsupported shentsize", .{});
......@@ -3638,7 +3638,7 @@ fn addSection(elf: *Elf, segment_ni: MappedFile.Node.Index, opts: struct {
36383638 },
36393639 };
36403640 assert(shndx < @intFromEnum(Section.Index.LORESERVE));
3641 break :shndx .{ @enumFromInt(shndx), elf.targetLoad(&ehdr.shentsize) * shnum };
3641 break :shndx .{ @enumFromInt(shndx), @as(u64, elf.targetLoad(&ehdr.shentsize)) * @as(u64, shnum) };
36423642 },
36433643 };
36443644 _, const shdr_node_size = elf.ni.shdr.location(&elf.mf).resolve(&elf.mf);