From 3a7e13cd3377f14e79089a9ce5773aa190d44b42 Mon Sep 17 00:00:00 2001 From: Hasan-Zayni Date: Sat, 14 Nov 2026 12:58:48 +0300 Subject: [PATCH] format: report a ZIP member over its read bound as LimitExceeded craft-libs' bundle reader returns Error::Zip(EntryTooLarge) for a member past its read bound; map it through zip::map_read_error so it surfaces as LimitExceeded, not Corrupt. The directory cleanup test now creates tiles/ and blobs/ itself, since an empty document's save no longer makes them. --- crates/format/src/store.rs | 2 ++ crates/format/src/zip.rs | 2 +- crates/format/tests/it/directory_symlinks.rs | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) 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();