#[test]
fn test_all_artifacts() {
extern crate std;
use crate::decoding::BlockDecodingStrategy;
use crate::decoding::FrameDecoder;
use std::borrow::ToOwned;
use std::fs;
use std::fs::File;
let mut frame_dec = FrameDecoder::new();
let entries = match fs::read_dir("./fuzz/artifacts/decode") {
Ok(e) => e,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => return,
Err(err) => panic!("unexpected error reading fuzz artifacts dir: {err}"),
};
for file in entries {
let file_name = file.unwrap().path();
let fnstr = file_name.to_str().unwrap().to_owned();
if !fnstr.contains("/crash-") {
continue;
}
let mut f = File::open(file_name.clone()).unwrap();
let _: Result<_, _> = frame_dec
.reset(&mut f)
.and_then(|()| frame_dec.decode_blocks(&mut f, BlockDecodingStrategy::All));
}
}
#[test]
fn interop_7_byte_input_does_not_oob_in_dfast_fast_loop() {
use crate::decoding::{BlockDecodingStrategy, FrameDecoder};
use crate::encoding::{CompressionLevel, compress_to_vec};
let data: &[u8] = &[0x04, 0x60, 0x2e, 0x20, 0x20, 0x0a, 0x20];
let compressed = compress_to_vec(data, CompressionLevel::Level(3));
let mut frame_dec = FrameDecoder::new();
let mut cursor = compressed.as_slice();
frame_dec.reset(&mut cursor).unwrap();
frame_dec
.decode_blocks(&mut cursor, BlockDecodingStrategy::All)
.unwrap();
let decoded = frame_dec.collect().expect("decoder returned no payload");
assert_eq!(decoded.as_slice(), data);
}
#[test]
fn malformed_block_does_not_panic_via_restore_checkpoint() {
extern crate std;
use std::io::Read;
let data: &[u8] = &[
0x28, 0xb5, 0x2f, 0xfd, 0x5d, 0x00, 0x00, 0xf7, 0x06, 0x5d, 0x00, 0x00, 0x5d, 0x00, 0x80,
0xf7, 0xff, 0x5d, 0x00, 0x00, 0x01, 0xe0, 0xe0, 0xe0, 0xe0, 0xe2, 0xe0, 0xa4, 0x00, 0x0c,
0x0c, 0x2c, 0x0c,
];
let mut decoder = crate::decoding::StreamingDecoder::new(data)
.expect("regression artifact must pass frame-header construction");
let mut output = alloc::vec::Vec::new();
assert!(
decoder.read_to_end(&mut output).is_err(),
"malformed block must surface a decode Err, not decode successfully"
);
}
#[test]
fn multi_frame_flat_buf_path_does_not_panic() {
extern crate std;
use std::io::Read;
let data: &[u8] = &[
0x28, 0xB5, 0x2F, 0xFD, 0x28, 0x28, 0xF5, 0x00, 0x00, 0x2D, 0x27, 0x8C, 0xB4, 0xB4, 0x20,
0xA0, 0x00, 0x02, 0x00, 0xF2, 0xF2, 0xF2, 0xF2, 0x85, 0x21, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
0xF2, 0xF2, 0xF2, 0xF2, 0xA8, 0xA8, 0xA8, 0xA8, 0x28, 0xB5, 0x2F, 0xFD, 0x30, 0x28, 0x2D,
0x00, 0x00, 0x61, 0x6A, 0x10, 0x00, 0x2D, 0x00, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8,
0xF2, 0xF2, 0xF2, 0x28, 0xB5, 0x2F, 0xFD, 0x00, 0x28, 0xB5, 0x2F, 0x00, 0x00, 0xB5, 0x28,
0x00, 0x28, 0xFD, 0xB5, 0x00, 0x00, 0x2D, 0x0B, 0x8C, 0xB4, 0xB4, 0x04, 0x21, 0xA0, 0x00,
0x00, 0x5E, 0xB4, 0x00, 0x00, 0x72, 0xA4, 0x00, 0xB4, 0x00, 0xFF, 0xFF, 0xFF, 0x28, 0x72,
0xA4, 0x00, 0xB4, 0x00, 0x00, 0x72, 0x28, 0xCF, 0xA4, 0x00, 0xB4, 0xA8, 0x28, 0xB5, 0x2F,
0xFD, 0x30, 0x00, 0x2D, 0x00, 0x00, 0x61, 0x6A, 0x10, 0x00, 0x2D, 0x00, 0xA8, 0xA8, 0xA8,
0xA8, 0xA8, 0xA8, 0xA8, 0xF2, 0xF2, 0xF2, 0x28, 0xB5, 0x2F, 0xFD, 0x00, 0x28, 0xB5, 0x00,
0x00, 0x28, 0xB5, 0x2F, 0xFD, 0x00, 0x28, 0xB5, 0x00, 0x02, 0x00, 0x2D, 0x0B, 0x02, 0x02,
0x02, 0xFF, 0xFF, 0xF2, 0x00, 0x8C,
];
let mut decoder = crate::decoding::StreamingDecoder::new(data)
.expect("regression artifact must pass frame-header construction");
let mut output = alloc::vec::Vec::new();
let _ = decoder.read_to_end(&mut output);
}