Skip to content

Commit 0eb054f

Browse files
committed
chore: add test for reading tables with trailing garbage in names
disk3.img contains a label written with 512-byte sector size. disk4.img contains a label with 4096-byte sector size. This test makes sure the CRC checksum performs correctly when the partition table contains such name fields. Both labels contains a partition with (intended) trailing garbage in its name: 0000: af 3d c6 0f 83 84 72 47 8e 79 3d 69 d8 47 7d e4 .=....rG .y=i.G}. 0010: 84 d6 89 47 76 ba 4e 45 b2 50 e0 65 2a 5a 4f 76 ...Gv.NE .P.e*ZOv 0020: 32 00 00 00 00 00 00 00 41 00 00 00 00 00 00 00 2....... A....... 0030: 00 00 00 00 00 00 00 00 4e 00 61 00 6d 00 65 00 ........ N.a.m.e. 0040: 20 00 77 00 69 00 74 00 68 00 20 00 67 00 61 00 .w.i.t. h. .g.a. 0050: 72 00 62 00 61 00 67 00 65 00 00 00 2d 00 3e 00 r.b.a.g. e...-.>. 0060: 20 00 67 00 61 00 72 00 62 00 61 00 67 00 65 00 .g.a.r. b.a.g.e. 0070: 20 00 68 00 65 00 72 00 65 00 21 00 00 00 00 00 .h.e.r. e.!.....
1 parent 78e8c8f commit 0eb054f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ mod test {
13671367

13681368
const DISK1: &str = "tests/fixtures/disk1.img";
13691369
const DISK2: &str = "tests/fixtures/disk2.img";
1370+
const DISK3: &str = "tests/fixtures/disk3.img";
1371+
const DISK4: &str = "tests/fixtures/disk4.img";
13701372

13711373
#[test]
13721374
fn read_header_and_partition_entries() {
@@ -1924,6 +1926,28 @@ mod test {
19241926
test(DISK1, 512);
19251927
test(DISK2, 4096);
19261928
}
1929+
1930+
#[test]
1931+
fn read_label_with_trailing_garbage_in_names() {
1932+
fn test(path: &str, ss: u64) {
1933+
let mut f = fs::File::open(path).unwrap();
1934+
let gpt = GPT::read_from(&mut f, ss);
1935+
// CRC check passes with trailing garbage within partition names
1936+
assert!(gpt.is_ok());
1937+
// Trailing garbage data are visible using hexdump
1938+
assert_eq!(
1939+
gpt.unwrap()
1940+
.partitions
1941+
.get(1)
1942+
.unwrap()
1943+
.partition_name
1944+
.as_str(),
1945+
"Name with garbage"
1946+
);
1947+
}
1948+
test(DISK3, 512);
1949+
test(DISK4, 4096);
1950+
}
19271951
}
19281952

19291953
#[cfg(doctest)]

tests/fixtures/disk3.img

50 KB
Binary file not shown.

tests/fixtures/disk4.img

400 KB
Binary file not shown.

0 commit comments

Comments
 (0)