forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/b6' into simplify/w1a

Browse files at this commit

eb345bb202d40b592a198dd2a11d6817f99af8f2Ahmet Kaan GümüşParent: afa57b3b4ff43f
crates/ec-ogg/src/mapping.rsmodified+7 -6
@@ -48,8 +48,9 @@ impl Mapping {
4848 /// a private mapping — all valid Ogg, none of them ours).
4949 pub fn identify(bos: &[u8]) -> Option<Mapping> {
5050 if bos.len() >= 16 && bos[0] == 1 && &bos[1..7] == b"vorbis" {
51- return Some(Mapping::Vorbis {
52- rate: u32::from_le_bytes(bos[12..16].try_into().ok()?),
51+ let rate = u32::from_le_bytes(bos[12..16].try_into().ok()?);
52+ return (rate != 0).then_some(Mapping::Vorbis {
53+ rate,
5354 channels: bos[11],
5455 });
5556 }
@@ -67,7 +68,7 @@ impl Mapping {
6768 let rate =
6869 (u32::from(si[10]) << 12) | (u32::from(si[11]) << 4) | u32::from(si[12] >> 4);
6970 let declared = usize::from(u16::from_be_bytes([bos[7], bos[8]]));
70- return Some(Mapping::Flac {
71+ return (rate != 0).then_some(Mapping::Flac {
7172 rate,
7273 channels: ((si[12] >> 1) & 0x07) + 1,
7374 // A zero here means "not stated"; the comment header still
@@ -92,9 +93,7 @@ impl Mapping {
9293 match self {
9394 // Opus granules are always 48 kHz, whatever the encoder was fed.
9495 Mapping::Opus { .. } => TimeBase::from_rate(48_000),
95- Mapping::Vorbis { rate, .. } | Mapping::Flac { rate, .. } => {
96- TimeBase::try_new(1, i64::from(*rate)).unwrap_or(TimeBase::from_rate(48_000))
97- }
96+ Mapping::Vorbis { rate, .. } | Mapping::Flac { rate, .. } => TimeBase::from_rate(*rate),
9897 }
9998 }
10099
@@ -211,6 +210,8 @@ mod tests {
211210 assert_eq!(mapping.layout(), ChannelLayout::Surround5_1);
212211 assert_eq!(mapping.header_packets(), 2);
213212
213+ vorbis[12..16].fill(0);
214+ assert_eq!(Mapping::identify(&vorbis), None);
214215 assert_eq!(Mapping::identify(b"not a header at all"), None);
215216 assert_eq!(Mapping::identify(&[]), None);
216217 }