File tree 3 files changed +14
-5
lines changed
3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -914,6 +914,7 @@ fn parseInputFileWorker(self: *MachO, file: File) void {
914
914
switch (err ) {
915
915
error .MalformedObject ,
916
916
error .MalformedDylib ,
917
+ error .MalformedTbd ,
917
918
error .InvalidCpuArch ,
918
919
error .InvalidTarget ,
919
920
= > {}, // already reported
@@ -4637,7 +4638,6 @@ const ObjcStubsSection = synthetic.ObjcStubsSection;
4637
4638
const Object = @import ("MachO/Object.zig" );
4638
4639
const LazyBind = bind .LazyBind ;
4639
4640
const LaSymbolPtrSection = synthetic .LaSymbolPtrSection ;
4640
- const LibStub = tapi .LibStub ;
4641
4641
const Liveness = @import ("../Liveness.zig" );
4642
4642
const LlvmObject = @import ("../codegen/llvm.zig" ).Object ;
4643
4643
const Md5 = std .crypto .hash .Md5 ;
Original file line number Diff line number Diff line change @@ -270,7 +270,10 @@ fn parseTbd(self: *Dylib, macho_file: *MachO) !void {
270
270
log .debug ("parsing dylib from stub: {s}" , .{self .path });
271
271
272
272
const file = macho_file .getFileHandle (self .file_handle );
273
- var lib_stub = LibStub .loadFromFile (gpa , file ) catch return error .NotLibStub ;
273
+ var lib_stub = LibStub .loadFromFile (gpa , file ) catch | err | {
274
+ try macho_file .reportParseError2 (self .index , "failed to parse TBD file: {s}" , .{@errorName (err )});
275
+ return error .MalformedTbd ;
276
+ };
274
277
defer lib_stub .deinit ();
275
278
const umbrella_lib = lib_stub .inner [0 ];
276
279
Original file line number Diff line number Diff line change @@ -129,8 +129,8 @@ pub const Tbd = union(enum) {
129
129
130
130
pub const TapiError = error {
131
131
NotLibStub ,
132
- FileTooBig ,
133
- } || yaml .YamlError || std .fs .File .ReadError ;
132
+ InputOutput ,
133
+ } || yaml .YamlError || std .fs .File .PReadError ;
134
134
135
135
pub const LibStub = struct {
136
136
/// Underlying memory for stub's contents.
@@ -140,8 +140,14 @@ pub const LibStub = struct {
140
140
inner : []Tbd ,
141
141
142
142
pub fn loadFromFile (allocator : Allocator , file : fs.File ) TapiError ! LibStub {
143
- const source = try file .readToEndAlloc (allocator , std .math .maxInt (u32 ));
143
+ const filesize = blk : {
144
+ const stat = file .stat () catch break :blk std .math .maxInt (u32 );
145
+ break :blk @min (stat .size , std .math .maxInt (u32 ));
146
+ };
147
+ const source = try allocator .alloc (u8 , filesize );
144
148
defer allocator .free (source );
149
+ const amt = try file .preadAll (source , 0 );
150
+ if (amt != filesize ) return error .InputOutput ;
145
151
146
152
var lib_stub = LibStub {
147
153
.yaml = try Yaml .load (allocator , source ),
You can’t perform that action at this time.
0 commit comments