Skip to content

Commit ba1659d

Browse files
committed
[WIP]
1 parent cc427c3 commit ba1659d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

ar_test.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! ```cargo
2+
//! [dependencies]
3+
//! ar = "0.6.2"
4+
//! ```
5+
6+
use std::io::Read;
7+
8+
// 64 gives Invalid file size field in entry header
9+
// 32 gives unexpected EOF in the middle of archive entry header
10+
const METADATA_LEN: usize = 64;
11+
12+
fn main() {
13+
let mut builder = ar::Builder::new(std::fs::File::create("test.a").expect("create"));
14+
15+
// Remove this append and there is no problem.
16+
let header = ar::Header::new(b"core-fc675.rcgu.o".to_vec(), 0);
17+
// Remove any of the characters in the filename and ! from will show up in the error message.
18+
// Making it shorter than 17 chars will fix the problem though.
19+
20+
builder.append(&header, &mut (&[] as &[u8])).expect("add rcgu");
21+
22+
let mut buf: Vec<u8> = vec!['!' as u8; 28];
23+
buf.extend(b"hello worl");
24+
buf.extend(&['*' as u8; 26] as &[u8]);
25+
assert!(buf.len() >= METADATA_LEN);
26+
27+
let header = ar::Header::new(b"rust.metadata.bin".to_vec(), METADATA_LEN as u64);
28+
builder.append(&header, &mut (&buf[0..METADATA_LEN])).expect("add meta");
29+
30+
std::mem::drop(builder);
31+
32+
// Remove this ranlib invocation and there is no problem.
33+
/*assert!(
34+
std::process::Command::new("ranlib")
35+
.arg("test.a")
36+
.status()
37+
.expect("Couldn't run ranlib")
38+
.success()
39+
);*/
40+
41+
let mut archive = ar::Archive::new(std::fs::File::open("test.a").expect("open"));
42+
while let Some(entry) = archive.next_entry() {
43+
entry.unwrap();
44+
}
45+
}

0 commit comments

Comments
 (0)