From ac4a6b79a71167cbc23d2e244ca643512b8fd6eb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 18:34:21 +0000 Subject: [PATCH] Expose FBX package detection --- crates/mesh/src/fbx/package.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/mesh/src/fbx/package.rs b/crates/mesh/src/fbx/package.rs index 4f49f5ec5..6605194fc 100644 --- a/crates/mesh/src/fbx/package.rs +++ b/crates/mesh/src/fbx/package.rs @@ -4,6 +4,11 @@ use crate::{Error, Limits, Result, malformed, too_large}; const ZIP_MAGIC: &[u8] = b"PK\x03\x04"; +/// Whether bytes begin with a ZIP local-file header. +pub fn is_package(bytes: &[u8]) -> bool { + bytes.starts_with(ZIP_MAGIC) +} + /// Limits for an FBX package and each referenced texture. #[derive(Clone, Copy, Debug)] pub struct PackageLimits { @@ -38,7 +43,7 @@ impl<'a> Package<'a> { .read(&self.name, self.limits.max_model_bytes) .map_err(|e| malformed(KIND, format!("package: {e}")))? .ok_or_else(|| malformed(KIND, "package FBX is missing"))?; - if bytes.starts_with(ZIP_MAGIC) { + if is_package(bytes) { return Err(malformed(KIND, "the package holds another package")); } Ok(bytes) @@ -78,7 +83,7 @@ pub fn write( package_limits: PackageLimits, found: &mut dyn FnMut(&str) -> Option>, ) -> Result<(Option>, Vec)> { - if bytes.starts_with(ZIP_MAGIC) { + if is_package(bytes) { return Ok((None, Vec::new())); } let mut files: Vec<(String, Vec)> = Vec::new();