Skip to content

Commit 98a4a20

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 a3b0dd9 commit 98a4a20

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
@@ -1368,6 +1368,8 @@ mod test {
13681368

13691369
const DISK1: &str = "tests/fixtures/disk1.img";
13701370
const DISK2: &str = "tests/fixtures/disk2.img";
1371+
const DISK3: &str = "tests/fixtures/disk3.img";
1372+
const DISK4: &str = "tests/fixtures/disk4.img";
13711373

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

19301954
#[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)