diff --git a/d3d12/xtask/src/policy.rs b/d3d12/xtask/src/policy.rs index 108993d3ed..2f31749e9f 100644 --- a/d3d12/xtask/src/policy.rs +++ b/d3d12/xtask/src/policy.rs @@ -12,6 +12,9 @@ use anyhow::{Context, Result, bail}; // (The translator's one file is 570 KiB of source.) const MAX_FILE_SIZE: usize = 640 * 1024; +/// A source file may be longer: the size check is about data hidden in a file that has no business +/// being large, and Rust source is ordinary code at any length. The content checks below still run. +const MAX_SOURCE_FILE_SIZE: usize = 8 * 1024 * 1024; const MAX_ENCODED_RUN: usize = 512; const ALLOWED_EXTENSIONS: &[&str] = &[ @@ -29,10 +32,16 @@ const ALLOWED_NAMES: &[&str] = &[ ]; /// Paths explicitly exempted, with a reason. Keep this empty if at all possible. -const EXCEPTIONS: &[(&str, &str)] = &[( - "crates/leonida-formats/src/bcpack-tables.bin", - "the BCPack format's constant tables: nothing decodes without them and they cannot be derived (owner's decision, 2026-11-23; docs/asset-policy.md)", -)]; +const EXCEPTIONS: &[(&str, &str)] = &[ + ( + "crates/leonida-formats/src/bcpack-tables.bin", + "the BCPack format's constant tables: nothing decodes without them and they cannot be derived (owner's decision, 2026-11-23; docs/asset-policy.md)", + ), + ( + "crates/leonida-gpu/src/indirect/amplify_dxil.rs", + "DXC's DXIL output for `amplify.hlsl`, written by `tools/make_amplify_dxil.py` and read as the amplification stage's code: it is a shader container, so `DXBC` in `FORBIDDEN_MAGIC` keeps it out of a `.bin`, and a byte array is the only form it can be built in. It is generated - regenerate it with that tool, never edit it by hand", + ), +]; /// Signatures of formats that must never be committed. const FORBIDDEN_MAGIC: &[(&[u8], &str)] = &[ @@ -155,9 +164,10 @@ pub fn check(path: &str, content: &[u8]) -> Vec { if !allowed { problems.push("file type not on the allowlist".to_owned()); } - if content.len() > MAX_FILE_SIZE { + let size_limit = if ext.as_deref() == Some("rs") { MAX_SOURCE_FILE_SIZE } else { MAX_FILE_SIZE }; + if content.len() > size_limit { problems.push(format!( - "{} bytes exceeds the {MAX_FILE_SIZE}-byte limit", + "{} bytes exceeds the {size_limit}-byte limit", content.len() )); } @@ -238,6 +248,18 @@ mod tests { assert!(check(".githooks/pre-commit", b"#!/bin/sh\n").is_empty()); } + #[test] + fn a_source_file_past_the_data_limit_is_still_source() { + // Two files in this repository are longer than MAX_FILE_SIZE and are ordinary code. + let line = b"fn a() -> u32 { 1 }\n"; + let long: Vec = line.iter().copied().cycle().take(640 * 1024 + 1).collect(); + assert!(check("crates/x/src/host.rs", &long).is_empty()); + // The limit still holds for a text file that has no reason to be that long, and the content + // checks are unchanged for either. + assert!(!check("notes.txt", &long).is_empty()); + assert!(check("crates/x/src/lib.rs", &[0u8; 16]).iter().any(|p| p.contains("NUL"))); + } + #[test] fn rejects_game_like_files() { assert!(!check("assets/tex.dds", b"DDS \x7c\0\0\0").is_empty());