flac
flac copied to clipboard
index out of bounds panic when parsing bytes
extern crate flac;
use flac::{ByteStream, Stream};
fn main() {
let s = Stream::<ByteStream>::from_buffer(b"fLaC\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\\");
if let Ok(mut stream) = s {
let _ = stream.info();
let _ = stream.metadata();
let mut iter = stream.iter::<i8>();
while iter.next().is_some() { }
}
}
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /root/.cargo/git/checkouts/flac-34fb57da42139a77/9549bf8/src/utility/macros.rs:9
Found via https://github.com/rust-fuzz/cargo-fuzz
https://datatracker.ietf.org/doc/rfc9639/
We have bytes fLaC followed by a header (big-endian): 0x01, 0x00, 0x00, 0x00. Per 8.1 this is a Padding (0x01) metadata block. Per sections 8 and 8.2 the first metadata block must be StreamInfo (i.e. first byte 0x00).
With that said, this crate hasn't seen activity for nearly a decade. It may be better to try https://github.com/tuffy/flac-codec.