diff --git a/crates/engine/src/services.rs b/crates/engine/src/services.rs index 4bc42baf0..2a641cf41 100644 --- a/crates/engine/src/services.rs +++ b/crates/engine/src/services.rs @@ -1,7 +1,7 @@ use super::config; /// The largest PhotoCraft bundle [`Services::read_pcraft`] reads. -pub const PCRAFT_MAX_INPUT: u64 = 512 << 20; +pub use effectcraft_project::PCRAFT_MAX_INPUT; /// The error for a PhotoCraft bundle over [`PCRAFT_MAX_INPUT`]. pub fn pcraft_too_large() -> std::io::Error { @@ -130,7 +130,7 @@ fn read_regular_file(path: &str, limit: Option) -> std::io::Result> let mut bytes = Vec::new(); // A sparse file can claim far more than memory: an error, not an abort. bytes.try_reserve_exact(usize::try_from(meta.len()).unwrap_or(usize::MAX)).map_err(|e| std::io::Error::new(std::io::ErrorKind::OutOfMemory, e))?; - file.take(limit.map_or(u64::MAX, |max| max + 1)).read_to_end(&mut bytes)?; + file.take(limit.map_or(u64::MAX, |max| max.saturating_add(1))).read_to_end(&mut bytes)?; if limit.is_some_and(|max| bytes.len() as u64 > max) { return Err(pcraft_too_large()); } diff --git a/crates/media/src/lib.rs b/crates/media/src/lib.rs index a6e9e0fb5..02ade4f9b 100644 --- a/crates/media/src/lib.rs +++ b/crates/media/src/lib.rs @@ -112,7 +112,7 @@ pub(crate) fn read_regular_file_stamped(path: &std::path::Path) -> std::io::Resu // A sparse file can claim far more than memory: an error, not an abort. bytes.try_reserve_exact(usize::try_from(meta.len()).unwrap_or(usize::MAX)).map_err(|e| std::io::Error::new(std::io::ErrorKind::OutOfMemory, e))?; if pcraft { - file.take(pcraft::MAX_INPUT_BYTES + 1).read_to_end(&mut bytes)?; + file.take(pcraft::MAX_INPUT_BYTES.saturating_add(1)).read_to_end(&mut bytes)?; if bytes.len() as u64 > pcraft::MAX_INPUT_BYTES { return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "PhotoCraft bundle grew beyond the 512 MiB input limit")); } diff --git a/crates/media/src/pcraft.rs b/crates/media/src/pcraft.rs index 220fcd381..ab8b0b74f 100644 --- a/crates/media/src/pcraft.rs +++ b/crates/media/src/pcraft.rs @@ -13,7 +13,7 @@ const MAX_PIXELS: u64 = 16 << 20; // (16 B), two blur images (32 B) and output (16 B), even where lifetimes do not // overlap. Twelve Mi pixels fit within a 1 GiB working-buffer budget (84 B/pixel). const MAX_LAYER_PIXELS: u64 = 12 << 20; -pub(crate) const MAX_INPUT_BYTES: u64 = 512 << 20; +pub(crate) const MAX_INPUT_BYTES: u64 = effectcraft_project::PCRAFT_MAX_INPUT; pub(crate) fn sniff(path: &str, bytes: &[u8]) -> bool { path.to_ascii_lowercase().ends_with(".pcraft") || craft_doc::sniff(bytes) == Some(craft_doc::Kind::PhotoCraft) diff --git a/crates/project/src/footage.rs b/crates/project/src/footage.rs index 462772dc4..107e5effc 100644 --- a/crates/project/src/footage.rs +++ b/crates/project/src/footage.rs @@ -49,6 +49,10 @@ impl FieldOrder { /// by this list. pub const VIDEO_EXTENSIONS: &[&str] = &["mp4", "m4v", "mov", "mkv", "webm", "mxf", "avi"]; +/// The largest PhotoCraft bundle that is read for import, in bytes. The engine's +/// `Services::read_pcraft` and `effectcraft_media`'s file reader both use it. +pub const PCRAFT_MAX_INPUT: u64 = 512 << 20; + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub enum AlphaMode { #[default] diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index 9f5f399e0..fe8146b9b 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -40,7 +40,9 @@ mod reach; mod settings; pub use comp::{Comp, Guide, Renderer, Resolution}; -pub use footage::{AlphaMode, CineonSettings, CineonUnits, FieldOrder, Footage, FootageKind, Proxy, Solid, SourceLayer, VIDEO_EXTENSIONS, cineon_log_to_lin}; +pub use footage::{ + AlphaMode, CineonSettings, CineonUnits, FieldOrder, Footage, FootageKind, PCRAFT_MAX_INPUT, Proxy, Solid, SourceLayer, VIDEO_EXTENSIONS, cineon_log_to_lin, +}; pub use item::NO_LAYER; pub use item::{Heard, Item, ItemId, ItemKind, LayerId}; pub use layer::{