diff --git a/crates/iz-core/src/store/sniff.rs b/crates/iz-core/src/store/sniff.rs index d83a465..52ec353 100644 --- a/crates/iz-core/src/store/sniff.rs +++ b/crates/iz-core/src/store/sniff.rs @@ -121,9 +121,24 @@ fn zip_mime(bytes: &[u8]) -> &'static str { /// Whether `haystack` holds `needle` anywhere in it. Used on zip bytes, where /// the entry names sit in the clear even when the entries themselves do not. fn contains(haystack: &[u8], needle: &[u8]) -> bool { - haystack - .windows(needle.len()) - .any(|window| window == needle) + // Skip to the needle's first byte before comparing the rest — a + // window-per-position compare over a half-gigabyte upload stalls the + // runtime; the byte scan vectorizes, the full compare runs on hits only. + let Some((&first, _)) = needle.split_first() else { + return true; + }; + let mut offset = 0usize; + while let Some(at) = haystack[offset..].iter().position(|&b| b == first) { + let start = offset + at; + if haystack.len() - start < needle.len() { + return false; + } + if &haystack[start..start + needle.len()] == needle { + return true; + } + offset = start + 1; + } + false } /// The office mime declared by the zip entry names in `bytes` — the central diff --git a/crates/iz-web/src/files.rs b/crates/iz-web/src/files.rs index 7cb2ffb..edd917a 100644 --- a/crates/iz-web/src/files.rs +++ b/crates/iz-web/src/files.rs @@ -407,7 +407,23 @@ async fn upload( let mut added: Result<(), Refusal> = Ok(()); for (file_name, bytes) in files { let label = label_of(&file_name); - let mime_type = sniff(&bytes); + // Sniffing's slow paths scan the whole payload; past a size where a + // worker-thread second is every other request waiting, the scan runs + // on the blocking pool (same door detail.rs parses sheets through). + let (bytes, mime_type) = if bytes.len() <= 8 * 1024 * 1024 { + let mime_type = sniff(&bytes); + (bytes, mime_type) + } else { + match tokio::task::spawn_blocking(move || { + let mime_type = sniff(&bytes); + (bytes, mime_type) + }) + .await + { + Ok(pair) => pair, + Err(_) => return Ok(back_to(&task_id, Some(Refusal::Unavailable))), + } + }; let this = match backend { StorageBackend::Local => store