Skip to content

Commit a99fd43

Browse files
committed
Avoid leaking file metadata (mtime/UID/GID) in rlibs through the ar crate.
1 parent 3cd665a commit a99fd43

File tree

1 file changed

+10
-1
lines changed
  • crates/rustc_codegen_spirv/src

1 file changed

+10
-1
lines changed

crates/rustc_codegen_spirv/src/link.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,16 @@ fn create_archive(files: &[&Path], metadata: &[u8], out_filename: &Path) {
491491
"Duplicate filename in archive: {:?}",
492492
file.file_name().unwrap()
493493
);
494-
builder.append_path(file).unwrap();
494+
495+
// NOTE(eddyb) we can't use `append_path` or `append_file`, as they
496+
// record too much metadata by default (mtime/UID/GID, at least),
497+
// which is determintal to reproducible build artifacts, but also
498+
// can misbehave in environments with high UIDs/GIDs (see #889).
499+
let file = File::open(file).unwrap();
500+
let header = Header::new(name.as_bytes().to_vec(), file.metadata().unwrap().len());
501+
// NOTE(eddyb) either `fs::File`, or the result of `fs::read`, could fit
502+
// here, but `fs::File` has specialized file->file copying on some OSes.
503+
builder.append(&header, file).unwrap();
495504
}
496505
builder.into_inner().unwrap();
497506
}

0 commit comments

Comments
 (0)