Skip to content

Commit ea32e40

Browse files
committed
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.
1 parent 31e46be commit ea32e40

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/link/Elf/Object.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ pub fn parseCommon(
106106
const header_buffer = try Elf.preadAllAlloc(gpa, handle, offset, @sizeOf(elf.Elf64_Ehdr));
107107
defer gpa.free(header_buffer);
108108
self.header = @as(*align(1) const elf.Elf64_Ehdr, @ptrCast(header_buffer)).*;
109+
if (!mem.eql(u8, self.header.?.e_ident[0..4], elf.MAGIC)) {
110+
return diags.failParse(path, "not an ELF file", .{});
111+
}
109112

110113
const em = target.toElfMachine();
111114
if (em != self.header.?.e_machine) {

0 commit comments

Comments
 (0)