From 537e531ccb7c8688e9b56a964ac8cb0c35461cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 17:20:02 +0300 Subject: [PATCH] test(symphonia-shim): pin an mp3 probe past a 2MB ID3v2 APIC cover art and an ID3v1 tail Regression for edith_replica's "open: NeedMore" on a real cover-art-tagged mp3, root-caused to that repo's test harness (not this shim): the shim's probe already skips a large ID3v2 tag and an ID3v1 TAG tail correctly (this test is new coverage, not a fix), but nothing here pinned it against a synthetic file carrying both, sized like the real one that triggered the investigation (21.7 KB real tag; this test uses 2 MB to stress the same path harder). --- shims/symphonia/tests/edith_surface.rs | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/shims/symphonia/tests/edith_surface.rs b/shims/symphonia/tests/edith_surface.rs index 5aadbbef..f1030b9b 100644 --- a/shims/symphonia/tests/edith_surface.rs +++ b/shims/symphonia/tests/edith_surface.rs @@ -280,3 +280,68 @@ fn opus_has_a_decoder_in_the_registry() { "the refusal names the codec: {refusal}" ); } + +/// Regression for `open: NeedMore` on a real mp3 whose ID3v2 header carries a +/// large APIC cover-art picture and whose tail carries an ID3v1 `TAG` block: +/// the probe must skip both rather than reading a bounded head short of the +/// first mp3 frame sync, or getting confused reading a 128-byte tail as audio. +/// Built out of a plain mp3 fixture wrapped in a synthetic 2 MB ID3v2 APIC +/// header and an ID3v1 tail, so this needs no real file on disk. +#[test] +fn cover_art_and_id3v1_tail_do_not_stop_the_probe() { + let raw = std::fs::read(fixtures().join("mp3-stereo-48000.mp3")).expect("fixture mp3"); + // A 2 MB ID3v2.3 tag: one oversized `APIC` frame of filler bytes. The + // probe only needs to skip past the tag's declared size, so the frame + // body's content does not matter. + let apic_body_len = 2_000_000usize; + let mut id3 = Vec::new(); + id3.extend_from_slice(b"ID3"); + id3.extend_from_slice(&[3, 0, 0]); // version 2.3.0, no flags + let frame_len = apic_body_len as u32; + let tag_size = 10 + apic_body_len as u32; // one frame header (10) + body + id3.extend_from_slice(&syncsafe(tag_size)); + id3.extend_from_slice(b"APIC"); + id3.extend_from_slice(&frame_len.to_be_bytes()); + id3.extend_from_slice(&[0, 0]); // frame flags + id3.extend(std::iter::repeat_n(0u8, apic_body_len)); + + let mut id3v1 = vec![0u8; 128]; + id3v1[0..3].copy_from_slice(b"TAG"); + + let mut bytes = id3; + bytes.extend_from_slice(&raw); + bytes.extend_from_slice(&id3v1); + + let path = std::env::temp_dir().join("edith-cover-art-id3v1-tail.mp3"); + std::fs::write(&path, &bytes).expect("write synthetic mp3"); + + let mut track = SymTrack::open(&path).expect("open past the ID3v2 APIC and ID3v1 tail"); + assert_eq!(track.codec, "mp3"); + let mut decoder = track.decoder(); + let mut out = Vec::new(); + let mut decoded_packets = 0; + while let Some(packet) = track.reader.next_packet().expect("demux") { + if packet.track_id != track.track_id { + continue; + } + decoder + .decode(&packet) + .expect("decode") + .copy_to_vec_interleaved::(&mut out); + decoded_packets += 1; + } + assert!(decoded_packets > 0, "no audio packets decoded"); + assert!(!out.is_empty(), "no samples decoded"); + let _ = std::fs::remove_file(&path); +} + +/// ID3v2's syncsafe integer: 4 bytes, 7 significant bits each (top bit clear), +/// big-endian. +fn syncsafe(mut n: u32) -> [u8; 4] { + let mut out = [0u8; 4]; + for b in out.iter_mut().rev() { + *b = (n & 0x7f) as u8; + n >>= 7; + } + out +}