From 877165a6c9fd70ce3ac1d988ca10636e383302fd Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 11 Oct 2026 16:41:30 +0200 Subject: [PATCH] Read region headers as vanilla's RegionFile does in the region tests Invalid allocations are dropped rather than refused, overlaps are not checked, and an empty or truncated file is a region without chunks. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-world/tests/world_io.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/horizon-world/tests/world_io.rs b/crates/horizon-world/tests/world_io.rs index bbbfab360..65b5006a8 100644 --- a/crates/horizon-world/tests/world_io.rs +++ b/crates/horizon-world/tests/world_io.rs @@ -120,12 +120,21 @@ fn malformed_region(path: &Path, first: u32, second: u32, payload_len: u32, code } #[test] -fn corrupt_allocations_lengths_codecs_and_missing_external_files_fail() { +fn corrupt_allocations_are_dropped_and_bad_payloads_fail() { let dir = Directory::new(); - for (first, second) in [(257, 0), (512, 0), (1025, 0), (513, 513)] { + // RegionFile's constructor drops (and logs) entries whose sector overlaps the + // header, that have no sectors or that start past the end of the file; it + // does not check overlaps between chunks. + for (first, second, chunks) in [(257, 0, 0), (512, 0, 0), (1025, 0, 0), (513, 513, 2)] { malformed_region(&dir.region(), first, second, 1, 3); - assert!(RegionFile::open(dir.region()).is_err()); + let reader = RegionFile::open(dir.region()).unwrap(); + assert_eq!(reader.chunks().count(), chunks); } + // An empty or truncated file reads as a region without chunks. + fs::write(dir.region(), b"").unwrap(); + assert_eq!(RegionFile::open(dir.region()).unwrap().chunks().count(), 0); + fs::write(dir.region(), [0, 0, 2, 1]).unwrap(); + assert_eq!(RegionFile::open(dir.region()).unwrap().chunks().count(), 0); for (len, codec) in [ (0, 3), (4093, 3),