From b4ff43f4ff05e84610065978c1e66af1d07f839b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 09:34:43 +0300 Subject: [PATCH] B6: ec-ogg identify rejects Vorbis/FLAC rate 0, drop silent 48 kHz time base fallback Rate 0 in a Vorbis identification or FLAC STREAMINFO header is invalid; the old code kept the stream and silently timed it at 48 kHz. Now identify returns None (stream not claimed), and time_base uses the stated rate directly since Mapping can only be built from a non-zero rate. Regression: identify on a Vorbis header with rate 0 returns None. Golden: only affects streams with rate 0 (none in goldens). --- crates/ec-ogg/src/mapping.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/ec-ogg/src/mapping.rs b/crates/ec-ogg/src/mapping.rs index ce4e74ea..1935ae66 100644 --- a/crates/ec-ogg/src/mapping.rs +++ b/crates/ec-ogg/src/mapping.rs @@ -48,8 +48,9 @@ impl Mapping { /// a private mapping — all valid Ogg, none of them ours). pub fn identify(bos: &[u8]) -> Option { if bos.len() >= 16 && bos[0] == 1 && &bos[1..7] == b"vorbis" { - return Some(Mapping::Vorbis { - rate: u32::from_le_bytes(bos[12..16].try_into().ok()?), + let rate = u32::from_le_bytes(bos[12..16].try_into().ok()?); + return (rate != 0).then_some(Mapping::Vorbis { + rate, channels: bos[11], }); } @@ -67,7 +68,7 @@ impl Mapping { let rate = (u32::from(si[10]) << 12) | (u32::from(si[11]) << 4) | u32::from(si[12] >> 4); let declared = usize::from(u16::from_be_bytes([bos[7], bos[8]])); - return Some(Mapping::Flac { + return (rate != 0).then_some(Mapping::Flac { rate, channels: ((si[12] >> 1) & 0x07) + 1, // A zero here means "not stated"; the comment header still @@ -92,9 +93,7 @@ impl Mapping { match self { // Opus granules are always 48 kHz, whatever the encoder was fed. Mapping::Opus { .. } => TimeBase::from_rate(48_000), - Mapping::Vorbis { rate, .. } | Mapping::Flac { rate, .. } => { - TimeBase::try_new(1, i64::from(*rate)).unwrap_or(TimeBase::from_rate(48_000)) - } + Mapping::Vorbis { rate, .. } | Mapping::Flac { rate, .. } => TimeBase::from_rate(*rate), } } @@ -211,6 +210,8 @@ mod tests { assert_eq!(mapping.layout(), ChannelLayout::Surround5_1); assert_eq!(mapping.header_packets(), 2); + vorbis[12..16].fill(0); + assert_eq!(Mapping::identify(&vorbis), None); assert_eq!(Mapping::identify(b"not a header at all"), None); assert_eq!(Mapping::identify(&[]), None); }