mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-28 17:19:31 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
55447549b3
commit
43ec43d79c
2 files changed
+19
-2
No files matched your search
@@ -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<Vec<StreamDump>, 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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user