diff --git a/Cargo.lock b/Cargo.lock index 9fcde4604..d074b770d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,14 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "bcpack-rs" +version = "0.2.0" +source = "git+https://github.com/Ahmet-Dedeler/bcpack-rs?rev=c51ec521cbe6869136f29f5d157342374ef5cf33#c51ec521cbe6869136f29f5d157342374ef5cf33" +dependencies = [ + "serde_json", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -547,6 +555,7 @@ checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" name = "xcl" version = "0.1.0" dependencies = [ + "bcpack-rs", "miniz_oxide", "retour", "serde", diff --git a/README.md b/README.md index 405559f8e..fc8579341 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,11 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder - **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Choose a game…* (pick its exe or `MicrosoftGame.config`) or *Run again* (the last one). On an error the window stays open until Enter. +- The window title shows active shader compilation and pipeline builds; pipelines deferred until + first use are not counted as active. +- Experimental BCPack BC1 decoding can be enabled with `XCL_DSTORAGE_BCPACK_BC1=1`. Its fitted + tables can produce inaccurate textures; streams using unknown lane 1 symbols are rejected. + BC2–BC7 remain unsupported, and this does not guarantee a game will render or run. - XCL works on **unpacked** game files you own; it contains nothing for decrypting or circumventing DRM. - **The game folder is never modified** – writes go to the overlay. diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md index 4afc9f29d..0f0536c1a 100644 --- a/THIRD_PARTY.md +++ b/THIRD_PARTY.md @@ -13,6 +13,8 @@ carry a note in their header about its origin and the date of changes (GPL-2.0 | [LLVM](https://github.com/llvm/llvm-project) | Apache-2.0 WITH LLVM-exception | `tests/data/llvm-amdgpu/*` (test data, not part of the program); GFX10 buffer format values (`UfmtSymbolicGFX10`) in `gpu/recomp/emit.rs` | test vectors; hardware facts | | [WinDurango](https://github.com/WinDurango/WinDurango) | LGPL-3.0 | no code; d3d12_x.dll export numbers (facts) in `crates/xcl/data/stubdb.toml` | reference only | | [libHttpClient](https://github.com/microsoft/libHttpClient) | MIT | no code; XTaskQueue/XAsync contract | specification | +| [bcpack-rs](https://github.com/Ahmet-Dedeler/bcpack-rs) and [silicon-rans](https://github.com/microsoft/silicon-rans) | MIT | experimental BCPack BC1 decoder and entropy tables | pinned Rust dependency; notices below | +| [bcpack-decoder](https://github.com/Tim0219800/bcpack-decoder) | MIT | no code; BC1 lane 1 semantics | format reference | | Windows XGameRuntime (`System32\xgameruntime.dll`) | system | class GUIDs and slot order of the GDK thunk protocol in `hle/xgameruntime/api.rs` (facts, determined by analysis); APIs XCL does not implement are forwarded to it at runtime | interoperability; not distributed | | docs.xbox.com | documentation | signatures, enums, structs written independently | reference | | Rust crates (`Cargo.lock`) | MIT / BSD-2 / Zlib / Unlicense (or with an MIT alternative) | build dependencies | statically linked | @@ -22,3 +24,28 @@ carry a note in their header about its origin and the date of changes (GPL-2.0 When adding dependencies: compatible with GPL-2.0-only are MIT, BSD, Zlib, ISC, Unlicense, LGPL-2.1(+), GPL-2.0(+), MPL-2.0 (via its Secondary License clause). Incompatible: Apache-2.0 without an alternative, GPL-3.0, LGPL-3.0, AGPL. + +## BCPack notices + +bcpack-rs: Copyright (c) 2026 Ahmet Dedeler. Its rANS decoder and tables derive from +silicon-rans: Copyright (c) Microsoft Corporation. Both are used under the MIT license: + +``` +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/crates/xcl/Cargo.toml b/crates/xcl/Cargo.toml index f3f6d604d..8ecef46bb 100644 --- a/crates/xcl/Cargo.toml +++ b/crates/xcl/Cargo.toml @@ -14,6 +14,7 @@ name = "xcl" path = "src/main.rs" [dependencies] +bcpack-rs = { git = "https://github.com/Ahmet-Dedeler/bcpack-rs", rev = "c51ec521cbe6869136f29f5d157342374ef5cf33", default-features = false } miniz_oxide = "0.9" retour = "0.3" serde = { version = "1", features = ["derive"] } diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs index 78c835901..ddaa9408d 100644 --- a/crates/xcl/src/hle/d3d12x/present.rs +++ b/crates/xcl/src/hle/d3d12x/present.rs @@ -347,15 +347,15 @@ const COMPILE_TIMER: usize = 0x5C0; /// While XCL compiles shaders (DXC, programs the disk cache did not have – the title draws /// nothing with those pipelines meanwhile: after an XCL update the screen stays black while /// thousands recompile), the window's title says so: -/// "XCL – | compiling shaders: N running, M done[, Q pipelines queued][, F failed]". +/// "XCL – | compiling shaders: N running, M done[, Q pipelines active][, F failed]". /// It stays 2 s after the last compile (compiles in the title's own calls come one by one), /// then the plain title comes back. unsafe fn show_compiling(hwnd: HWND) { static SHOWN: Mutex> = Mutex::new(None); static LAST_ACTIVE: Mutex> = Mutex::new(None); - let (_, failed, queued) = super::pso_async::counts(); + let (failed, pipelines) = super::pso_async::activity(); let (running, done) = crate::gpu::recomp::dxc::compile_counts(); - let active = running > 0 || queued > 0; + let active = running > 0 || pipelines > 0; let recent = { let mut last = LAST_ACTIVE.lock().unwrap(); if active { @@ -365,7 +365,7 @@ unsafe fn show_compiling(hwnd: HWND) { }; let title = window_name(); let text = if recent { - let queued = if queued > 0 { format!(", {queued} pipelines queued") } else { String::new() }; + let queued = if pipelines > 0 { format!(", {pipelines} pipelines active") } else { String::new() }; let failed = if failed > 0 { format!(", {failed} failed") } else { String::new() }; format!("XCL – {title} | compiling shaders: {running} running, {done} done{queued}{failed}") } else { diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index e4769de82..1c050eed9 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -25,6 +25,12 @@ struct Pending { orphan: std::sync::atomic::AtomicBool, } +impl Pending { + fn is_active(&self) -> bool { + self.sent.load(Ordering::Acquire) && !*self.done.lock().unwrap() + } +} + /// stand-in handed to the title → its real pipeline static PENDING: Mutex>>> = Mutex::new(None); @@ -153,6 +159,7 @@ pub fn resolve(pso: usize) -> usize { /// it yet (a queue of a title's hundreds of pipelines must not hold up the one it binds now). pub fn resolve_wait(pso: usize) -> usize { let Some(p) = entry(pso) else { return pso }; + p.sent.store(true, Ordering::Release); let job = p.job.lock().unwrap().take(); if let Some(job) = job { complete(&p, job()); @@ -201,3 +208,31 @@ pub fn counts() -> (usize, usize, usize) { let pending = PENDING.lock().unwrap().as_ref().map_or(0, |m| m.values().filter(|p| !*p.done.lock().unwrap()).count()); (BUILT.load(Ordering::Relaxed), FAILED.load(Ordering::Relaxed), pending) } + +/// Failed builds and builds actually started or sent to workers, excluding dormant lazy pipelines. +pub fn activity() -> (usize, usize) { + let active = PENDING.lock().unwrap().as_ref().map_or(0, |m| { + m.values().filter(|p| p.is_active()).count() + }); + (FAILED.load(Ordering::Relaxed), active) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lazy_pipeline_is_active_only_after_its_build_starts() { + let standin = usize::MAX - 1000; + submit_lazy(standin, true, Box::new(move || { + let p = entry(standin).unwrap(); + assert!(p.is_active()); + 0 + })); + let p = entry(standin).unwrap(); + assert!(!p.is_active()); + assert_eq!(resolve_wait(standin), standin); + assert!(!p.is_active()); + assert_eq!(released(standin), 0); + } +} diff --git a/crates/xcl/src/hle/dstorage.rs b/crates/xcl/src/hle/dstorage.rs index 557266edc..730a94774 100644 --- a/crates/xcl/src/hle/dstorage.rs +++ b/crates/xcl/src/hle/dstorage.rs @@ -26,7 +26,7 @@ //! Each queue has a worker thread: submitted requests run in order (file reads through the //! VFS like the title's own, memory copies, zlib), a status entry gets the first failure of //! the requests since the previous one, a signal sets the fence from the CPU. Methods not -//! listed are logged and answer E_NOTIMPL; BCPack and other console formats are refused. +//! listed are logged and answer E_NOTIMPL; BCPack BC1 is experimental and opt-in. #![allow(non_snake_case)] @@ -211,7 +211,7 @@ fn log_bcpack_refusal(r: &Request, k: u64) { warn_once( &key, format_args!( - "mode {bc} unsupported (src={}, intermediate={}, dst={}, swizzle={}); the request fails with E_DECOMPRESSION", + "mode {bc} unsupported or disabled (src={}, intermediate={}, dst={}, swizzle={}); the request fails with E_DECOMPRESSION", r.source_size, r.intermediate_size, r.destination_size, @@ -642,7 +642,12 @@ impl Request { } /// What a queue of `source_memory` refuses at enqueue. + #[cfg(test)] fn check(&self, source_memory: bool) -> Result<(), HRESULT> { + self.check_with_bc1(source_memory, false) + } + + fn check_with_bc1(&self, source_memory: bool, bc1: bool) -> Result<(), HRESULT> { if self.memory_source() != source_memory || (self.source_physical_pages() && !self.memory_source()) { return Err(E_SOURCE_TYPE); } @@ -674,22 +679,28 @@ impl Request { return Err(E_DESTINATION_SIZE); } } - // Two-stage zlib -> BCPack: validate intermediate bounds when supplied, then refuse BCPack - // (counted and logged at enqueue, `BcpackRefusals`). + // Two-stage zlib -> BCPack. (true, _) => { if self.intermediate_size != 0 && (self.intermediate_size <= self.source_size || self.destination_size <= self.intermediate_size) { return Err(E_DESTINATION_SIZE); } - return Err(E_DECOMPRESSION); + if self.bcpack() != 1 || !bc1 { + return Err(E_DECOMPRESSION); + } } - // Single-stage BCPack: `intermediate_size` must be 0, then refuse BCPack. + // Single-stage BCPack: `intermediate_size` must be 0. (false, _) => { if self.intermediate_size != 0 { return Err(E_DESTINATION_SIZE); } - return Err(E_DECOMPRESSION); + if self.bcpack() != 1 || !bc1 { + return Err(E_DECOMPRESSION); + } } } + if self.bcpack() == 1 && (self.destination_size == 0 || self.destination_size % 8 != 0) { + return Err(E_DESTINATION_SIZE); + } Ok(()) } } @@ -805,17 +816,17 @@ unsafe fn execute(r: &Request, file: Option<&FileInner>, dest_pages: Option<&[us b }; - if r.swizzle() != 0 || r.bcpack() != 0 { + if r.swizzle() != 0 || r.bcpack() > 1 { return Err(E_DECOMPRESSION); } let payload: Vec = if r.zlib() { let stage1_len = if r.intermediate_size != 0 { r.intermediate_size as usize } else { n }; let mut d = miniz_oxide::inflate::decompress_to_vec_zlib_with_limit(&src, stage1_len).map_err(|_| E_ZLIB_DATA)?; - if d.len() != stage1_len { + if (r.intermediate_size != 0 || r.bcpack() == 0) && d.len() != stage1_len { return Err(E_ZLIB_DATA); } - if d.len() < n { + if r.bcpack() == 0 && d.len() < n { d.resize(n, 0); } d @@ -823,6 +834,8 @@ unsafe fn execute(r: &Request, file: Option<&FileInner>, dest_pages: Option<&[us src }; + let payload = if r.bcpack() == 1 { decode_bc1(&payload, n)? } else { payload }; + if r.dest_physical_pages() { let pages = dest_pages.ok_or(E_ACCESS_VIOLATION)?; if !crate::hle::kernelx::write_physical_pages(pages, r.destination_page_offset as usize, &payload[..n]) { @@ -834,6 +847,28 @@ unsafe fn execute(r: &Request, file: Option<&FileInner>, dest_pages: Option<&[us Ok(()) } +fn decode_bc1(src: &[u8], n: usize) -> Result, HRESULT> { + if n == 0 || n % 8 != 0 { + return Err(E_DESTINATION_SIZE); + } + static TABLES: OnceLock<(bcpack::bc1::Window, bcpack::bc1::QuadTable)> = OnceLock::new(); + let (window, quads) = TABLES.get_or_init(|| (bcpack::bc1::Window::default_table(), bcpack::bc1::QuadTable::default_table())); + let lanes = bcpack::bc1::decode_symbols(src, n / 8).map_err(|e| { + warn_once("BCPack BC1 decode", format_args!("{e}")); + E_DECOMPRESSION + })?; + if lanes.lane(1).iter().any(|&symbol| symbol != 0) { + warn_once("BCPack BC1 lane 1", format_args!("nonzero symbols have unknown semantics")); + return Err(E_DECOMPRESSION); + } + let decoded = bcpack::bc1::assemble(&lanes, window, quads); + if decoded.unfitted_blocks != 0 { + warn_once("BCPack BC1 window", format_args!("{} blocks use unfitted endpoint entries", decoded.unfitted_blocks)); + return Err(E_DECOMPRESSION); + } + Ok(decoded.blocks) +} + // --------------------------------------------------------------------------------------- // queues // --------------------------------------------------------------------------------------- @@ -915,6 +950,8 @@ struct QueueInner { errors: Mutex<(u32, Option)>, /// `XCL_DSTORAGE_BCPACK_FILL` when the queue was made bcpack_fill: AtomicBool, + /// Experimental BC1 decoding, configured when the queue was made. + bcpack_bc1: AtomicBool, } impl QueueInner { @@ -1135,6 +1172,7 @@ unsafe extern "system" fn factory_create_queue(_p: *mut c_void, desc: *const u8, error_event: ev as usize, errors: Mutex::new((0, None)), bcpack_fill: AtomicBool::new(bcpack_fill_from_env()), + bcpack_bc1: AtomicBool::new(std::env::var("XCL_DSTORAGE_BCPACK_BC1").is_ok_and(|v| v == "1")), }); let o = new_object(queue_vtbl(), inner); let hr = queue_qi(o, riid, out); @@ -1176,7 +1214,8 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8) return; } let r = Request::parse(&*(req as *const [u8; REQUEST_BYTES])); - if let Err(hr) = r.check(q.source_memory) { + let bc1 = q.bcpack_bc1.load(Ordering::Relaxed); + if let Err(hr) = r.check_with_bc1(q.source_memory, bc1) { warn_once("EnqueueRequest", format_args!("refused ({hr:#x}): {r:x?}")); let mut fill = None; if hr == E_DECOMPRESSION && r.bcpack() != 0 { @@ -1191,6 +1230,9 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8) } return q.enqueue(Entry::Refused { hr, req: r, file: None, fill }); } + if r.bcpack() == 1 { + warn_once("BCPack BC1 experimental", format_args!("decoder enabled; fitted tables may produce inaccurate textures")); + } let file = if r.memory_source() { None } else { @@ -2138,6 +2180,126 @@ mod tests { } } + #[test] + fn experimental_bc1_requests_decode_or_report_errors() { + use bcpack::bc1::BC1_ALPHABET_BITS; + use bcpack::encode::{encode_lanes, header_model, Fragment}; + + let blocks = 4096; + let lanes: Vec<_> = (0..12).map(|i| { + let symbol = if (2..8).contains(&i) || i >= 8 { 2 } else { 0 }; + let (q, z) = (0..4).flat_map(|z| (0..16).map(move |q| (q, z))).max_by_key(|&(q, z)| { + bcpack::rans::model(header_model(BC1_ALPHABET_BITS[i], z).unwrap(), q).forward(symbol).0 + }).unwrap(); + vec![Fragment { symbols: vec![symbol; blocks], q, z }] + }).collect(); + let packed = encode_lanes(&BC1_ALPHABET_BITS, &lanes).unwrap(); + let compressed = miniz_oxide::deflate::compress_to_vec_zlib(&packed, 6); + assert!(compressed.len() < packed.len() && packed.len() < blocks * 8, "zlib {}, BCPack {}, BC1 {}", compressed.len(), packed.len(), blocks * 8); + + unsafe { + let mut f = std::ptr::null_mut(); + assert_eq!(DStorageGetFactory(&IID_FACTORY, &mut f), S_OK); + let vt = *(f as *const *const usize); + let create_queue: unsafe extern "system" fn(*mut c_void, *const u8, *const GUID, *mut *mut c_void) -> HRESULT = std::mem::transmute(*vt.add(3)); + let create_status: unsafe extern "system" fn(*mut c_void, u32, *const u8, *const GUID, *mut *mut c_void) -> HRESULT = std::mem::transmute(*vt.add(5)); + let mut desc = [0u8; 0x18]; + desc[0..4].copy_from_slice(&1u32.to_le_bytes()); + desc[8..10].copy_from_slice(&8u16.to_le_bytes()); + desc[10] = 2; + let mut q = std::ptr::null_mut(); + assert_eq!(create_queue(f, desc.as_ptr(), &IID_QUEUE, &mut q), S_OK); + queue(q).bcpack_bc1.store(false, Ordering::Relaxed); + let mut s = std::ptr::null_mut(); + assert_eq!(create_status(f, 8, std::ptr::null(), &IID_STATUS_ARRAY, &mut s), S_OK); + let qv = *(q as *const *const usize); + let enqueue: unsafe extern "system" fn(*mut c_void, *const u8) = std::mem::transmute(*qv.add(3)); + let status: unsafe extern "system" fn(*mut c_void, *mut c_void, u32) = std::mem::transmute(*qv.add(4)); + let submit: unsafe extern "system" fn(*mut c_void) = std::mem::transmute(*qv.add(6)); + let sv = *(s as *const *const usize); + let complete: unsafe extern "system" fn(*mut c_void, u32) -> bool = std::mem::transmute(*sv.add(3)); + let hresult: unsafe extern "system" fn(*mut c_void, u32) -> HRESULT = std::mem::transmute(*sv.add(4)); + let run = |dst: &mut [u8], src: &[u8], options: u64, intermediate: u32, index: u32| { + let r = request_ex(SOURCE_MEMORY_BIT | options, dst.as_mut_ptr() as u64, 0, dst.len() as u32, src.as_ptr() as u64, 0, src.len() as u32, intermediate, 0); + enqueue(q, r.as_ptr()); + status(q, s, index); + submit(q); + let t = std::time::Instant::now(); + while !complete(s, index) && t.elapsed().as_secs() < 5 { + std::thread::yield_now(); + } + hresult(s, index) + }; + let bc1 = 1 << BCPACK_SHIFT; + let mut dst = vec![0xCD; blocks * 8]; + assert_eq!(run(&mut dst, &packed, bc1, 0, 0), E_DECOMPRESSION); + assert!(dst.iter().all(|&b| b == 0xCD)); + queue(q).bcpack_bc1.store(true, Ordering::Relaxed); + assert_eq!(run(&mut dst, &packed, bc1, 0, 1), S_OK); + assert!(dst.chunks_exact(8).all(|b| b == [0x21, 0x08, 0x21, 0x08, 0, 0, 0, 0])); + dst.fill(0xCD); + assert_eq!(run(&mut dst, &packed[..packed.len() - 1], bc1, 0, 2), E_DECOMPRESSION); + assert!(dst.iter().all(|&b| b == 0xCD)); + assert_eq!(run(&mut dst, &compressed, bc1 | ZLIB_BIT, packed.len() as u32, 3), S_OK); + assert!(dst.chunks_exact(8).all(|b| b == [0x21, 0x08, 0x21, 0x08, 0, 0, 0, 0])); + dst.fill(0xCD); + assert_eq!(run(&mut dst, &packed, 7 << BCPACK_SHIFT, 0, 4), E_DECOMPRESSION); + assert!(dst.iter().all(|&b| b == 0xCD)); + assert_eq!(run(&mut dst, &compressed, bc1 | ZLIB_BIT, 0, 5), S_OK); + assert!(dst.chunks_exact(8).all(|b| b == [0x21, 0x08, 0x21, 0x08, 0, 0, 0, 0])); + dst.fill(0xCD); + assert_eq!(run(&mut dst, &[0xFF; 16], bc1 | ZLIB_BIT, 0, 6), E_ZLIB_DATA); + assert!(dst.iter().all(|&b| b == 0xCD)); + if crate::gpu::uma::get().is_some() { + let mut count = 1usize; + let mut pages = [0usize; 1]; + assert_eq!(crate::hle::kernelx::AllocateTitlePhysicalPages(std::ptr::null_mut(), 0, &mut count, pages.as_mut_ptr()), 1); + let r = request_ex(SOURCE_MEMORY_BIT | DEST_PHYS_PAGES_BIT | bc1, pages.as_ptr() as u64, 64, dst.len() as u32, packed.as_ptr() as u64, 0, packed.len() as u32, 0, 0); + enqueue(q, r.as_ptr()); + status(q, s, 7); + submit(q); + let t = std::time::Instant::now(); + while !complete(s, 7) && t.elapsed().as_secs() < 5 { + std::thread::yield_now(); + } + assert_eq!(hresult(s, 7), S_OK); + assert!(crate::hle::kernelx::read_physical_pages(&pages, 64, &mut dst)); + assert!(dst.chunks_exact(8).all(|b| b == [0x21, 0x08, 0x21, 0x08, 0, 0, 0, 0])); + assert_eq!(crate::hle::kernelx::FreeTitlePhysicalPages(std::ptr::null_mut(), count, pages.as_mut_ptr()), 1); + } + queue_close(q); + queue_release(q); + status_release(s); + } + } + + #[test] + fn bc1_rejects_unfitted_windows_and_invalid_sizes() { + use bcpack::bc1::BC1_ALPHABET_BITS; + use bcpack::encode::{encode_lanes, Fragment}; + let lanes: Vec<_> = (0..12).map(|i| { + let symbol = if i == 0 { 7 } else { 0 }; + vec![Fragment { symbols: vec![symbol], q: 0, z: 0 }] + }).collect(); + let packed = encode_lanes(&BC1_ALPHABET_BITS, &lanes).unwrap(); + assert_eq!(decode_bc1(&packed, 8), Err(E_DECOMPRESSION)); + assert_eq!(decode_bc1(&packed, 7), Err(E_DESTINATION_SIZE)); + assert_eq!(decode_bc1(&packed, 0), Err(E_DESTINATION_SIZE)); + let r = Request::parse(&request(SOURCE_MEMORY_BIT | 1 << BCPACK_SHIFT, 0x1000, 7, 0x2000, 0, packed.len() as u32)); + assert_eq!(r.check_with_bc1(true, true), Err(E_DESTINATION_SIZE)); + } + + #[test] + fn bc1_rejects_unknown_lane_one_symbols() { + use bcpack::bc1::BC1_ALPHABET_BITS; + use bcpack::encode::{encode_lanes, Fragment}; + let lanes: Vec<_> = (0..12).map(|i| { + vec![Fragment { symbols: vec![if i == 1 { 1 } else { 0 }], q: 0, z: 0 }] + }).collect(); + let packed = encode_lanes(&BC1_ALPHABET_BITS, &lanes).unwrap(); + assert_eq!(decode_bc1(&packed, 8), Err(E_DECOMPRESSION)); + } + #[test] fn a_refused_bcpack_request_is_filled_only_under_the_switch() { unsafe {