diff --git a/crates/format/src/store.rs b/crates/format/src/store.rs index 2b84a4a124..ae76140ab9 100644 --- a/crates/format/src/store.rs +++ b/crates/format/src/store.rs @@ -155,6 +155,8 @@ impl ByteSource for ZipSource<'_> { fn bundle_error(error: craft_pcraft_bundle::Error) -> FormatError { match error { craft_pcraft_bundle::Error::LimitExceeded { entry, limit } => FormatError::LimitExceeded(format!("`{entry}` exceeds {limit} bytes")), + // A ZIP member past its read bound arrives as a craft-zip error, not as `LimitExceeded`. + craft_pcraft_bundle::Error::Zip(error) => crate::zip::map_read_error(error), other => FormatError::corrupt(other.to_string()), } } diff --git a/crates/format/src/zip.rs b/crates/format/src/zip.rs index d3ded4bb9b..20443a1cbf 100644 --- a/crates/format/src/zip.rs +++ b/crates/format/src/zip.rs @@ -24,7 +24,7 @@ pub struct ZipReader<'a> { by_name: HashMap, } -fn map_read_error(error: craft_zip::Error) -> FormatError { +pub(crate) fn map_read_error(error: craft_zip::Error) -> FormatError { match error { craft_zip::Error::TooManyEntries { .. } | craft_zip::Error::TooManyEndRecords(_) diff --git a/crates/format/tests/it/directory_symlinks.rs b/crates/format/tests/it/directory_symlinks.rs index 0a8d7d2462..198ffdce24 100644 --- a/crates/format/tests/it/directory_symlinks.rs +++ b/crates/format/tests/it/directory_symlinks.rs @@ -19,6 +19,9 @@ fn directory_cleanup_preserves_unrelated_zst_files() { let mut writer = PcraftWriter::new(); writer.save_dir(&empty_doc(), &bundle, &SaveOptions::default()).unwrap(); + // An empty document writes no objects, so a save creates neither folder. + std::fs::create_dir_all(bundle.join("tiles")).unwrap(); + std::fs::create_dir_all(bundle.join("blobs")).unwrap(); let unrelated = bundle.join("tiles/personal-notes.zst"); let orphan = bundle.join("blobs").join(format!("{}.zst", "b".repeat(64))); std::fs::write(&unrelated, b"unrelated file").unwrap();