From b1369afb40017099471223ff61327c4550669a61 Mon Sep 17 00:00:00 2001 From: Yusuf Al-Khawaldeh <114036712+yualk@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:15:56 -0500 Subject: [PATCH] fix(cli): hash only the embedded DXBC container Validate and use the declared DXBC byte extent when scanning an embedded shader. Keep the borrowed slice and offset, and leave packed inputs unchanged. Tested on Windows with the focused embedded-container regression and a synthetic CLI run. --- apps/victory/src/shader.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/victory/src/shader.rs b/apps/victory/src/shader.rs index 1c20285..431f567 100644 --- a/apps/victory/src/shader.rs +++ b/apps/victory/src/shader.rs @@ -43,15 +43,39 @@ pub(crate) fn sources(data: &[u8]) -> Vec> { out.extend(sgd5::records(data).map(Source::Packed)); } let raw = memchr::memmem::find_iter(data, b"DXBC") - .filter(|&offset| Container::parse(&data[offset..]).is_ok()) - .map(|offset| Source::Raw { - offset, - data: &data[offset..], + .filter_map(|offset| { + let tail = &data[offset..]; + // DXBC total size, validated below. Hash the container, not the + // rest of its carrier, so offline warming uses the runtime key. + let size = u32::from_le_bytes(tail.get(0x18..0x1c)?.try_into().ok()?) as usize; + let data = tail.get(..size)?; + Container::parse(data).ok()?; + Some(Source::Raw { offset, data }) }); out.extend(raw); out } +#[cfg(test)] +mod tests { + use super::sources; + + #[test] + fn embedded_containers_keep_runtime_hashes() { + // A 32-byte DXBC with no parts; the scan should not add carrier bytes. + let shader = b"DXBC\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\x20\0\0\0\0\0\0\0"; + let first = [b"MZ".as_slice(), shader, b"first suffix"].concat(); + let second = [b"PE header".as_slice(), shader, b"other suffix", b"DXBC"].concat(); + let runtime_hash = blake3::hash(shader); + for (carrier, label) in [(&first, "@0x2"), (&second, "@0x9")] { + let entries = sources(carrier); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].label(), label); + assert_eq!(blake3::hash(&entries[0].bytes().unwrap()), runtime_hash); + } + } +} + #[derive(Default)] struct Totals { containers: usize,