use crate::tier1::mq::MqDecoder;
use crate::tier1::passes::{BlockParams, BlockState, Orientation, decode_block, init_contexts};
pub fn mq_stream(data: &[u8]) {
let mut mq = MqDecoder::new(data);
let mut contexts = init_contexts();
let decisions = (data.len() * 8).clamp(256, 1 << 20);
for i in 0..decisions {
let _ = mq.decode(&mut contexts[i % contexts.len()]);
}
}
pub fn tier1_block(data: &[u8]) {
let [a, b, c, d, e, f, g, coded @ ..] = data else {
return;
};
use crate::codestream::markers::code_block_style::{PTERM, RESET, SEGSYM, TERMALL, VCAUSAL};
let width = u32::from(a & 0x3F) + 1; let height = u32::from(b & 0x3F) + 1;
let orient = match a >> 6 {
0 => Orientation::Ll,
1 => Orientation::Hl,
2 => Orientation::Lh,
_ => Orientation::Hh,
};
let params = BlockParams {
style: c & (RESET | TERMALL | VCAUSAL | PTERM | SEGSYM),
roi_shift: d & 0x3F,
};
let num_passes = u32::from(*e) % 110; let numbps = u32::from(*f) % 31; let zero_bit_planes = u32::from(*g) % 32;
let mut state = BlockState::new(width, height);
let segments = [(coded.to_vec(), num_passes)];
let _ = decode_block(
&segments,
&mut state,
orient,
numbps,
num_passes,
zero_bit_planes,
params,
);
}
#[cfg(test)]
mod tests {
#[test]
fn fuzz_hooks_run_on_sample_inputs() {
let samples: [&[u8]; 5] = [
&[],
&[0xFF; 40],
&[0x00; 40],
&[0x55, 0x1E, 0x22, 0x0A, 0x03, 0x80, 0xFF, 0x91],
&[0xC0, 0x24, 0x6D, 0x1E, 0x21, 0xFF, 0xD9, 0x00],
];
for sample in samples {
super::mq_stream(sample);
super::tier1_block(sample);
}
}
}