Zig Version
0.16.0
Steps to Reproduce and Observed Behavior
zig cc -c foo.c -o foo.obj -target x86_64-windows
then
conststd=@import("std");pubfnmain(init:std.process.Init)!void{constsource_file=trystd.Io.Dir.cwd().openFile(init.io,"foo.obj",.{});defersource_file.close(init.io);varread_buffer:[2048]u8=undefined;varfile_reader:std.Io.File.Reader=source_file.reader(init.io,&read_buffer);varbuffer:std.ArrayList(u8)=.empty;deferbuffer.deinit(init.gpa);tryfile_reader.interface.appendRemaining(init.gpa,&buffer,.unlimited);constfile=trybuffer.toOwnedSlice(init.gpa);deferinit.gpa.free(file);constcoff=trystd.coff.Coff.init(file,false);_=coff;}I err with
C:\Zig\lib\std\coff.zig:979:43: 0x7ff78f69f2a1 in init (test_zcu.obj)
if (data.len < header_offset + 4) return error.EndOfStream;
^
C:\Users7円743l\Desktop\Giit\Zar\test\zstd\lib\decompress\test.zig:17:18: 0x7ff78f72d91d in main (test_zcu.obj)
const coff = try std.coff.Coff.init(file, false);
Expected Behavior
Run without err.
The issue lies within std.coff.Coff.init obj file kind detection.
PE-files start with a Dos-Header, that points towards the actual header on offset 0x3c or the field address_of_new_exe_header: u32, but plain .obj files begin with a Header.
a proper .init would be detect if we have a leading DOS-Header (NZ magic) and only then jump to read the header Position of the aforementioned offset. Otherwise assume we have a leading Header.
### Zig Version
0.16.0
### Steps to Reproduce and Observed Behavior
``` bash
zig cc -c foo.c -o foo.obj -target x86_64-windows
```
then
``` zig
const std = @import("std");
pub fn main(init: std.process.Init) !void {
const source_file = try std.Io.Dir.cwd().openFile(init.io, "foo.obj", .{});
defer source_file.close(init.io);
var read_buffer: [2048]u8 = undefined;
var file_reader: std.Io.File.Reader = source_file.reader(init.io, &read_buffer);
var buffer: std.ArrayList(u8) = .empty;
defer buffer.deinit(init.gpa);
try file_reader.interface.appendRemaining(init.gpa, &buffer, .unlimited);
const file = try buffer.toOwnedSlice(init.gpa);
defer init.gpa.free(file);
const coff = try std.coff.Coff.init(file, false);
_ = coff;
}
```
I err with
``` bash
C:\Zig\lib\std\coff.zig:979:43: 0x7ff78f69f2a1 in init (test_zcu.obj)
if (data.len < header_offset + 4) return error.EndOfStream;
^
C:\Users7743円l\Desktop\Giit\Zar\test\zstd\lib\decompress\test.zig:17:18: 0x7ff78f72d91d in main (test_zcu.obj)
const coff = try std.coff.Coff.init(file, false);
```
### Expected Behavior
**Run without err.**
The issue lies within std.coff.Coff.init obj file kind detection.
PE-files start with a Dos-Header, that points towards the actual header on offset 0x3c or the field address_of_new_exe_header: u32, but plain .obj files begin with a Header.
a proper .init would be detect if we have a leading DOS-Header (NZ magic) and only then jump to read the header Position of the aforementioned offset. Otherwise assume we have a leading Header.