Import: one PhotoCraft input limit for the engine and media readers

The 512 MiB limit is effectcraft_project::PCRAFT_MAX_INPUT. The engine
re-exports it and the media reader's limit is defined from it, so the two
reads cannot drift apart. Both reads compute their take() limit with
saturating_add.
This commit is contained in:
dotCooCoo committed 2026-11-17 18:07:13 -08:00
1 parent 46eaed1e03
commit 8e648b3e6f
5 files changed
+11 -5

No files matched your search

+2 -2
View File
@@ -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<u64>) -> std::io::Result<Vec<u8>>
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());
}
+1 -1
View File
@@ -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"));
}
+1 -1
View File
@@ -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)
+4
View File
@@ -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]
+3 -1
View File
@@ -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::{