From 43ec43d79cc04c1e1eeb17610ce123729e2e179b Mon Sep 17 00:00:00 2001 From: Rob Coenen <753704+rcoenen@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:49:41 +0100 Subject: [PATCH] fix(fla): fla-dump shares one tag budget across all streams Several directory entries may point at one FAT chain, so MAX_TAGS per stream let a small file make the dump hold millions of tags. The budget is now the file's: each stream scans with what is left, and a stream cut short says so. Co-Authored-By: Claude Opus 5.5 --- crates/fla/src/lib.rs | 9 +++++++-- crates/fla/src/tests_bounds.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/fla/src/lib.rs b/crates/fla/src/lib.rs index 90caaae7..0777d631 100644 --- a/crates/fla/src/lib.rs +++ b/crates/fla/src/lib.rs @@ -57,7 +57,8 @@ pub struct StreamDump { pub head: String, /// The record tags the scanner found, in order. pub tags: Vec<(usize, String)>, - /// False when the scan stopped at [`records::MAX_TAGS`]: `tags` are the first ones only. + /// False when the scan stopped at [`records::MAX_TAGS`], which all of a file's streams + /// share: `tags` are the first ones only. pub tags_complete: bool, } @@ -65,12 +66,16 @@ pub struct StreamDump { pub fn dump(data: &[u8]) -> Result, cfb::Error> { let file = cfb::Compound::new(data)?; let mut out = Vec::new(); + // One tag budget for the whole file: several directory entries may share one chain, so a + // budget per stream would let a small file hold millions of tags. + let mut tags_left = records::MAX_TAGS; for entry in file.entries() { if entry.kind != cfb::Kind::Stream { continue; } let bytes = file.stream(&entry.path)?; - let scan = records::scan_tags(&bytes); + let scan = records::scan_tags_max(&bytes, tags_left); + tags_left = tags_left.saturating_sub(scan.tags.len()); out.push(StreamDump { path: entry.path.clone(), size: entry.size, diff --git a/crates/fla/src/tests_bounds.rs b/crates/fla/src/tests_bounds.rs index ec16df79..e05548e8 100644 --- a/crates/fla/src/tests_bounds.rs +++ b/crates/fla/src/tests_bounds.rs @@ -226,6 +226,18 @@ fn the_tag_scan_stops_at_its_budget_and_says_so() { assert!(dumped.iter().all(|s| s.tags_complete)); } +#[test] +fn the_dump_shares_one_tag_budget_across_streams() { + // Two streams of three-quarters of the budget each: the first is whole, the second keeps + // what is left and says it stopped early. + let three_quarters = records::MAX_TAGS / 4 * 3; + let flood = tags(&vec!["CPicShape"; three_quarters]); + let dumped = super::dump(&write(&[("S 1 1", flood.clone()), ("S 2 2", flood)])).unwrap(); + let get = |path: &str| dumped.iter().find(|s| s.path == path).map(|s| (s.tags.len(), s.tags_complete)).unwrap(); + assert_eq!(get("S 1 1"), (three_quarters, true)); + assert_eq!(get("S 2 2"), (records::MAX_TAGS - three_quarters, false)); +} + // The shape rebuild before its indexes, kept here as the oracle the indexed one must match // exactly: one style's fill segments gathered by scanning every edge, and each chain step's // next segment found by scanning its vertex's list from the start.