#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::io::Write;
const FOOTER: u64 = 512;
const DYN_HEADER: u64 = 1024;
fn dynamic_vhd(max_entries: u32) -> tempfile::NamedTempFile {
let table_offset = FOOTER + DYN_HEADER;
let mut footer = [0u8; 512];
footer[0..8].copy_from_slice(b"conectix");
footer[16..24].copy_from_slice(&FOOTER.to_be_bytes()); footer[48..56].copy_from_slice(&(2 * 1024 * 1024u64).to_be_bytes()); footer[60..64].copy_from_slice(&3u32.to_be_bytes());
let mut dh = [0u8; 1024];
dh[0..8].copy_from_slice(b"cxsparse");
dh[16..24].copy_from_slice(&table_offset.to_be_bytes());
dh[28..32].copy_from_slice(&max_entries.to_be_bytes());
dh[32..36].copy_from_slice(&(2 * 1024 * 1024u32).to_be_bytes());
let mut f = tempfile::NamedTempFile::new().unwrap();
f.write_all(&footer).unwrap(); f.write_all(&dh).unwrap();
f.write_all(&[0u8; 512]).unwrap(); f.write_all(&footer).unwrap(); f.flush().unwrap();
f
}
#[test]
fn vhd_bat_entry_count_is_bounded_by_the_file() {
let f = dynamic_vhd(u32::MAX);
let err = disk_forensic::container::open(f.path()).expect_err("must reject");
let msg = err.to_string();
assert!(
msg.contains("BAT") || msg.contains("bat"),
"expected a BAT-bounds error naming the offending size, got: {msg}"
);
}
#[test]
fn vhd_with_honest_bat_still_opens() {
let f = dynamic_vhd(128);
assert!(
disk_forensic::container::open(f.path()).is_ok(),
"a well-formed dynamic VHD must still open"
);
}