diff --git a/crates/sylpheed-formats/src/slb.rs b/crates/sylpheed-formats/src/slb.rs index d7f75e65..78a979f2 100644 --- a/crates/sylpheed-formats/src/slb.rs +++ b/crates/sylpheed-formats/src/slb.rs @@ -264,7 +264,10 @@ pub fn to_xma_riffs(slb: &[u8]) -> Vec> { } let mut pos = 0usize; while let Some(ri) = find(slb, b"RIFF", pos) { - // Parse this sub-wave's fmt + data (declared size is honest per sub-wave). + // Parse this sub-wave's fmt + data. The declared `data` size is an + // UPPER bound, not an exact one: 5 296 of 7 586 banks declare more than + // the entry holds and none declares exactly what it holds, so the clamp + // below is load-bearing (docs/re/structures/slb-data-offset.md). let Some(fi) = find(slb, b"fmt ", ri) else { break }; let Some(fsz) = le32(slb, fi + 4) else { break }; let Some(fmt_end) = fi.checked_add(8).and_then(|v| v.checked_add(fsz as usize)) else { @@ -298,10 +301,12 @@ pub fn to_xma_riff(slb: &[u8]) -> Option> { if let Some(ri) = find(slb, b"RIFF", 0) { // RIFF layout: a `.slb` is an XACT bank of one or more sub-waves, each // `[seek][RIFF: fmt + Dmmy pad + data][declared_size XMA bytes]`. Take the - // FIRST sub-wave, bounded by its **declared `data` size** (which is - // honest per sub-wave). Decoding to end-of-file instead would append the - // later sub-waves — for multi-take story movies those are ALTERNATE takes, - // which is what made S10–S16 play the wrong audio. + // FIRST sub-wave, bounded by its **declared `data` size** — which is an + // upper bound only (69.8 % of banks over-declare it, so the clamp + // matters), but still the right boundary to cut at. Decoding to + // end-of-file instead would append the later sub-waves — for multi-take + // story movies those are ALTERNATE takes, which is what made S10–S16 + // play the wrong audio. let fi = find(slb, b"fmt ", ri)?; let fsz = le32(slb, fi + 4)? as usize; let fmt_end = fi.checked_add(8)?.checked_add(fsz)?;