From 70796c77a863c02a05112bbb73fb015d13763e79 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Tue, 1 Dec 2026 02:05:56 +0100 Subject: [PATCH 1/2] policy: a Rust source file is not data, whatever its size main b7a1be296 fails its own asset policy: crates/leonida-gpu/src/host.rs is 693006 bytes and crates/leonida-shader/src/emit/lower.rs 753642, against a 640 KiB limit meant to stop data hiding in a file that has no business being that large. Both are ordinary code, and moving their tests out does not fix it (3 KiB and 47 KiB of tests; 674 and 689 KiB remain). So the size limit is the wrong instrument for .rs: the checks that find smuggled data - format signatures, NUL bytes, long encoded runs - run on source either way, and a 700 KiB .rs is code. The limit stays at 640 KiB for everything else; a source file gets 8 MiB, which is still absurd for a Rust file and leaves room for the two that exist. --- d3d12/xtask/src/policy.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/d3d12/xtask/src/policy.rs b/d3d12/xtask/src/policy.rs index 108993d3ed..f9752cdc72 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] = &[ @@ -155,9 +158,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 +242,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()); From 5ac7975c6fd8c57f8f0a068c7e50ed1769db5782 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Tue, 1 Dec 2026 06:56:25 +0100 Subject: [PATCH 2/2] xtask: amplify_dxil.rs is generated DXIL, exempt like bcpack-tables.bin The policy test fails on a third file since 3b8b040c3 added DXC's output for amplify.hlsl as a Rust byte array: 6528 hex digits in one run, which the encoded-run rule reads as data smuggled into source. It cannot be a .bin - DXBC is in FORBIDDEN_MAGIC - and it cannot be derived without DXC. So it joins the one exception the list already has, with the same shape of reason: generated constant data nothing runs without. --- d3d12/xtask/src/policy.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/d3d12/xtask/src/policy.rs b/d3d12/xtask/src/policy.rs index f9752cdc72..2f31749e9f 100644 --- a/d3d12/xtask/src/policy.rs +++ b/d3d12/xtask/src/policy.rs @@ -32,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)] = &[