motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit f551c7c581c7bf1f3324c0611a73c22f2aae82b4 (tree)
parent 5360968e03525be4d312ca61a7ba2dcb7890ec42
Author: Isaac Freund <mail@isaacfreund.com>
Date:   Wed,  9 Jul 2025 19:03:16 +0200

link.Elf: check files in archives for ELF magic

Apparently raw LLVM IR Bitcode files ("Bitstreams") may appear in
archives with LTO enabled. I observed this in the wild on
Chimera Linux.

I'm not yet sure if it's in scope for Zig to support these special
archives, but we should at least give a correct error message.

Diffstat:
Msrc/link/Elf/Object.zig | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig @@ -106,6 +106,9 @@ pub fn parseCommon( const header_buffer = try Elf.preadAllAlloc(gpa, handle, offset, @sizeOf(elf.Elf64_Ehdr)); defer gpa.free(header_buffer); self.header = @as(*align(1) const elf.Elf64_Ehdr, @ptrCast(header_buffer)).*; + if (!mem.eql(u8, self.header.?.e_ident[0..4], elf.MAGIC)) { + return diags.failParse(path, "not an ELF file", .{}); + } const em = target.toElfMachine(); if (em != self.header.?.e_machine) {