forge
Explore
Log in

Don't you dare go Hollow

Pin an mp3 probe past a 2MB ID3v2 APIC cover art and an ID3v1 tail

Browse files at this commit

537e531ccb7c8688e9b56a964ac8cb0c35461ccaAhmet Kaan GümüşParent: f8c4e7b
  • test
    • pin an mp3 probe past a 2MB ID3v2 APIC cover art and an ID3v1 tail
Show full message
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.rsmodified+65 -0
@@ -280,3 +280,68 @@ fn opus_has_a_decoder_in_the_registry() {
280 "the refusal names the codec: {refusal}"280 "the refusal names the codec: {refusal}"
281 );281 );
282 }282 }
283+
284+/// Regression for `open: NeedMore` on a real mp3 whose ID3v2 header carries a
285+/// large APIC cover-art picture and whose tail carries an ID3v1 `TAG` block:
286+/// the probe must skip both rather than reading a bounded head short of the
287+/// first mp3 frame sync, or getting confused reading a 128-byte tail as audio.
288+/// Built out of a plain mp3 fixture wrapped in a synthetic 2 MB ID3v2 APIC
289+/// header and an ID3v1 tail, so this needs no real file on disk.
290+#[test]
291+fn cover_art_and_id3v1_tail_do_not_stop_the_probe() {
292+ let raw = std::fs::read(fixtures().join("mp3-stereo-48000.mp3")).expect("fixture mp3");
293+ // A 2 MB ID3v2.3 tag: one oversized `APIC` frame of filler bytes. The
294+ // probe only needs to skip past the tag's declared size, so the frame
295+ // body's content does not matter.
296+ let apic_body_len = 2_000_000usize;
297+ let mut id3 = Vec::new();
298+ id3.extend_from_slice(b"ID3");
299+ id3.extend_from_slice(&[3, 0, 0]); // version 2.3.0, no flags
300+ let frame_len = apic_body_len as u32;
301+ let tag_size = 10 + apic_body_len as u32; // one frame header (10) + body
302+ id3.extend_from_slice(&syncsafe(tag_size));
303+ id3.extend_from_slice(b"APIC");
304+ id3.extend_from_slice(&frame_len.to_be_bytes());
305+ id3.extend_from_slice(&[0, 0]); // frame flags
306+ id3.extend(std::iter::repeat_n(0u8, apic_body_len));
307+
308+ let mut id3v1 = vec![0u8; 128];
309+ id3v1[0..3].copy_from_slice(b"TAG");
310+
311+ let mut bytes = id3;
312+ bytes.extend_from_slice(&raw);
313+ bytes.extend_from_slice(&id3v1);
314+
315+ let path = std::env::temp_dir().join("edith-cover-art-id3v1-tail.mp3");
316+ std::fs::write(&path, &bytes).expect("write synthetic mp3");
317+
318+ let mut track = SymTrack::open(&path).expect("open past the ID3v2 APIC and ID3v1 tail");
319+ assert_eq!(track.codec, "mp3");
320+ let mut decoder = track.decoder();
321+ let mut out = Vec::new();
322+ let mut decoded_packets = 0;
323+ while let Some(packet) = track.reader.next_packet().expect("demux") {
324+ if packet.track_id != track.track_id {
325+ continue;
326+ }
327+ decoder
328+ .decode(&packet)
329+ .expect("decode")
330+ .copy_to_vec_interleaved::<f32>(&mut out);
331+ decoded_packets += 1;
332+ }
333+ assert!(decoded_packets > 0, "no audio packets decoded");
334+ assert!(!out.is_empty(), "no samples decoded");
335+ let _ = std::fs::remove_file(&path);
336+}
337+
338+/// ID3v2's syncsafe integer: 4 bytes, 7 significant bits each (top bit clear),
339+/// big-endian.
340+fn syncsafe(mut n: u32) -> [u8; 4] {
341+ let mut out = [0u8; 4];
342+ for b in out.iter_mut().rev() {
343+ *b = (n & 0x7f) as u8;
344+ n >>= 7;
345+ }
346+ out
347+}