From 9ed81da8cbcfff0bf11d362f0e83fa4baa9d1300 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 17:28:04 -0500 Subject: [PATCH] formats: account for the USDC path table's real allocation (#507) The PATHS table charged 64 bytes per entry but allocates Option (about 80), letting a small declared count exceed the decoded-byte budget, and had no entry ceiling. Charge the real element size and cap the table at four million paths. --- crates/formats/src/mesh_import/usd/usdc.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/formats/src/mesh_import/usd/usdc.rs b/crates/formats/src/mesh_import/usd/usdc.rs index 221c7b4a..0a07b637 100644 --- a/crates/formats/src/mesh_import/usd/usdc.rs +++ b/crates/formats/src/mesh_import/usd/usdc.rs @@ -15,6 +15,9 @@ const MIN_VERSION: (u8, u8, u8) = (0, 4, 0); const MAX_SECTIONS: usize = 64; /// Items in one table or array. const MAX_ITEMS: usize = 1 << 28; +/// Entries in the PATHS table. The declared count is tiny in the file but each entry is a +/// materialised path, so it needs its own ceiling as well as the decoded-byte budget. +const MAX_PATHS: usize = 4_000_000; /// Spec types. const SPEC_ATTRIBUTE: i64 = 1; @@ -248,7 +251,11 @@ impl<'a> Crate<'a> { let index = s.ints(n, 4, budget)?; let elements = s.ints(n, 4, budget)?; let jumps = s.ints(n, 4, budget)?; - budget.take(total.saturating_mul(64))?; + if total > MAX_PATHS { + return Err(FormatError::TooLarge(format!("the USD path table has {total} entries (limit {MAX_PATHS})"))); + } + // Charge what the vector really allocates, not a guessed 64 bytes per entry. + budget.take(total.saturating_mul(std::mem::size_of::>()))?; self.paths = vec![None; total]; let mut work: Vec<(usize, Option)> = vec![(0, None)]; let mut steps = 0usize;