From 660a62a45abc028e305f349906420f39f749bd46 Mon Sep 17 00:00:00 2001 From: bmjask <11672696+bmjask@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:46:28 -0500 Subject: [PATCH 1/2] Olympus: load UTF-16 game configurations --- crates/xcl/src/launcher.rs | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/launcher.rs b/crates/xcl/src/launcher.rs index 24f10db..01d7adf 100644 --- a/crates/xcl/src/launcher.rs +++ b/crates/xcl/src/launcher.rs @@ -49,10 +49,28 @@ fn xml_attr(xml: &str, tag: &str, attr: &str) -> Option { xml_attrs(xml, tag, attr).into_iter().next() } +fn decode_game_config(raw: &[u8]) -> Option { + let (body, little_endian) = if let Some(body) = raw.strip_prefix(&[0xFF, 0xFE]) { + (body, true) + } else if let Some(body) = raw.strip_prefix(&[0xFE, 0xFF]) { + (body, false) + } else { + return String::from_utf8(raw.to_vec()).ok(); + }; + if body.len() % 2 != 0 { + return None; + } + let units: Vec = body + .chunks_exact(2) + .map(|b| if little_endian { u16::from_le_bytes([b[0], b[1]]) } else { u16::from_be_bytes([b[0], b[1]]) }) + .collect(); + String::from_utf16(&units).ok() +} + /// (executables, title) from MicrosoftGame.config if present. pub fn read_game_config(root: &Path) -> (Vec, Option) { let p = root.join("MicrosoftGame.config"); - let Ok(xml) = std::fs::read_to_string(p) else { return (Vec::new(), None) }; + let Some(xml) = std::fs::read(p).ok().and_then(|raw| decode_game_config(&raw)) else { return (Vec::new(), None) }; (xml_attrs(&xml, "Executable", "Name"), xml_attr(&xml, "Identity", "Name")) } @@ -337,6 +355,29 @@ mod tests { assert_eq!(xml_attr(xml, "ShellVisuals", "Name").as_deref(), Some("no"), "DisplayName= must not match Name="); } + #[test] + fn game_config_accepts_bom_marked_utf16_and_rejects_malformed_text() { + let dir = TempDir::new("utf16_config"); + let xml = r#""#; + for (bom, bytes) in [ + ([0xFF, 0xFE], xml.encode_utf16().flat_map(u16::to_le_bytes).collect::>()), + ([0xFE, 0xFF], xml.encode_utf16().flat_map(u16::to_be_bytes).collect::>()), + ] { + let mut raw = bom.to_vec(); + raw.extend(bytes); + let decoded = decode_game_config(&raw).unwrap(); + assert_eq!(xml_attr(&decoded, "Executable", "Name").as_deref(), Some(r"Bin\game.exe")); + assert_eq!(xml_attr(&decoded, "Identity", "Name").as_deref(), Some("Contoso.Test")); + std::fs::write(dir.0.join("MicrosoftGame.config"), &raw).unwrap(); + assert_eq!(read_game_config(&dir.0), (vec![r"Bin\game.exe".into()], Some("Contoso.Test".into()))); + } + assert!(decode_game_config(&[0xFF, 0xFE, b'<']).is_none()); + assert!(decode_game_config(&[0xFF, 0xFE, 0x00, 0xD8]).is_none()); + assert!(decode_game_config(&[0xFF, 0xFF]).is_none()); + std::fs::write(dir.0.join("MicrosoftGame.config"), [0xFF, 0xFE, b'<']).unwrap(); + assert_eq!(read_game_config(&dir.0), (Vec::new(), None)); + } + struct TempDir(PathBuf); impl TempDir { fn new(tag: &str) -> TempDir { From 55ebf2b8b03e2be4c9e84f7772524bcaae130e55 Mon Sep 17 00:00:00 2001 From: bmjask <11672696+bmjask@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:53:25 -0500 Subject: [PATCH 2/2] Olympus: validate D3D12 texture dimensions --- crates/xcl/src/gpu/desc.rs | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/crates/xcl/src/gpu/desc.rs b/crates/xcl/src/gpu/desc.rs index 6814c39..0f29069 100644 --- a/crates/xcl/src/gpu/desc.rs +++ b/crates/xcl/src/gpu/desc.rs @@ -179,6 +179,24 @@ pub fn valid_image_shape(t: &Image) -> bool { if matches!(t.ty, ImageType::D1Array | ImageType::D2Array | ImageType::D2MsaaArray | ImageType::Cube | ImageType::D3) && t.depth > u16::MAX as u32 { return false; } + let within_d3d12_limits = match t.ty { + ImageType::D1 => t.width <= D3D12_REQ_TEXTURE1D_U_DIMENSION, + ImageType::D1Array => t.width <= D3D12_REQ_TEXTURE1D_U_DIMENSION && t.depth <= D3D12_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION, + ImageType::D2 | ImageType::D2Msaa => t.width <= D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION && t.height <= D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, + ImageType::D2Array | ImageType::D2MsaaArray | ImageType::Cube => { + t.width <= D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION + && t.height <= D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION + && t.depth <= D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION + } + ImageType::D3 => { + t.width <= D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION + && t.height <= D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION + && t.depth <= D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION + } + }; + if !within_d3d12_limits { + return false; + } if matches!(t.ty, ImageType::D2Msaa | ImageType::D2MsaaArray) { return true; } @@ -480,6 +498,75 @@ mod tests { } } + #[test] + fn resource_dimensions_respect_d3d12_texture_limits() { + let mut t = image(&tsharp()).unwrap(); + t.base_level = 0; + t.last_level = 0; + t.max_mip = 0; + + t.ty = ImageType::D1; + t.width = D3D12_REQ_TEXTURE1D_U_DIMENSION; + assert!(image_d3d12(&t).is_some()); + t.width += 1; + assert!(image_d3d12(&t).is_none()); + + t.ty = ImageType::D2; + for axis in 0..2 { + t.width = 1; + t.height = 1; + if axis == 0 { + t.width = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION; + } else { + t.height = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION; + } + assert!(image_d3d12(&t).is_some(), "2D axis {axis} at the limit"); + if axis == 0 { + t.width += 1; + } else { + t.height += 1; + } + assert!(image_d3d12(&t).is_none(), "2D axis {axis} over the limit"); + } + + for ty in [ImageType::D1Array, ImageType::D2Array, ImageType::D2MsaaArray] { + t.width = 1; + t.height = 1; + t.ty = ty; + t.depth = D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; + assert!(image_d3d12(&t).is_some(), "{ty:?} at the array limit"); + t.depth += 1; + assert!(image_d3d12(&t).is_none(), "{ty:?} over the array limit"); + } + + t.ty = ImageType::Cube; + t.base_array = 0; + t.depth = 2046; // largest whole number of faces within the 2048-slice limit + assert!(image_d3d12(&t).is_some()); + t.depth = 2052; + assert!(image_d3d12(&t).is_none()); + + t.ty = ImageType::D3; + t.depth = 1; + for axis in 0..3 { + t.width = 1; + t.height = 1; + t.depth = 1; + match axis { + 0 => t.width = D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, + 1 => t.height = D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, + _ => t.depth = D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, + } + assert!(image_d3d12(&t).is_some(), "3D axis {axis} at the limit"); + match axis { + 0 => t.width += 1, + 1 => t.height += 1, + _ => t.depth += 1, + } + assert!(image_d3d12(&t).is_none(), "3D axis {axis} over the limit"); + } + } + #[test] fn decodes_ssharp() { // clamp/wrap/border, aniso 8, compare LESS, bias -1.5, mag/min linear, mip linear, lod 0..13