diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ceaee..e1205bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,11 @@ part was built. - **The image hash and the PNG**: `sha256:` and the lowercase hex SHA-256 of the raw RGBA8 bytes (ADR 0009), with Lumen's own SHA-256; a PNG encoder with stored deflate blocks, whose bytes are a fixed function of the pixels (`write_png`, `png_len`). (flyingrobots/lumen#2.) +- **Image decoding, `lumen-image`** (ADR 0012): a workspace crate with no dependency and no + float, inside the deterministic core, that `lumen` depends on. It decompresses a zlib stream + (RFC 1950 and 1951: stored, fixed- and dynamic-Huffman blocks, the Adler-32 check) into a + caller-limited output, refusing every malformed stream with a typed error and its byte + offset. (flyingrobots/lumen#195.) - **Tests**: hand-derived radiance, shadows against exact geometry, every ray and every sample against brute force and an independent composition, order independence, counts against oracles other than the counting code, golden image hashes and content digests (one value for diff --git a/crates/lumen-image/Cargo.toml b/crates/lumen-image/Cargo.toml new file mode 100644 index 0000000..0afb782 --- /dev/null +++ b/crates/lumen-image/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "lumen-image" +description = "Lumen's image decoders: integer-only, with no dependency (ADR 0012)." +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true +keywords = ["zlib", "inflate", "deterministic"] +categories = ["compression"] +publish = false + +[lints] +workspace = true diff --git a/crates/lumen-image/src/inflate.rs b/crates/lumen-image/src/inflate.rs new file mode 100644 index 0000000..8f375f5 --- /dev/null +++ b/crates/lumen-image/src/inflate.rs @@ -0,0 +1,144 @@ +//! This module owns zlib decompression: the RFC 1950 frame (a two-byte header, deflate blocks, +//! an Adler-32 trailer) and the entry points. +//! +//! The rules the decoder holds to, beyond the RFCs' own: +//! +//! - **A preset dictionary is refused** (`FDICT` set), by name: no caller supplies one. +//! - **Distances are checked twice**: against the bytes decoded so far, and against the window +//! the header declares (`CINFO`, 256 to 32 768 bytes), as zlib's own decoder does. +//! - **Incomplete codes**: a literal/length or distance code whose lengths do not fill the code +//! space is refused, except a code of exactly one symbol of length 1 (RFC 1951 section 3.2.7 +//! allows one distance code of one bit; zlib accepts the same shape in either alphabet) and a +//! distance code with no symbols at all (a block of literals only). Reading the unused bit +//! pattern of such a code is refused. The code-length code must be complete. +//! - **Trailing bytes are an error**: the stream must end at its Adler-32 trailer. +//! +//! Byte offsets in errors count from the start of the stream (for [`inflate_zlib_chunks`], of +//! the chunks' concatenation). A fault is reported at the byte holding the last bit read when +//! it was found; a truncation at the stream's length, the first byte that is missing. + +mod adler32; +mod bits; +mod blocks; +mod error; +mod huffman; +mod output; +#[cfg(test)] +mod tests; + +pub use error::{Alphabet, InflateError, InflateErrorKind}; + +use bits::BitReader; +use output::Output; + +/// The identity of the decoder's contract: which zlib streams it accepts (the rules above and +/// in [`InflateErrorKind`]) and what it returns for them. An accepted stream's output is fixed +/// by RFC 1951; a change to what is refused makes a new identity. +pub const INFLATE_ID: &str = "lumen-zlib-inflate/1"; + +/// The most bytes a decode may produce, from the caller. +/// +/// A stream whose output would pass it is refused with [`InflateErrorKind::OutputLimit`] as soon +/// as a block declares or decodes the first byte beyond it, and the output's buffer never +/// requests capacity beyond it. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct OutputLimit { + bytes: usize, +} + +impl OutputLimit { + /// A limit of `bytes` decoded bytes; zero admits only an empty stream. + #[must_use] + pub const fn new(bytes: usize) -> Self { + Self { bytes } + } + + /// The limit in bytes. + #[must_use] + pub const fn bytes(self) -> usize { + self.bytes + } +} + +/// Decompresses the zlib stream `stream` into at most `limit` bytes. +/// +/// Allocates the returned vector, at most `limit` bytes of capacity; reads nothing outside +/// `stream`. +/// +/// # Errors +/// +/// An [`InflateError`] for a malformed or truncated stream, a bad Adler-32 check, bytes after +/// the trailer, or an output beyond `limit`; its [`kind`](InflateError::kind) names the fault. +/// +/// # Panics +/// +/// Does not panic. +pub fn inflate_zlib(stream: &[u8], limit: OutputLimit) -> Result, InflateError> { + inflate_zlib_chunks(&[stream], limit) +} + +/// Decompresses one zlib stream stored as the concatenation of `chunks`, in order, into at most +/// `limit` bytes: a PNG file's `IDAT` chunk data, passed without copying them together. Empty +/// chunks are allowed, and a chunk boundary may fall anywhere, even inside a code. Error offsets +/// count from the start of the first chunk. +/// +/// # Errors +/// +/// As [`inflate_zlib`]. +/// +/// # Panics +/// +/// Does not panic. +pub fn inflate_zlib_chunks( + chunks: &[&[u8]], + limit: OutputLimit, +) -> Result, InflateError> { + let mut input = BitReader::new(chunks); + let window = header(&mut input)?; + let mut output = Output::new(limit.bytes, window); + blocks::inflate(&mut input, &mut output)?; + trailer(&mut input, output.bytes())?; + Ok(output.into_bytes()) +} + +/// Reads the two header bytes (RFC 1950 section 2.2) and returns the window size they declare. +fn header(input: &mut BitReader<'_>) -> Result { + let cmf = input.byte()?; + let flg = input.byte()?; + let at = |kind| InflateError::new(kind, input.last_offset()); + if (u16::from(cmf) << 8 | u16::from(flg)) % 31 != 0 { + return Err(at(InflateErrorKind::HeaderCheck { cmf, flg })); + } + if cmf & 0x0f != 8 { + return Err(at(InflateErrorKind::CompressionMethod { method: cmf & 0x0f })); + } + let cinfo = cmf >> 4; + if cinfo > 7 { + return Err(at(InflateErrorKind::WindowSize { cinfo })); + } + if flg & 0x20 != 0 { + return Err(at(InflateErrorKind::PresetDictionary)); + } + Ok(1 << (cinfo + 8)) +} + +/// Reads the Adler-32 trailer after the last block (RFC 1950 section 2.2), checks it against +/// `decoded` and refuses anything after it. +fn trailer(input: &mut BitReader<'_>, decoded: &[u8]) -> Result<(), InflateError> { + input.align(); + let mut stored = 0_u32; + for _ in 0..4 { + stored = stored << 8 | u32::from(input.byte()?); + } + let computed = adler32::adler32(decoded); + if stored != computed { + let kind = InflateErrorKind::Adler32Mismatch { stored, computed }; + return Err(InflateError::new(kind, input.last_offset())); + } + let trailing = input.remaining(); + if trailing != 0 { + let kind = InflateErrorKind::TrailingBytes { count: trailing }; + return Err(InflateError::new(kind, input.next_offset())); + } + Ok(()) +} diff --git a/crates/lumen-image/src/inflate/adler32.rs b/crates/lumen-image/src/inflate/adler32.rs new file mode 100644 index 0000000..bc78768 --- /dev/null +++ b/crates/lumen-image/src/inflate/adler32.rs @@ -0,0 +1,24 @@ +//! This module owns the Adler-32 checksum of RFC 1950 section 8. + +/// The largest prime below 2^16. +const MODULUS: u32 = 65_521; + +/// The most bytes summed before reducing: the largest `n` with +/// `255 n (n + 1) / 2 + (n + 1) (MODULUS - 1) < 2^32`, so neither sum can overflow (zlib's +/// `NMAX`). +const RUN: usize = 5_552; + +/// The Adler-32 of `bytes`: the high half is the sum of the running sums, the low half one +/// plus the sum of the bytes, both modulo 65 521. +pub(super) fn adler32(bytes: &[u8]) -> u32 { + let (mut low, mut high) = (1_u32, 0_u32); + for run in bytes.chunks(RUN) { + for &byte in run { + low += u32::from(byte); + high += low; + } + low %= MODULUS; + high %= MODULUS; + } + high << 16 | low +} diff --git a/crates/lumen-image/src/inflate/bits.rs b/crates/lumen-image/src/inflate/bits.rs new file mode 100644 index 0000000..344bb74 --- /dev/null +++ b/crates/lumen-image/src/inflate/bits.rs @@ -0,0 +1,99 @@ +//! This module owns reading the input: bytes from a sequence of slices, and bits from those +//! bytes least significant first (RFC 1951 section 3.1.1). + +use super::error::{InflateError, InflateErrorKind}; + +/// A reader of bits and bytes over the concatenation of its chunks. +/// +/// Invariant: `held < 8` between calls, so the last byte taken holds every buffered bit, and +/// the bit most recently read is in byte `taken - 1`. +pub(super) struct BitReader<'a> { + chunks: &'a [&'a [u8]], + /// The chunk being read, and the position in it. + chunk: usize, + at: usize, + /// Bytes taken from the input so far. + taken: usize, + /// Bits taken but not yet read, the next one lowest, and how many. + buffer: u32, + held: u32, +} + +impl<'a> BitReader<'a> { + pub(super) fn new(chunks: &'a [&'a [u8]]) -> Self { + Self { chunks, chunk: 0, at: 0, taken: 0, buffer: 0, held: 0 } + } + + /// The offset of the byte that holds the last bit read (zero before any). + pub(super) fn last_offset(&self) -> usize { + self.taken.saturating_sub(1) + } + + /// The offset of the next byte to be taken. + pub(super) fn next_offset(&self) -> usize { + self.taken + } + + /// The next whole byte, after the bits already read are discarded by [`Self::align`]. + pub(super) fn byte(&mut self) -> Result { + while let Some(chunk) = self.chunks.get(self.chunk) { + if let Some(&byte) = chunk.get(self.at) { + self.at += 1; + self.taken = self.taken.saturating_add(1); + return Ok(byte); + } + self.chunk += 1; + self.at = 0; + } + Err(InflateError::new(InflateErrorKind::Truncated, self.taken)) + } + + /// The next `count` bits (at most 16) as an integer, the first read lowest. + pub(super) fn bits(&mut self, count: u32) -> Result { + debug_assert!(count <= 16, "at most 16 bits at a time"); + while self.held < count { + // `held < count <= 16`, so the byte lands below bit 24. + self.buffer |= u32::from(self.byte()?) << self.held; + self.held += 8; + } + let value = self.buffer & ((1 << count) - 1); + self.buffer >>= count; + self.held -= count; + Ok(value) + } + + /// Discards the bits left in the current byte, so the next read starts on a byte boundary. + pub(super) fn align(&mut self) { + self.buffer = 0; + self.held = 0; + } + + /// Copies the next `count` whole bytes into `out`, as a stored block's data. Call after + /// [`Self::align`]. + pub(super) fn copy(&mut self, count: usize, out: &mut Vec) -> Result<(), InflateError> { + let mut left = count; + while left > 0 { + let Some(chunk) = self.chunks.get(self.chunk) else { + return Err(InflateError::new(InflateErrorKind::Truncated, self.taken)); + }; + let rest = chunk.get(self.at..).unwrap_or_default(); + let take = rest.len().min(left); + out.extend_from_slice(rest.get(..take).unwrap_or_default()); + self.at += take; + self.taken = self.taken.saturating_add(take); + left -= take; + if left > 0 { + self.chunk += 1; + self.at = 0; + } + } + Ok(()) + } + + /// The bytes not yet taken, in every chunk. + pub(super) fn remaining(&self) -> usize { + let current = self.chunks.get(self.chunk).map_or(0, |c| c.len().saturating_sub(self.at)); + let later = self.chunks.get(self.chunk + 1..).unwrap_or_default(); + later.iter().fold(current, |sum, c| sum.saturating_add(c.len())) + } +} diff --git a/crates/lumen-image/src/inflate/blocks.rs b/crates/lumen-image/src/inflate/blocks.rs new file mode 100644 index 0000000..66851c9 --- /dev/null +++ b/crates/lumen-image/src/inflate/blocks.rs @@ -0,0 +1,161 @@ +//! This module owns the deflate blocks of RFC 1951 section 3.2: their headers, the stored, +//! fixed-Huffman and dynamic-Huffman forms, and the literal, length and distance symbols. + +use super::bits::BitReader; +use super::error::{Alphabet, InflateError, InflateErrorKind}; +use super::huffman::{CodeFault, Huffman}; +use super::output::Output; + +/// The base length of length symbols 257 to 285, and their extra bits (section 3.2.5). +const LENGTH_BASE: [u16; 29] = [ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, + 163, 195, 227, 258, +]; +const LENGTH_EXTRA: [u8; 29] = + [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]; + +/// The base distance of distance symbols 0 to 29, and their extra bits (section 3.2.5). +const DISTANCE_BASE: [u16; 30] = [ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, + 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, +]; +const DISTANCE_EXTRA: [u8; 30] = + [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; + +/// The order in which a dynamic block lists the code-length code's lengths (section 3.2.7). +const CODE_LENGTH_ORDER: [usize; 19] = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; + +/// The end-of-block symbol. +const END_OF_BLOCK: u16 = 256; + +/// Decodes blocks into `output` until the one marked final. +pub(super) fn inflate(input: &mut BitReader<'_>, output: &mut Output) -> Result<(), InflateError> { + loop { + let last = input.bits(1)? == 1; + match input.bits(2)? { + 0 => stored(input, output)?, + 1 => { + let (literals, distances) = fixed(); + codes(input, output, &literals, &distances)?; + } + 2 => { + let (literals, distances) = dynamic(input)?; + codes(input, output, &literals, &distances)?; + } + _ => return Err(InflateError::new(InflateErrorKind::ReservedBlockType, input.last_offset())), + } + if last { + return Ok(()); + } + } +} + +/// A stored block (section 3.2.4): to the byte boundary, `LEN`, `NLEN`, then `LEN` bytes. +fn stored(input: &mut BitReader<'_>, output: &mut Output) -> Result<(), InflateError> { + input.align(); + let mut field = || -> Result { + let low = input.byte()?; + Ok(u16::from_le_bytes([low, input.byte()?])) + }; + let (len, nlen) = (field()?, field()?); + if len != !nlen { + let kind = InflateErrorKind::StoredLengthMismatch { len, nlen }; + return Err(InflateError::new(kind, input.last_offset())); + } + output.stored(input, usize::from(len)) +} + +/// The fixed codes (section 3.2.6): literal/length 0-143 of 8 bits, 144-255 of 9, 256-279 of 7, +/// 280-287 of 8; all 32 distance codes of 5 bits. Both are complete. +fn fixed() -> (Huffman, Huffman) { + let mut lengths = [8_u8; 288]; + lengths[144..256].fill(9); + lengths[256..280].fill(7); + (Huffman::canonical(Alphabet::LiteralLength, &lengths), Huffman::canonical(Alphabet::Distance, &[5; 32])) +} + +/// A dynamic block's header (section 3.2.7): the counts, the code-length code, then the +/// literal/length and distance code lengths it encodes. +fn dynamic(input: &mut BitReader<'_>) -> Result<(Huffman, Huffman), InflateError> { + let literal_count = 257 + input.bits(5)?; + let distance_count = 1 + input.bits(5)?; + let length_count = 4 + input.bits(4)?; + let too_many = |alphabet, count: u32| { + let count = u16::try_from(count).unwrap_or(u16::MAX); + InflateError::new(InflateErrorKind::TooManyCodes { alphabet, count }, input.last_offset()) + }; + if literal_count > 286 { + return Err(too_many(Alphabet::LiteralLength, literal_count)); + } + if distance_count > 30 { + return Err(too_many(Alphabet::Distance, distance_count)); + } + let mut code_lengths = [0_u8; 19]; + for &symbol in CODE_LENGTH_ORDER.iter().take(usize::try_from(length_count).unwrap_or(19)) { + code_lengths[symbol] = u8::try_from(input.bits(3)?).unwrap_or(0); + } + let code_lengths = build(input, Alphabet::CodeLength, &code_lengths)?; + let (literal_count, total) = (literal_count as usize, (literal_count + distance_count) as usize); + let mut lengths = [0_u8; 286 + 30]; + let mut filled = 0; + while filled < total { + let symbol = code_lengths.decode(input)?; + let (value, repeat) = match symbol { + 0..=15 => (u8::try_from(symbol).unwrap_or(0), 1), + 16 => { + let previous = filled.checked_sub(1).and_then(|i| lengths.get(i)).copied(); + let previous = previous.ok_or(InflateError::new(InflateErrorKind::RepeatWithoutLength, input.last_offset()))?; + (previous, 3 + input.bits(2)?) + } + 17 => (0, 3 + input.bits(3)?), + _ => (0, 11 + input.bits(7)?), + }; + let end = filled + repeat as usize; + let run = lengths.get_mut(filled..end).filter(|_| end <= total); + run.ok_or(InflateError::new(InflateErrorKind::CodeLengthsOverrun, input.last_offset()))?.fill(value); + filled = end; + } + if lengths[usize::from(END_OF_BLOCK)] == 0 { + return Err(InflateError::new(InflateErrorKind::MissingEndOfBlock, input.last_offset())); + } + let literals = build(input, Alphabet::LiteralLength, &lengths[..literal_count])?; + let distances = build(input, Alphabet::Distance, &lengths[literal_count..total])?; + Ok((literals, distances)) +} + +/// The code of `lengths` in `alphabet`, or the error for its fault at the current offset. +fn build(input: &BitReader<'_>, alphabet: Alphabet, lengths: &[u8]) -> Result { + Huffman::new(alphabet, lengths).map_err(|fault| { + let kind = match fault { + CodeFault::OverSubscribed => InflateErrorKind::OverSubscribedCode { alphabet }, + CodeFault::Incomplete => InflateErrorKind::IncompleteCode { alphabet }, + }; + InflateError::new(kind, input.last_offset()) + }) +} + +/// A Huffman-coded block's symbols (section 3.2.5), to its end-of-block symbol. +fn codes(input: &mut BitReader<'_>, output: &mut Output, literals: &Huffman, distances: &Huffman) -> Result<(), InflateError> { + loop { + let symbol = literals.decode(input)?; + let invalid = |alphabet, symbol| InflateError::new(InflateErrorKind::InvalidSymbol { alphabet, symbol }, input.last_offset()); + match symbol { + 0..=255 => output.literal(u8::try_from(symbol).unwrap_or(0), input.last_offset())?, + END_OF_BLOCK => return Ok(()), + _ => { + let index = usize::from(symbol - 257); + let (Some(&base), Some(&extra)) = (LENGTH_BASE.get(index), LENGTH_EXTRA.get(index)) else { + return Err(invalid(Alphabet::LiteralLength, symbol)); + }; + let length = usize::from(base) + input.bits(u32::from(extra))? as usize; + let symbol = distances.decode(input)?; + let index = usize::from(symbol); + let (Some(&base), Some(&extra)) = (DISTANCE_BASE.get(index), DISTANCE_EXTRA.get(index)) else { + return Err(invalid(Alphabet::Distance, symbol)); + }; + let distance = usize::from(base) + input.bits(u32::from(extra))? as usize; + output.copy_match(distance, length, input.last_offset())?; + } + } + } +} diff --git a/crates/lumen-image/src/inflate/error.rs b/crates/lumen-image/src/inflate/error.rs new file mode 100644 index 0000000..fcea15c --- /dev/null +++ b/crates/lumen-image/src/inflate/error.rs @@ -0,0 +1,202 @@ +//! This module owns the decoder's errors: what was refused, and where. + +use core::fmt; + +/// A refused zlib stream: the fault, and the byte offset where it was found (see the +/// [crate documentation](crate) for how offsets are counted). +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct InflateError { + kind: InflateErrorKind, + offset: usize, +} + +impl InflateError { + pub(super) const fn new(kind: InflateErrorKind, offset: usize) -> Self { + Self { kind, offset } + } + + /// What was refused. + #[must_use] + pub const fn kind(&self) -> &InflateErrorKind { + &self.kind + } + + /// The offset, from the start of the stream, of the byte where the fault was found: the + /// byte holding the last bit read, or for [`InflateErrorKind::Truncated`] the stream's + /// length, and for [`InflateErrorKind::TrailingBytes`] the first byte after the trailer. + #[must_use] + pub const fn offset(&self) -> usize { + self.offset + } +} + +/// One of the three Huffman alphabets of a deflate block (RFC 1951 section 3.2.7). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Alphabet { + /// The code lengths' own code, of 19 symbols, that a dynamic block's header uses. + CodeLength, + /// Literal bytes, the end of the block and match lengths: 286 symbols, 288 codes. + LiteralLength, + /// Match distances: 30 symbols, 32 codes. + Distance, +} + +/// Why a zlib stream was refused. +#[derive(Clone, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub enum InflateErrorKind { + /// The two header bytes, read as a big-endian number, are not a multiple of 31. + HeaderCheck { + /// The first header byte (`CMF`). + cmf: u8, + /// The second header byte (`FLG`). + flg: u8, + }, + /// The compression method is not 8 (deflate). + CompressionMethod { + /// The method the header names. + method: u8, + }, + /// The window size field is above 7 (a window over 32 768 bytes). + WindowSize { + /// The field (`CINFO`). + cinfo: u8, + }, + /// The header asks for a preset dictionary (`FDICT`), which no caller supplies. + PresetDictionary, + /// A block has the reserved type 3. + ReservedBlockType, + /// A stored block's length is not the complement of its check field. + StoredLengthMismatch { + /// The length field (`LEN`). + len: u16, + /// The check field (`NLEN`). + nlen: u16, + }, + /// A dynamic block declares more literal/length or distance codes than the alphabet has + /// symbols (over 286 or 30). + TooManyCodes { + /// The alphabet. + alphabet: Alphabet, + /// How many codes the block declares. + count: u16, + }, + /// A code's lengths give more codes than the code space holds. + OverSubscribedCode { + /// The alphabet. + alphabet: Alphabet, + }, + /// A code's lengths leave part of the code space unused, outside the shapes the decoder + /// admits (one symbol of length 1; no distance symbol at all). + IncompleteCode { + /// The alphabet. + alphabet: Alphabet, + }, + /// A repeat of the previous code length (symbol 16) comes first. + RepeatWithoutLength, + /// The code lengths run past the number of codes the block declares. + CodeLengthsOverrun, + /// The end-of-block symbol (256) has no code. + MissingEndOfBlock, + /// The bits read are the unused pattern of an incomplete code. + UnusedCode { + /// The alphabet. + alphabet: Alphabet, + }, + /// A fixed block's code for a symbol outside the alphabet: literal/length 286 or 287, or + /// distance 30 or 31. + InvalidSymbol { + /// The alphabet. + alphabet: Alphabet, + /// The symbol. + symbol: u16, + }, + /// A match reaches back past the first decoded byte. + DistanceTooFar { + /// The match's distance. + distance: usize, + /// The bytes decoded before the match. + available: usize, + }, + /// A match reaches back past the window the header declares. + DistanceBeyondWindow { + /// The match's distance. + distance: usize, + /// The window size in bytes. + window: usize, + }, + /// The stream ends before its last block or its trailer does. + Truncated, + /// The Adler-32 trailer does not match the decoded bytes. + Adler32Mismatch { + /// The trailer's value. + stored: u32, + /// The Adler-32 of the decoded bytes. + computed: u32, + }, + /// Bytes follow the Adler-32 trailer. + TrailingBytes { + /// How many. + count: usize, + }, + /// The output would pass the caller's limit. + OutputLimit { + /// The limit in bytes. + limit: usize, + }, +} + +impl fmt::Display for Alphabet { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Self::CodeLength => "code-length", + Self::LiteralLength => "literal/length", + Self::Distance => "distance", + }) + } +} + +impl fmt::Display for InflateErrorKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::HeaderCheck { cmf, flg } => { + write!(f, "header check failed: {cmf:#04x} {flg:#04x} is not a multiple of 31") + } + Self::CompressionMethod { method } => write!(f, "compression method {method} is not deflate"), + Self::WindowSize { cinfo } => write!(f, "window size field {cinfo} is over 7"), + Self::PresetDictionary => f.write_str("a preset dictionary is not supported"), + Self::ReservedBlockType => f.write_str("reserved block type 3"), + Self::StoredLengthMismatch { len, nlen } => { + write!(f, "stored block length {len} does not match its complement {nlen}") + } + Self::TooManyCodes { alphabet, count } => write!(f, "{count} {alphabet} codes declared"), + Self::OverSubscribedCode { alphabet } => write!(f, "over-subscribed {alphabet} code"), + Self::IncompleteCode { alphabet } => write!(f, "incomplete {alphabet} code"), + Self::RepeatWithoutLength => f.write_str("code length repeat with no previous length"), + Self::CodeLengthsOverrun => f.write_str("code lengths run past the declared codes"), + Self::MissingEndOfBlock => f.write_str("the end-of-block symbol has no code"), + Self::UnusedCode { alphabet } => write!(f, "unused {alphabet} code"), + Self::InvalidSymbol { alphabet, symbol } => write!(f, "invalid {alphabet} symbol {symbol}"), + Self::DistanceTooFar { distance, available } => { + write!(f, "distance {distance} reaches before the output's {available} bytes") + } + Self::DistanceBeyondWindow { distance, window } => { + write!(f, "distance {distance} is beyond the {window}-byte window") + } + Self::Truncated => f.write_str("the stream is truncated"), + Self::Adler32Mismatch { stored, computed } => { + write!(f, "adler-32 {stored:#010x} does not match the output's {computed:#010x}") + } + Self::TrailingBytes { count } => write!(f, "{count} bytes after the trailer"), + Self::OutputLimit { limit } => write!(f, "the output passes its limit of {limit} bytes"), + } + } +} + +impl fmt::Display for InflateError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "zlib stream refused at byte {}: {}", self.offset, self.kind) + } +} + +impl core::error::Error for InflateError {} diff --git a/crates/lumen-image/src/inflate/huffman.rs b/crates/lumen-image/src/inflate/huffman.rs new file mode 100644 index 0000000..f25d609 --- /dev/null +++ b/crates/lumen-image/src/inflate/huffman.rs @@ -0,0 +1,101 @@ +//! This module owns the canonical Huffman codes of RFC 1951 section 3.2.2: building a code from +//! its lengths, with the completeness rules of the [module above](super), and decoding a symbol +//! bit by bit. + +use super::bits::BitReader; +use super::error::{Alphabet, InflateError, InflateErrorKind}; + +/// The longest code any alphabet uses. +const MAX_BITS: usize = 15; + +/// The most codes in any alphabet (the fixed literal/length code's 288). +const MAX_SYMBOLS: usize = 288; + +/// A canonical Huffman code: how many codes there are of each length, and the symbols in code +/// order (by length, then by symbol). +pub(super) struct Huffman { + alphabet: Alphabet, + counts: [u16; MAX_BITS + 1], + symbols: [u16; MAX_SYMBOLS], + longest: usize, +} + +/// Why a set of lengths makes no code the decoder admits. +#[derive(Debug, PartialEq, Eq)] +pub(super) enum CodeFault { + OverSubscribed, + Incomplete, +} + +impl Huffman { + /// The code whose symbol `s` has length `lengths[s]` (0: no code), refused if it is + /// over-subscribed or incomplete beyond the shapes [the module above](super) admits. + /// `lengths` holds at most 288 entries, each at most 15: the callers' alphabets guarantee + /// both. + pub(super) fn new(alphabet: Alphabet, lengths: &[u8]) -> Result { + let code = Self::canonical(alphabet, lengths); + // The code space left after each length; negative means more codes than room. + let mut left: i32 = 1; + for &count in code.counts.iter().skip(1) { + left = 2 * left - i32::from(count); + if left < 0 { + return Err(CodeFault::OverSubscribed); + } + } + let used: u16 = code.counts.iter().sum(); + let single = used == 1 && code.counts[1] == 1 && alphabet != Alphabet::CodeLength; + let none = used == 0 && alphabet == Alphabet::Distance; + if left > 0 && !single && !none { + return Err(CodeFault::Incomplete); + } + Ok(code) + } + + /// The canonical code of `lengths`, unchecked: for the fixed codes, which are complete. + pub(super) fn canonical(alphabet: Alphabet, lengths: &[u8]) -> Self { + let mut code = Self { alphabet, counts: [0; MAX_BITS + 1], symbols: [0; MAX_SYMBOLS], longest: 0 }; + for &length in lengths.iter().filter(|&&l| l != 0) { + if let Some(count) = code.counts.get_mut(usize::from(length)) { + *count += 1; + code.longest = code.longest.max(usize::from(length)); + } + } + // The first slot of each length in `symbols`, then each symbol in its slot. + let mut next = [0_u16; MAX_BITS + 1]; + for length in 1..MAX_BITS { + next[length + 1] = next[length] + code.counts[length]; + } + for (symbol, &length) in (0_u16..).zip(lengths) { + // Each slot is below the number of lengths, so below 288. + if let Some(slot) = next.get_mut(usize::from(length)).filter(|_| length != 0) { + if let Some(entry) = code.symbols.get_mut(usize::from(*slot)) { + *entry = symbol; + } + *slot += 1; + } + } + code + } + + /// The next symbol from `input`, reading the code most significant bit first. + pub(super) fn decode(&self, input: &mut BitReader<'_>) -> Result { + // `code` is the bits read so far; `first` the first code of the current length and + // `index` its slot in `symbols`. + let (mut code, mut first, mut index) = (0_u32, 0_u32, 0_u32); + for &count in self.counts.iter().take(self.longest + 1).skip(1) { + code |= input.bits(1)?; + let count = u32::from(count); + if code < first + count { + let slot = usize::try_from(index + code - first).unwrap_or(MAX_SYMBOLS); + if let Some(&symbol) = self.symbols.get(slot) { + return Ok(symbol); + } + } + index += count; + first = (first + count) << 1; + code <<= 1; + } + let kind = InflateErrorKind::UnusedCode { alphabet: self.alphabet }; + Err(InflateError::new(kind, input.last_offset())) + } +} diff --git a/crates/lumen-image/src/inflate/output.rs b/crates/lumen-image/src/inflate/output.rs new file mode 100644 index 0000000..c153e35 --- /dev/null +++ b/crates/lumen-image/src/inflate/output.rs @@ -0,0 +1,81 @@ +//! This module owns the decoded bytes: appending literals, stored data and matches while +//! holding the caller's limit and the header's window. + +use super::bits::BitReader; +use super::error::{InflateError, InflateErrorKind}; + +/// The first capacity requested, before the output doubles towards its limit. +const FIRST_CAPACITY: usize = 4_096; + +/// The bytes decoded so far, never more than `limit`, in a buffer that never requests capacity +/// beyond `limit`. +pub(super) struct Output { + bytes: Vec, + limit: usize, + window: usize, +} + +impl Output { + pub(super) fn new(limit: usize, window: usize) -> Self { + Self { bytes: Vec::new(), limit, window } + } + + pub(super) fn bytes(&self) -> &[u8] { + &self.bytes + } + + pub(super) fn into_bytes(self) -> Vec { + self.bytes + } + + /// Makes room for `count` more bytes, refusing (at `offset`) if they pass the limit. + /// Capacity grows by doubling, capped at the limit. + fn reserve(&mut self, count: usize, offset: usize) -> Result<(), InflateError> { + let len = self.bytes.len(); + let needed = len + .checked_add(count) + .filter(|&n| n <= self.limit) + .ok_or(InflateError::new(InflateErrorKind::OutputLimit { limit: self.limit }, offset))?; + if needed > self.bytes.capacity() { + let target = self.bytes.capacity().saturating_mul(2).max(FIRST_CAPACITY).max(needed); + self.bytes.reserve_exact(target.min(self.limit) - len); + } + Ok(()) + } + + /// Appends one literal byte. + pub(super) fn literal(&mut self, byte: u8, offset: usize) -> Result<(), InflateError> { + self.reserve(1, offset)?; + self.bytes.push(byte); + Ok(()) + } + + /// Appends a stored block's `count` bytes from `input`, after checking the limit. + pub(super) fn stored(&mut self, input: &mut BitReader<'_>, count: usize) -> Result<(), InflateError> { + self.reserve(count, input.last_offset())?; + input.copy(count, &mut self.bytes) + } + + /// Appends the `length` bytes that start `distance` bytes back, which may overlap the bytes + /// being written (a distance below the length repeats them). + pub(super) fn copy_match(&mut self, distance: usize, length: usize, offset: usize) -> Result<(), InflateError> { + let available = self.bytes.len(); + if distance > available { + return Err(InflateError::new(InflateErrorKind::DistanceTooFar { distance, available }, offset)); + } + if distance > self.window { + let window = self.window; + return Err(InflateError::new(InflateErrorKind::DistanceBeyondWindow { distance, window }, offset)); + } + self.reserve(length, offset)?; + let mut left = length; + while left > 0 { + // Each piece is at most `distance` long, so it lies wholly in the bytes written. + let start = self.bytes.len() - distance; + let piece = left.min(distance); + self.bytes.extend_from_within(start..start + piece); + left -= piece; + } + Ok(()) + } +} diff --git a/crates/lumen-image/src/lib.rs b/crates/lumen-image/src/lib.rs new file mode 100644 index 0000000..1bce3d3 --- /dev/null +++ b/crates/lumen-image/src/lib.rs @@ -0,0 +1,37 @@ +//! Lumen's image decoders, written without a dependency and without floating point +//! ([ADR 0012](https://github.com/flyingrobots/lumen/blob/main/docs/adr/0012-image-decoding.md)). +//! +//! The crate is part of Lumen's deterministic core: the nondeterminism gates of ADR 0006 read it +//! as they read `lumen`. It holds, so far, one decoder: [`inflate_zlib`], which decompresses a +//! zlib stream (RFC 1950 framing over RFC 1951 deflate blocks) into at most a caller-given +//! number of bytes. [`inflate_zlib_chunks`] does the same for a stream split across several +//! slices, as a PNG file splits its image data across `IDAT` chunks. +//! +//! Every input is either decoded or refused with an [`InflateError`] that names the fault and +//! the byte offset where it was found; no input makes the decoder panic, read past its input or +//! allocate past the caller's limit. +//! +//! # Example +//! +//! ``` +//! use lumen_image::{inflate_zlib, InflateErrorKind, OutputLimit}; +//! +//! // The zlib stream of "abc" from a standard encoder, with its Adler-32 trailer. +//! let stream = [0x78, 0x9c, 0x4b, 0x4c, 0x4a, 0x06, 0x00, 0x02, 0x4d, 0x01, 0x27]; +//! assert_eq!(inflate_zlib(&stream, OutputLimit::new(3))?, b"abc"); +//! +//! let refused = inflate_zlib(&stream, OutputLimit::new(2)).unwrap_err(); +//! assert_eq!(refused.kind(), &InflateErrorKind::OutputLimit { limit: 2 }); +//! # Ok::<(), lumen_image::InflateError>(()) +//! ``` + +// No float in the crate: `clippy.toml` bans the float types; this catches arithmetic on a float +// whose type is only inferred (docs/adr/0006-nondeterminism-gate.md). +#![deny(clippy::float_arithmetic)] + +mod inflate; + +pub use inflate::{ + inflate_zlib, inflate_zlib_chunks, Alphabet, InflateError, InflateErrorKind, OutputLimit, + INFLATE_ID, +}; diff --git a/crates/lumen-image/tests/corpus/corpus.table b/crates/lumen-image/tests/corpus/corpus.table new file mode 100644 index 0000000..12ecae9 --- /dev/null +++ b/crates/lumen-image/tests/corpus/corpus.table @@ -0,0 +1,36 @@ +| `empty` | `empty.raw` | 0 | 8 | fixed | `aca503def43dc086a5aaa5c3d6f86bcbbc2aa6a80007ddea4a81bce2b376fceb` | +| `final_stored` | `final_stored.raw` | 3700 | 1545 | dynamic, stored x2 | `3f754f95da9af9c317f0bee0b281ad9d6142881e0f8b47607384c8a7217deeda` | +| `fixed_strategy` | `fixed_strategy.raw` | 20000 | 5342 | fixed | `fac2fb0410617d404c9b7eab84af1a525cf88ad43a74df88b97220e36743a7e3` | +| `huffman_only` | `huffman_only.raw` | 20000 | 10519 | dynamic x2 | `d123a9c8e521ae7aed9b48c6f2ba3e5854b9955f742d8d4576a2d4f7af630072` | +| `level_1` | `level_1.raw` | 40000 | 10675 | dynamic | `5a8117e6f2f251ac26f4a8cd27771093762c2a685999a3d1b90b8af0d29a196b` | +| `level_2` | `level_1.raw` | 40000 | 10443 | dynamic | `64d11c3ecaaf7fe4ac958f58d28f084d36b4e29c1d9a97308a9832ab5abe5895` | +| `level_3` | `level_1.raw` | 40000 | 9645 | dynamic | `e5894073b0cbd81d5644d68f5d9a174a5c058d1c0dac56ce2e62b9886f9693a2` | +| `level_4` | `level_1.raw` | 40000 | 9420 | dynamic | `90036a448da5fa72920258ab2005f4e7d55869e5bf5e976e1dd245b882d63ead` | +| `level_5` | `level_1.raw` | 40000 | 8845 | dynamic | `8dffe3ea1c5830c413ead6ed1c8c96147caef06cc992bf1495a32fe7b7812123` | +| `level_6` | `level_1.raw` | 40000 | 8305 | dynamic | `be5b0f39d4f9a425a4890fa5f00c971374b1899d06674aaf104b8b79886df464` | +| `level_7` | `level_1.raw` | 40000 | 8268 | dynamic | `ca630fe618e2e8be80bc15757efa1c7fc00d614f6d9cc858d14eddc7f0199a6b` | +| `level_8` | `level_1.raw` | 40000 | 8266 | dynamic | `1bc2fcd2291718dd17d372dbccc7b454c0952d6e15aaa8cb570c5b31e4b087d8` | +| `level_9` | `level_1.raw` | 40000 | 8266 | dynamic | `1bc2fcd2291718dd17d372dbccc7b454c0952d6e15aaa8cb570c5b31e4b087d8` | +| `max_distance` | `max_distance.raw` | 33026 | 34564 | fixed | `883db1f9acaa21e57e31c775409ed0708ea5bf324c50aff0b6fe4e162dc6e269` | +| `noise` | `noise.raw` | 20000 | 20016 | stored x2 | `88f701ce3c1883be61cca7fe562ada7b99953348b2fce3db8f199e9fec3ae6c3` | +| `one_byte` | `one_byte.raw` | 1 | 9 | fixed | `0c5d0951f7867ca2f99c7fd5bf7ae00e477e65c20847532870ae33a81236aeab` | +| `rle` | `rle.raw` | 20000 | 10487 | dynamic x2 | `c4a7c2dd2617eb5818c722be15cc52d4b1d3328b8bc523271511ae7ca6c62d36` | +| `run_258` | `run_258.raw` | 20000 | 43 | dynamic | `2fc2d8b54a08717a2f1a405b77309df0e29a4143cd88b58ad87e6bf0e43ca624` | +| `short_text` | `short_text.raw` | 120 | 93 | dynamic | `3c3fce012ec5f5a6b0f814c95224ccb0fad1bed3843f43bf0e34d67d0afbfb5c` | +| `small_window` | `small_window.raw` | 20000 | 6525 | dynamic | `2cdb285f2ccb2143e017386e00542f5e1c3580d65b3a5437b9130eee6483a7ef` | +| `stored_multi` | `stored_multi.raw` | 70000 | 70016 | stored x2 | `2083f5a7615a535748bfbac2361dfdbff4587619338bad2f0082d1b6d6ce3dde` | +| `stored_small` | `stored_small.raw` | 1000 | 1011 | stored | `599d3a4d201f8e3dc0f4d1492fd401ba6e697df0bf2bf8797dcd1f112113c7be` | +| `empty.raw` | 0 | `e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855` | +| `final_stored.raw` | 3700 | `bc205f959cf452b364d4afad548a59832998f573a70e61d6c6950183c47264e0` | +| `fixed_strategy.raw` | 20000 | `1f8de4ce447c2b7b0c3fe8dcc3764349a24d0207e83f161388dedc54ef187957` | +| `huffman_only.raw` | 20000 | `c05f67ad3b3b141f642b6d195282dab9dab765cda3a37db38b00d31a726eeba0` | +| `level_1.raw` | 40000 | `6047bce9add3acccc284fb321cc7b60adef48f30439d6bfa581c5839d6549a6a` | +| `max_distance.raw` | 33026 | `c28970b54518a6908e371100b0bbdb6fc2c301255396a76777e7f1eda07a3f73` | +| `noise.raw` | 20000 | `a23a346a52bea99a81333db1a0288acfd6fc88f6beff3c65c1a5a6c0214d2839` | +| `one_byte.raw` | 1 | `72dfcfb0c470ac255cde83fb8fe38de8a128188e03ea5ba5b2a93adbea1062fa` | +| `rle.raw` | 20000 | `3012c9aeab22d26227fc20f366b7a71324bcd19c1f09c5d968b67cb18dc81eb4` | +| `run_258.raw` | 20000 | `cc17faaad36649c4603dda4d8ff97cb149722af0bcac0746305a2134ad2d0b97` | +| `short_text.raw` | 120 | `237411b1c8c28eca0d8b49d562b85f52e823f76e7f00f0a24f083808536ddc01` | +| `small_window.raw` | 20000 | `b47be152c1e4509497bf3d262bbd9612385e829764117bfc51306df9aa3bd097` | +| `stored_multi.raw` | 70000 | `f8b58ae9a520ad84487fabaea5e87c6b9a63d34141e838981feb600078ab328f` | +| `stored_small.raw` | 1000 | `ee351d9f8ddd78318dafb7818b3d4c713a25bdd3b38080a31cfb1011b46629d8` | diff --git a/crates/lumen-image/tests/corpus/empty.raw b/crates/lumen-image/tests/corpus/empty.raw new file mode 100644 index 0000000..e69de29 diff --git a/crates/lumen-image/tests/corpus/empty.zlib b/crates/lumen-image/tests/corpus/empty.zlib new file mode 100644 index 0000000..f89cd1a Binary files /dev/null and b/crates/lumen-image/tests/corpus/empty.zlib differ diff --git a/crates/lumen-image/tests/corpus/final_stored.raw b/crates/lumen-image/tests/corpus/final_stored.raw new file mode 100644 index 0000000..a9deae1 --- /dev/null +++ b/crates/lumen-image/tests/corpus/final_stored.raw @@ -0,0 +1,50 @@ +bunny returns same texture point bytes texture +every returns +texture floating light lumen returns light on on point a falls floating +bunny while a light maps renders thread without point each falls same ray floating on every bytes same the bunny same +falls lumen each on on bunny maps every floating on floating renders bunny thread thread returns bunny each +every ray floating bunny the renders light light thread returns ray +while a lumen light point floating the without texture every returns without triangles each renders ray point integer and point integer renders without a on and a +on a point same platform bunny made on platform decoded light the decoded +renders decoded integer platform light a without maps on each platform +platform point triangles bytes made +maps made while returns falls and renders bytes the count bytes without of +thread of each lumen texture ray of point light same platform renders and thread platform thread same ray ray point floating +while without a bunny +triangles ray the point returns while each integer the integer point thread of integer bunny the the integer thread integer point every floating every +bytes ray count the a triangles every every each maps maps +made without of maps floating texture +each +returns lumen thread light bytes platform thread while a triangles the falls bunny thread every light each thread ray on every returns made bytes while made lumen on and count same decoded the thread +thread without platform triangles point count the bunny platform +ray bunny on returns bytes renders renders every of bunny thread every the point the lumen on on without triangles of platform renders made integer maps same light the texture each triangles lumen bunny ray +renders each maps made decoded texture thread +every a the each platform falls renders and texture on made while falls of a floating thread and made renders made +without and the a integer returns +renders and lumen count bytes on and +point every the the each texture decoded the renders each every bunny +integer while point +bunny the decoded on on and renders count on +renders platform of each floating thread ray while thread texture each without texture bunny +and +point same bytes triangles thread integer texture on falls maps renders triangles on thread of +lumen returns on same without made +and while renders returns bunny +made point thread decoded the every ray count maps every while without a renders thread falls of triangles ray texture ray +each integer platform of decoded +made made count made and ray triangles bytes a renders the same +and bunny triangles decoded returns point on the maps without and without decoded bytes floating made maps texture the light every bytes +texture +while on a platform platform on lumen integer lumen texture triangles lumen +triangles triangles renders point point the count bunny platform light floating without same floating on platform lumen triangles lumen and decoded point falls every decoded the integer triangles of floating bunny apoint of +the on without without +integer while bunny thread returns light the triangles bunny each lumen point light platform bunny triangles decoded and integer thread returns +on returns bytes without thread bunny every the platform bytes thread returns the returns light point of on made on bunny every the +on renders made on +returns a the +on bytes triangles lumen same and point maps integer the every while and returns bunny +point thread made same bunny +renders same ray lumen bytes light maps light renders ray +count the without integer floating bunny point light +bunny light count +renders made the of returns while maps count and decoded without and decoded integer integer every bytes same on r \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/final_stored.zlib b/crates/lumen-image/tests/corpus/final_stored.zlib new file mode 100644 index 0000000..22c1c29 Binary files /dev/null and b/crates/lumen-image/tests/corpus/final_stored.zlib differ diff --git a/crates/lumen-image/tests/corpus/fixed_strategy.raw b/crates/lumen-image/tests/corpus/fixed_strategy.raw new file mode 100644 index 0000000..31702d3 --- /dev/null +++ b/crates/lumen-image/tests/corpus/fixed_strategy.raw @@ -0,0 +1,272 @@ +of lumen a the floating renders +bytes integer maps made the texture integer triangles decoded decoded every platform ray bunny integer floating point triangles +triangles without renders returns triangles bunny integer light the integer and while thread returns and integer returns while made on count renders decoded while triangles light falls point thread the while renders decoded platform falls made triangles ray bunny the the texture triangles the returns on +light platform a on of light bytes returns made of same +returns and maps made +integer bytes of integer light while each without decoded lumen +ray made each floating triangles texture while bytes texture integer ray falls integer thread ray a integer light count each ray made made the integer texture ray on +point thread maps renders floating the +count same integer a +falls bytes triangles maps +point ray triangles renders point falls platform every returns count falls point triangles same texture every bunny while while without +bunny +triangles on count bytes +of triangles renders decoded thread +floating floating texture triangles bytes platform ray renders thread returns a platform without made every without ray without and bunny the bytes maps every point bunny same point +floating on same lumen texture triangles count platform same triangles lumen and the ray maps the the without count maps point the falls point floating texture falls same floating platform a falls point +ray thread count integer +of on point on without triangles and lumen returns without falls count +without bytes made same ray decoded bytes thread ray ray +the thread +point falls decoded the on +floating bunny the count thread ray bunny each same floating floating without lumen +and each thread texture and texture without while thread light bytes point falls light on count made while floating triangles without bytes falls platform point +lumen the a of lumen triangles and light same renders bytes count made returns made +without integer floating and returns platform integer the platform floating platform falls texture falls floating thread and on the made of on while each a falls bunny lumen +renders thread light and renders every bunny made +light thread floating +without floating maps decoded a platform on returns maps +floating +a triangles each point every on point every on the triangles lumen on light texture ray ray every the the +texture count on platform without +bunny bytes +maps platform the the of a a triangles lumen and lumen thread thread floating platform on +a decoded same on +and bunny count maps +maps point point +maps on platform +same integer same bytes point +a returns +every decoded every +returns texture floating +made point bunny floating falls the point bytes falls and bunny bytes light falls point on bytes while a on platform +point +light on renders every a on platform same each each point point each point point triangles point while on triangles decoded while of while made on triangles +the +point +and bunny of and of point triangles while on returns +bunny lumen +of while without the on each every returns falls falls bytes the on the every without ray without without on while bytes count count of platform returns while bytes and thread bunny of every the decoded same the returns same lumen a a count floating same texture same lumen platform renders without +texture integer count and decoded +point each light +of a while each texture +falls +on and same falls bunny the bytes of bytes every ray count floating and platform on +while light ray +count same every +decoded count decoded without count bytes floating bunny bunny on bytes the each decoded integer integer each count floating on renders floating count thread and texture without +lumen +triangles +bytes on the maps renders texture ray floating on platform lumen without point made same bunny bunny light made the while bunny each maps every floating renders texture integer on integer without platform same the every on platform +ray bunny same while of bunny count triangles while count lumen light on maps bytes integer renders +every +lumen texture every ray ray a integer count point every each renders triangles bytes a +thread on +thread platform renders +returns bunny floating on returns maps on point without +while lumen without bunny decoded integer while +platform decoded on on decoded returns on returns bytes each bunny same triangles without and +thread and bytes triangles count floating integer renders light platform on every of platform +integer returns triangles bytes count decoded triangles lumen maps point same same falls platform +while every a +bytes +every every falls on floating the count a while decoded maps triangles texture and bunny of floating and on +bunny texture texture bytes without returns maps on +bytes bunny lumen maps bunny bytes maps the a decoded +each without thread while the lumen bytes triangles point triangles +the the texture +bytes count platform +on texture texture same bytes decoded same light thread bunny triangles platform count +a made decoded without returns of each bunny thread thread lumen +same ray of each bunny bunny integer count triangles decoded texture without falls the bytes ray made +the renders same integer every integer same on same a same integer without on and bytes +and thread bytes count of maps falls made bunny texture a +decoded point bytes count ray texture +ray without triangles maps triangles without on ray integer while decoded lumen bytes without maps and bytes of ray thread thread while +ray maps and thread +a +same while platform of same made ray +every on integer integer lumen on the bytes texture thread made returns texture thread count decoded each triangles of decoded count without the point integer point bunny texture +count texture each bytes returns on same thread without triangles a renders the bunny ray renders point renders every and light renders without texture each without returns thread floating thread triangles without platform returns and thread bunny on a point floating bytes the count bytes renders renders maps ray platform point decoded a maps each triangles +same bytes bytes point point count +bunny each a texture triangles point light floating made of count +while without +bunny while bunny thread light the bunny every made bytes maps without maps renders texture renders the every and each a returns made lumen and while point thread maps ray maps decoded +bunny decoded falls each +decoded the ray same returns bytes +triangles a and same +returns the a of falls falls bunny decoded on decoded point bunny lumen thread integer triangles +thread bytes of lumen a maps returns triangles each decoded texture decoded made decoded made +while point each integer light texture falls platform count thread count platform returns of every ray each platform light maps same bunny a a decoded +without +a a triangles triangles the bunny platform renders +bytes made while floating lumen point each bytes while +falls count and on point on decoded while bytes falls lumen lumen and maps bytes every triangles returns a of platform +while maps +on lumen light renders +lumen a same thread maps thread while +bytes integer light renders triangles point while light renders made point every of while on bytes without on platform same count returns each while triangles the while +ray renders lumen the triangles light on triangles without falls on +every on ray count maps lumen renders triangles of light on point integer integer without platform each ray falls a without each floating lumen bunny and bytes ray texture count platform count each count each triangles each +a light every thread falls bunny light count platform falls ray light +point lumen maps and platform texture +thread and same and count count +and bytes +platform bytes triangles +of ray on light renders falls +and lumen floating +made floating lumen renders each on falls the decoded maps thread while falls triangles on on while and texture and count +maps count falls +integer texture on the on without floating count floating on on a count +light +on +renders the without each returns the same renders light each on +platform thread decoded platform decoded renders falls same light thread thread the of on every maps and lumen +renders point and light bytes point made the on +count the floating falls floating without made falls on of a decoded decoded count lumen light maps falls count light on bunny floating the renders texture floating every while +and a count triangles platform while the while a decoded without without integer platform triangles falls bytes each while +of light +a ray renders of every without on of point floating while platform without same made renders decoded thread made count thread count the bytes floating decoded falls without ray each platform +triangles texture while integer +triangles +falls every on while of bytes bytes point bytes thread floating the on texture +ray texture ray while on returns same decoded count on renders the while bunny +a floating renders same platform renders thread while +returns +lumen +without on thread lumen point a triangles made platform without made decoded and of +returns renders ray maps maps platform ray while integer returns renders each integer +while without maps lumen integer point bytes integer count returns ray without bunny the and platform lumen each renders same +point maps lumen each floating on lumen on on ray +without decoded +lumen every each bytes without integer while while ray +made floating returns of lumen on every the bunny integer bytes count integer made lumen returns bunny integer integer falls while returns +triangles triangles count returns point light integer texture +lumen integer thread point every without +platform and returns of +same count decoded same decoded +maps maps integer texture floating +without ray a count on +a platform same each same texture +falls ray texture platform light triangles platform floating every count floating thread decoded +each +thread without integer renders decoded platform on the on light of made point same renders on on maps light triangles bytes falls of every on thread +triangles lumen lumen while falls on without a of made without falls lumen +triangles platform lumen floating on while integer +on each lumen same made +on each the decoded and without without without every same while bytes platform of of each bunny of falls count light bunny each integer +light point bunny integer on decoded count on a made renders bunny count +bunny without integer on integer texture each texture of maps of without each triangles and every floating integer bunny thread maps ray each platform bytes +ray platform ray texture +bytes point renders point +lumen +decoded light a point maps every +triangles while light floating bunny triangles the count integer a count +triangles decoded the lumen each lumen ray integer of bunny the the +texture on maps made made without count falls falls platform and ray each on renders point bunny texture texture ray renders each returns the point lumen renders renders bunny triangles without the on maps platform on bytes every bunny count made falls lumen every and +bunny thread triangles +light floating count integer while on a triangles bytes count integer returns floating bytes maps integer platform lumen on maps texture light made integer made maps +falls lumen thread returns the bytes same point texture point bytes texture made floating falls on lumen of on texture the of platform bytes made of ray bytes a a returns the light made floating on platform triangles decoded platform on the the while maps on falls ray every bytes without lumen and triangles decoded on floating integer on maps count the returns while +each each triangles +bunny falls the renders bytes made +same lumen maps renders floating renders count maps bytes light bunny maps same platform and made on without on decoded falls on each point without a the +ray of light falls +of each the without +ray on returns made maps same thread returns triangles triangles on light point on same count and while decoded each while lumen count light returns +bytes texture lumen each while each point renders integer platform thread integer renders a each +floating light platform +integer triangles ray a on +bunny decoded +triangles a renders made point while decoded without the and same lumen a bytes on decoded platform +a made each renders point triangles renders light ray light +maps ray falls count decoded the +every light floating decoded count light decoded +while texture maps while same and triangles a platform the integer on without bytes maps on platform same triangles and returns same count lumen of +the triangles without the floating bunny maps and +texture maps lumen triangles +of lumen platform integer triangles platform returns integer maps a while while of thread thread light bytes thread the platform each maps bytes falls +bytes returns returns +made triangles bunny the +maps light triangles without platform lumen integer while lumen thread light same on integer on same triangles lumen made while returns bunny every integer floating the the thread ray bytes decoded count platform without falls every bunny lumen each a on +decoded returns decoded of floating on every same the without decoded renders each while point +without without integer maps texture made count each maps returns integer falls +made point renders texture on +falls bytes on without +lumen every and triangles floating +on platform renders returns and while bunny triangles on bunny decoded ray returns same integer ray point of every each light of triangles returns thread every bytes bunny on triangles every the texture +lumen on of the texture light platform made each bunny +same made light each every on while lumen without ray on bunny bytes of maps thread on while without renders a maps same bunny decoded falls bytes the on while integer the light the on on bytes the floating the the point lumen +on same lumen +while maps of the same +count bunny on each renders count +on same integer point and made thread integer platform bunny renders integer maps decoded count without while ray +light floating same maps floating without point bytes the +bunny without platform bytes of lumen falls same same returns bytes count bunny on count bunny ray integer a point decoded +made bunny and without of on falls a returns a point without returns triangles floating +platform returns renders each on made each the thread while bunny returns made +triangles while count +ray thread each integer returns lumen same bunny triangles thread point same every the falls each +on bunny and point floating lumen each and while decoded bytes maps count triangles on on while +every +maps +light made floating each without decoded +ray renders bytes thread falls same every made bytes bytes returns count on floating point +every every floating ray integer bunny the +every count of triangles triangles on made thread thread each every while made same same triangles made returns thread bunny falls the the on texture decoded triangles triangles each without texture the the renders floating same thread without integer integer renders count and bunny and without on of on ray bytes on returns bytes bytes count count on integer falls returns falls each ray point a each the bytes floating platform the without bytes and and bunny while without light platform light light decoded on count of floating light ray on on platform ray light on decoded +same bytes renders without bytes while the without +triangles decoded +point ray +integer texture count same renders ray same and floating returns while returns ray count falls floating same without +each renders triangles +light a every and count +platform every on +falls triangles integer the lumen without renders a ray the +same light bunny maps a and light a the +the the floating integer bytes returns while the on of of lumen without integer falls lumen without light decoded integer every falls decoded the bunny each made falls a bytes floating the +while on on +bunny of texture without renders thread returns of +bunny every bunny the each integer without of same the while falls on thread +every on returns floating a falls every +light without point platform on every the without light thread decoded bunny maps integer +bytes made on +the count point floating texture on the each on the and same integer +each returns on integer falls decoded texture made without triangles the without same lumen on +triangles the +and a bytes maps on the on the +a a without point while and light renders floating renders texture thread maps on each count count +decoded integer on a returns and same light a on +point a decoded thread of on texture the integer ray light lumen +on and without maps +same same ray each on of count returns same on renders ray point same on decoded on bytes the count triangles of falls bytes light floating platform +while decoded without every thread falls texture made bytes of platform renders returns +platform made ray bunny integer falls falls renders ray without falls falls the platform decoded each same renders triangles texture and texture bunny triangles bunny integer floating lumen maps without and texture count floating texture texture texture without same on while while renders point count triangles +texture falls count triangles without on renders +while on floating lumen platform on +point while light +count a triangles renders +count floating the light +renders light floating texture platform a made while on a the triangles decoded +falls ray same +and +while point returns decoded count +thread lumen maps bunny made bytes integer without while +decoded lumen maps thread renders the lumen lumen bunny same of every on returns on texture maps and maps a light count while returns renders on light point bytes thread each and renders light bytes light +a on made ray floating on on without lumen renders and floating of count and without light decoded maps the ray on light made falls maps ray integer integer point same returns the platform renders thread the the falls each +on and +texture on falls count of and without floating integer ray lumen every ray a each point on every decoded on the light each bytes renders triangles decoded without renders triangles integer light while ray made falls floating while while renders while falls integer and thread bunny floating and bunny count without the while every +a renders on floating bytes bytes texture renders falls light every returns renders texture of texture count floating ray while bunny point on a a ray light made decoded platform decoded and returns maps maps on returns bytes floating maps +returns same the a every +thread falls floating maps integer without integer same while platform lumen +bytes bytes on bunny lumen bunny on maps ray returns without decoded ray the ray on decoded same the thread floating without +and on returns of triangles without each maps ray the lumen triangles while lumen each bytes renders a point the ray decoded light on +every falls maps +the count the a platform texture on lumen a thread platform lumen triangles thread texture +on count same bunny the without +texture made without +same without falls thread thread without thread +every count each decoded count returns point bytes same without on every floating same thread light bytes integer same decoded maps made made the triangles integer same light ray maps point each light a thread maps without ray a and +on +same +bytes thread decoded on of the point every returns without and decoded platform light every falls a +on while platform decoded the texture bunny texture lumen the point count a on the ray and the texture triangles texture point bytes bytes count on decoded lumen integer floating on renders decoded ray returns returns falls light without on the of lumen every maps without while falls each count of thread made bytes floating every on same decoded floating on bytes ray made ray renders renders made decoded triangles point on floating while renders made made the without a the renders count bytes without triangles while +and tr \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/fixed_strategy.zlib b/crates/lumen-image/tests/corpus/fixed_strategy.zlib new file mode 100644 index 0000000..ebaa923 Binary files /dev/null and b/crates/lumen-image/tests/corpus/fixed_strategy.zlib differ diff --git a/crates/lumen-image/tests/corpus/hand_streams.py b/crates/lumen-image/tests/corpus/hand_streams.py new file mode 100644 index 0000000..a9ef683 --- /dev/null +++ b/crates/lumen-image/tests/corpus/hand_streams.py @@ -0,0 +1,27 @@ +import zlib, struct +class B: + def __init__(s): s.bits=[] + def put(s,v,n): s.bits += [(v>>i)&1 for i in range(n)] + def huff(s,c,n): s.bits += [(c>>i)&1 for i in range(n-1,-1,-1)] + def done(s): + b=s.bits+[0]*(-len(s.bits)%8) + print(''.join(map(str,s.bits)), len(s.bits)) + return bytes(sum(b[i+j]<I',zlib.adler32(raw)) +# fixed +b=B(); b.put(1,1); b.put(1,2); b.huff(0x30+97,8); b.huff(1,7); b.huff(0,5); b.huff(0,7) +f=wrap(b.done(),b'aaaa'); print(f.hex(), zlib.decompress(f)) +# dynamic +b=B(); b.put(1,1); b.put(2,2); b.put(0,5); b.put(0,5); b.put(14,4) +order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15] +cl={18:1,1:1} +for s in order[:18]: b.put(cl.get(s,0),3) +# code-length code: symbol 1 -> '0', symbol 18 -> '1' +b.huff(1,1); b.put(86,7) # 97 zeros +b.huff(0,1) # 'a' length 1 +b.huff(1,1); b.put(127,7) # 138 zeros +b.huff(1,1); b.put(9,7) # 20 zeros +b.huff(0,1) # 256 length 1 +b.huff(0,1) # distance 0 length 1 +b.huff(0,1); b.huff(0,1); b.huff(1,1) # a a EOB +d=wrap(b.done(),b'aa'); print(d.hex(), zlib.decompress(d)) diff --git a/crates/lumen-image/tests/corpus/huffman_only.raw b/crates/lumen-image/tests/corpus/huffman_only.raw new file mode 100644 index 0000000..1027ab2 --- /dev/null +++ b/crates/lumen-image/tests/corpus/huffman_only.raw @@ -0,0 +1,297 @@ +platform every point and the renders and +bunny same ray each lumen integer decoded bunny falls platform a +decoded +renders bunny triangles made thread bunny count point triangles +returns a while platform platform while +every same bunny count integer the every the returns each the +bunny point renders maps every without renders each texture triangles +point made platform a floating falls while texture +a triangles bunny falls on light platform integer returns floating texture maps lumen a texture bunny a +returns the platform bytes same while triangles without ray on and decoded falls bytes decoded falls renders each renders on integer integer count point and decoded +on while the bytes texture integer lumen returns maps decoded every bytes bunny every same falls lumen platform each floating platform decoded lumen made the bunny thread count +same bunny +a point made returns ray falls of every +ray decoded on on light triangles on point point a maps on a ray point a every thread +on floating a without ray of same ray decoded platform lumen same the triangles triangles the platform of texture ray +on of texture +same a triangles platform bytes platform without renders triangles while lumen the thread each the the on on returns returns count and decoded ray thread made the falls the returns and floating bunny on while returns texture +lumen maps falls the returns ray light on and on a count a bunny bunny +made +on lumen +light on without the while same point floating +count each bytes point platform falls integer triangles a decoded lumen a and each falls bytes of the while bytes +lumen decoded point texture on floating maps count every triangles platform texture a every texture point bytes +each bunny on +bunny light floating renders returns without floating the made bunny +decoded without on integer renders of +without +floating while count +the point texture triangles of bunny +count +of platform count triangles every lumen the of made and lumen the the returns light maps every count +without falls light and +ray light returns and +light made bytes made falls texture on bunny decoded platform +on returns ray a floating count maps on triangles renders maps a falls count returns thread light of +made without on +renders renders the and a the count point +light integer texture a triangles integer while falls lumen the a returns point the returns made the platform lumen integer bunny a point returns while of returns light floating same platform +a returns made light of without the integer triangles every texture every maps maps light ray a same on on triangles made renders thread on texture count +bytes platform ray +thread +triangles bytes count the maps floating thread +a every the bytes triangles +falls platform renders returns floating +floating falls +falls point every maps platform made falls of texture ray thread bunny bytes floating while on without count of made texture platform +point and bunny falls and without returns returns platform triangles falls point returns +on on bunny while and while light a point +made and without count texture on +thread falls every on the maps bunny floating each point every falls while the lumen of on the platform a same while falls point triangles +texture every made ray without count falls triangles point bytes of of lumen +integer on bunny ray of every falls +renders texture +integer point bytes +made texture same point point same light renders returns point and each +the lumen decoded returns ray +maps without triangles returns falls made made same the on renders falls light without and +maps while a falls point the returns a every made bytes without falls on every floating each decoded each the lumen of count +the returns count texture texture light without the the and without bytes each point ray bunny thread +the +made ray bytes on returns every +the made light +falls without point maps texture on maps +integer and count without floating bunny each +lumen on +light platform decoded the on bytes platform on on lumen falls +count and on falls thread on triangles triangles without bytes same a point point the every and platform ray a bunny the every a each on made thread on maps platform integer decoded integer count point count while decoded decoded bunny +on and renders returns without falls while decoded falls bunny +on without returns returns +returns +each and bytes every the bunny on on thread returns triangles maps made floating thread floating without bytes +triangles +point triangles floating and triangles and same count a the lumen the a and the the bunny same each and light on renders +each and decoded floating platform without bytes returns renders and point the bunny decoded triangles maps the lumen while platform the same on renders every +on +on bunny decoded thread and returns of floating +thread falls bytes each lumen on renders texture light bytes a the +renders bunny the same bytes +renders renders the platform floating platform and bytes falls made every bunny the +light lumen ray point ray made without returns integer renders count thread falls floating maps thread on count lumen while count renders +maps maps and platform maps triangles on returns lumen +on maps while without +a light every same each floating on ray the the triangles bytes +on falls platform falls returns every renders +and on without and thread light without the returns the thread without falls falls triangles bunny point while every the maps while +point decoded platform triangles the bytes bytes decoded without thread lumen returns falls without +texture platform on the triangles +on count falls triangles triangles of +the count count each maps the bunny while falls without floating point on decoded integer lumen on integer returns +thread integer a platform on light made of without bytes +on triangles while bunny the +same +same light while of the +on on triangles without +on without floating every integer renders falls of same renders decoded light lumen point ray on light the on floating every platform maps the while every and maps triangles thread +each floating +triangles of thread made lumen renders on platform lumen of and integer +bunny texture on and same maps +the platform texture integer decoded and made on lumen floating floating triangles made bunny maps falls triangles platform platform integer ray integer +ray a without same light point platform +bytes integer thread returns platform bunny count decoded of texture light of same lumen texture point and of count a renders the texture +thread same thread point light falls the point the renders thread renders count bunny same without light each same made floating triangles thread thread +same same returns every while a triangles point renders triangles on on and a decoded the a decoded while light and the maps count falls the on floating and point triangles returns bytes +same point on renders +returns each bytes bytes thread bytes made the +platform the the of without made same falls platform each count thread floating +bunny +returns decoded made thread +bytes of without and texture the decoded on triangles +the floating platform lumen bytes and triangles light every bunny ray every returns point bunny floating while on floating renders without lumen made ray light while every while texture while without without +the falls every falls platform count thread made the integer platform the count on bunny count while renders +the on returns without count thread bunny and count platform bunny maps platform the integer light thread platform and texture +on on and decoded a returns +platform renders integer point texture on point on without every and lumen light a falls thread falls the bytes each thread lumen bytes triangles a platform and same +a returns a ray returns every the same of every point returns lumen +on count made lumen floating while and falls ray +falls falls bytes made floating renders ray every made thread thread light without ray platform a a +the light thread integer same +on +decoded each light each +the maps maps decoded decoded +without the count every renders made integer floating each made bunny on ray the integer same of +lumen without ray integer on while made maps thread bunny lumen of light thread on integer on falls a renders light point of decoded without bunny integer thread without thread the +while every without +the each count decoded while the ray on +lumen thread maps returns point floating +while every integer point a lumen +falls platform +floating and integer lumen and ray floating of and a each maps of bunny returns ray integer falls bunny maps +thread platform platform on on the same the maps +while of the triangles on and platform on without of bunny a bunny same count bunny bytes +a texture made +triangles made point platform renders a integer a count floating bunny +count made count made floating the +a integer floating falls thread decoded of decoded lumen maps ray triangles same +texture the maps floating point the ray falls decoded maps of returns bunny while of made thread +point on maps on lumen integer platform made ray thread maps without while a while of ray of point a and on count triangles thread thread maps while texture count the renders maps every decoded +triangles without decoded +each the +platform the integer every floating +point without made texture lumen +made maps integer lumen on ray point the bunny point without of lumen bunny and maps texture point of decoded texture lumen platform triangles of on bytes without platform same light platform triangles without +the lumen made integer bunny of while ray every and and platform returns texture floating each the returns renders +point count count a returns returns point bunny and the integer triangles each on point every lumen a every floating falls +made bunny renders the count +without triangles returns while +on the count lumen returns platform on texture every returns platform bytes while platform integer bytes triangles made texture made made light without bytes and count ray count thread on every decoded same every +a and texture on point on a and while the made every count on bytes on texture ray while each the floating lumen count count maps and on same floating maps and maps texture the every floating made +same ray while thread each bunny ray on returns the each point decoded +thread bytes light ray same triangles bytes thread thread each renders a on while each the falls maps the on integer decoded while integer same a triangles on count floating same every integer integer renders +ray bunny the count +decoded renders while +and +decoded +every texture returns +made each on point bunny +while light +falls the a a bunny the made +renders renders lumen a platform decoded +bunny count and triangles renders lumen count same integer on the while lumen bytes +without made bytes +triangles platform on light made +point lumen +returns while on +thread decoded maps light triangles count floating count decoded made the platform same integer on count of on texture floating +the each same every count platform renders +each texture returns light returns texture returns maps a renders texture on same maps +on returns the a while +every each point the made integer +on on of floating while without count falls made thread +floating count same each each renders ray maps while the decoded the light light lumen without texture falls and renders +falls floating the decoded on count each made lumen texture every on texture falls decoded integer platform and each renders maps renders point each renders same texture returns platform count +on falls returns the a ray and without +light +integer on count each thread ray on decoded renders maps and ray made +bunny same the on integer made texture the renders light floating made floating and returns of point triangles platform light returns ray light without lumen bytes on made +texture ray and +floating count the +platform same renders decoded the the the +point every platform every lumen +ray texture count texture integer +integer texture bunny platform the returns maps +without bunny while decoded on triangles integer +maps +every a falls made while bunny count point every light falls renders maps platform on decoded without on point +made falls the of lumen count of bytes each +same of +point ray of on texture point renders on each and light without light integer count bytes renders thread ray integer count returns texture integer +maps lumen platform count integer and maps made triangles triangles on +the +point renders falls integer integer point same on decoded each and point the a maps bunny without on of without integer while every lumen light +platform made while made platform returns +every point maps decoded platform while bytes floating without of maps each a and bytes count same maps platform maps count bytes every of bytes lumen and count decoded thread each every +the while platform and lumen +on made texture floating the every thread +renders texture bytes thread platform on and floating bytes the ray +floating every texture thread returns on lumen same thread bytes made made maps on each +on triangles +light returns on +light integer +the thread triangles returns renders a count each a without platform on while every without +on maps point on falls integer while texture made +the while integer +maps thread floating maps +a floating on platform maps bytes bunny while and each decoded +a on thread falls texture the renders the point ray bunny made falls triangles bytes floating decoded thread of while without point same triangles the of on count same falls platform a lumen each point falls bunny +and bunny triangles thread on renders on +every the same on integer on renders on bunny on on decoded while maps texture +count +bytes made on count while of ray +each lumen the light texture the count texture of thread the each made without count ray thread texture thread on bytes and triangles count of without thread platform on maps thread on each the without point floating triangles same decoded the the +and texture triangles texture same a the triangles light made platform on of returns floating bytes point returns point light decoded bunny of the falls and light texture bytes decoded integer on returns thread without the bunny renders point integer same falls every count integer lumen falls lumen while +floating maps point same falls on platform on falls light light maps bunny while bytes decoded integer bytes made count the platform floating integer the bunny bytes thread falls point the made thread integer and count +lumen platform +triangles every every made ray same +texture renders on on bytes the of +bunny bunny point count of on triangles bunny decoded the floating a while platform decoded while made renders +each same on and each falls while a without bunny every maps while falls while +maps without a without point lumen of while lumen maps on renders platform bytes the on count bytes made decoded each the renders the floating platform made falls decoded the without while while bunny each maps decoded on returns platform ray without triangles the triangles the every without point while bunny count point without bunny without +made on +point without +returns same on maps lumen each made on the integer bytes returns of +bunny lumen texture triangles +on of bunny integer same falls count maps and and decoded on triangles the maps +count thread triangles falls falls without renders platform texture platform triangles renders returns thread without integer triangles on texture a a light of without floating texture made count lumen of without thread a texture every texture lumen triangles thread thread lumen point on returns platform +floating +falls +platform lumen +while platform every count without and maps made maps bunny decoded falls texture ray +integer triangles ray count without while ray +without bytes without returns +count lumen triangles the ray on renders texture of maps texture +same bytes bytes +every the the returns on integer lumen +bytes a ray ray bunny bytes on platform bytes count falls +same triangles the point triangles lumen count count on the +light texture floating +bunny bunny a floating maps falls on every decoded ray triangles +light bytes each platform without without count on on light same texture while floating renders same texture every made texture floating falls ray +on +count the made floating decoded each bunny the +falls bunny every platform triangles made point each on each of thread +without ray floating +on maps every lumen ray of on lumen maps floating light the +on +on maps +floating each texture made bytes of the thread floating the ray light bunny made light the a same floating triangles +renders while on floating bunny integer renders decoded returns triangles integer falls triangles on and on made the renders made renders floating of without point a on the made floating on made each integer returns the point +and the without the without and lumen platform +of thread a and integer integer every without floating +on every the made +count without the while the renders every and point and triangles light +integer maps and the on renders bunny returns point falls integer ray bytes without light +maps ray renders each lumen lumen platform point every triangles texture same bunny each the light +ray floating without point renders count platform lumen on integer falls bytes integer light returns without without bunny made +of decoded bunny texture lumen decoded falls every the +light renders on without while maps on platform renders triangles triangles same while every ray same and same without texture bytes without returns every renders +light bytes of and falls of each triangles +same while each platform +of +platform on thread of integer +count on and same +each the point falls made on decoded renders count renders +while each made texture renders +on of triangles triangles and platform without without while floating thread triangles falls +every lumen the thread renders every on triangles on light made light every floating +floating and light thread thread +triangles triangles a light bunny platform thread on of of lumen of without of bunny each on the every thread renders returns integer thread count triangles decoded ray on and a of +on triangles light ray the +and a the the count made made bunny platform every returns on ray every of lumen +every +lumen and point floating renders thread of while and every +returns thread decoded each the light falls +integer on every a same triangles lumen of floating bunny light ray on made platform without bytes lumen thread made light ray without ray falls falls the triangles floating every and +same lumen on the integer bunny made lumen the every without decoded the of light on light point maps of on +made same without bytes texture renders on thread +texture while bytes decoded of a each +the of on integer bunny maps same same platform on maps without floating on on of platform point light each count +on +platform same integer every maps the bunny the decoded bytes point every without ray falls +every and a on of every while a a bunny thread the falls the thread platform floating decoded same decoded +on ray floating floating +lumen lumen decoded the floating maps each on falls floating renders +each made renders +maps the same a on renders every renders +lumen every integer without thread bunny decoded of maps thread every without decoded renders +floating on every while the without maps on thread while a +returns texture same maps and platform texture integer the on each a each each falls same a same a and floating thread on made and without same +lumen while +integer falls each +the integer without bunny the of on ray ray on floating the decoded decoded on each +triangles and same decoded lumen lumen floating point on platform the decoded maps the platform platform triangles while of lumen decoded on a maps light platform bunny returns decoded on every light each and bytes without without while same returns platform thread +renders +bunny +made same point lumen made texture +platform returns decoded on +thread on thread each triangles on the thread texture renders r \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/huffman_only.zlib b/crates/lumen-image/tests/corpus/huffman_only.zlib new file mode 100644 index 0000000..1500114 --- /dev/null +++ b/crates/lumen-image/tests/corpus/huffman_only.zlib @@ -0,0 +1,11 @@ +xÁÑ‘¥0 À¢˜Ôôð€]%K”<>–ì¯ûqÓ•5Á¬OŽ,Ô‰b4Ö‚E;~;âòI”} �¾'#Ä›…Æ3~;âÃeî �›®¬ ;ÏllG1ká·#>¨†Åí\˜Öõ¢5üvć3wOŽTÃâv®£¨]±`xûpâqÓ•5ñ¸éÊšxûpüÇú°l¿ñáÌÂñfA�à?Öu¢¨]±@;;Ôyüvć'GÅh¬…iÏÿ±>¼C=·PŒÆZ �âŸvªaq;×ñäaZ#7]Y†ËÓ4âÆeî oNˆÚÅà·sá·#>\æ¾�w7]Y#Ä›…¢vÅÂåiqCüÓ.bÚ³à{2`ÿ´‹øíˆvµ+Ô‰ÇMWÖÄï–Mâíà հ¸� ïPÏ-”}È€ECã™� —¹/ü>q¡ñÌÆ†ËÜŠÑX ´³£�µ��âÍÂñfáÌ“#‹†Æ3Û‘�·'Ô‰ß'.ˆÚEŒo|OŠÚ Óž…Æ3ø�õá÷‰ ¿ñ�ÿX–Mâ2÷ß“�ÇMWÖí츨­áÌ:–Mâ·#¾ÃðäaZ#ŠÚ e.s_È üÇú޲�g66d >î.¨†Åí\ÈÀ“#„'G†iÏB ež!ø�õA½híÈÀåiqÃðõÜBÙ‡¼°leÏllxÜteMøž ,›„:¡·sA5,nç‚:ñ¸éÊšÈ âŸveß‘�¼ þi�e“0¨†Åí\xÜteMü>qáqÓ•5ñõÜB1kA5,nçÂÛ‡¾'ê„zÑhg‡:¡Nd E튅¢vÅ™;‹†Æ3Ê>¨­aZ#Ô‰ËÜÔ‰¢vÅ‚EÃåiqã·#>dàíÉ¢vÅ‚ø§]<|O¦= —¹/¨E튅²>î.dÀ¢!†3w†ßŽøðÛß1­ñÈ€ïÉ8|Ü]ÈÀ;Ôs êÄÛ‡Ë&ñäáò4�¸�3w´³ã÷‰ OŽ7]Y—¹/ŒoTÃâv.Ïllð=0X4ÐÎŽËÜ~Ÿ¸�Ô‰·'~Ÿ¸ß“�Æ3ž!ˆÚEdàò4�¸1íY8s‡À¬ªaq;7]YâŸvþc}ÿ´‹xr„ðûÄuÐΎߎø�qüvÄw.OÓˆÅh¬…¢vÅÂ;Ôs —§iÄ ubZ#~;â;Ïllx‡zn!#Ä›…b4ÖB^Ç;Ôs븜¹CÇ;Ôs —¹/ø¸»`ÑŽ²>î.µ+,Úáãî´Fü>qaZ#.s_ÿ´‹ÈÀoG|h<³±áqÓ•5� µ+Ê>.OÓˆgî¦= P ‹Û¹PŒÆZ˜ö,.s_8s‡PÔ®XP/Zƒ�» yÓñõÜBÆQŒÆZ(Fc-¨ uâÌ“#tø¸»0B¼Yÿ´‹0¨†Åí\!Þ,¼}8q™û‚ïÉ€:a(jW,<9BP'ŠÚ Ó¡NL{¦= >î.”}0,›D2 ·saZ#ŠÑX êEkÈ€ø§]Ä™;tü>qáqÓ•5QöêEk‡jXÜÎ…ß'.œ¹CP'¦= —§iÄ õ¢µÃÀ¬êÄïTÃâv®ã2÷…ÇMWÖD1k¡¨]±pyšFÜÇåiqã2÷u\æ¾ðä�ÿX¦= �›®¬‰i�¸Ì}!/ˆÚE”}P/ZÃoG|ø}âÂåiqãíÉ ¼C=·pæ!/Lk„ø§]Äã¦+kOŽ,~;âÃeî  ïPÏ-µ+ŠÚ �›®¬ Õ°¸� —¹/<9B(jW¬#øíˆoNX4¼}8áãî‚áÉ:¦5¢áê¹…3wâŸv‡zÑ.s_à?Ö‡ ¨Óž…ߎøpyšFÜ �OŽø�õá2÷…·'Ô ß“�¼�uâqÓ•5aX6‰·'.s_xr„ ·sâŸvüÇú0­eÞ¡ž[8s‡p™û‚jXÜÎ…'G¿O\È yÁ÷d#Ä›… üvć²y�ÿX.s_G1kAüÓ.#Ä›…'G¿O\Ç´FˆÚE,›Ä“#„'GË&áãîB1k¡¨]±ðäÁ¢�vöC�ð=h<³±¡¨]±PöÓž…w¨çTÃâv.µ+.s_˜Öˆi�X6 u"Åh¬…ËÜ|Ü]x‡znÁ¢Óž…·' —¹/<9BP'ŠÚ þc}˜Öˆß'.¼C=·p™ûBø�õáò4�¸A;;Ïll �ê„ïÉ@^8s‡u¢¨]±pæAüÓ.BüÓ.ÂÇÝ…w¨çÔ u¢áê¹…ß'.ÐÎŽ'Ge~;âƒzÑÚ¡ÎcZ#Ê>ü>q!EíŠþc}‡:1­>î®ã2÷…w¨çž!L{Ä?í"20íYÇñfÁ¢áÌÂ;Ôs —§iÄ�ߎø@;ûá{2�qø¸»ð¸éÊšh<³±A�ÈÀï7]YÈ€ïÉÀeîë8s‡`Ñ��ËÜÔ‹Ö�Õ°¸� ªaq;Þ¡ž[ø}â²Iž!<9BP'ø�õÁ¢áqÓ•5QöÁðÛÔ þc}0ÐÎŽ Lk„zÑ20íYxÜteMŒoÏll!Þ,œ¹Cxr„pæáíÉÆ3ÏlløíˆïÈ€EC1k¡¨]±ðõÜÂeî oN4žÙØp™ûÂoG|GÞ¡ž[(jW,µ+ÖQÔ®Xíì°hø}âÿ±>¨¿ñ!P/ZCQ»bA5,nç´gaZ#.OÓˆêEk¸Ô‹Öp™ûÂïhg‡ïÉ@ŠÑX âŸv>î.ü>qÁ Î£�µðÛÔ‰e“ø}â:ŠÑX Åh¬uâqÓ•5qyšFÜxÜteMX4ü>qá2÷…i�à?ևߎø ÎÃÇÝß“�²OŽÊ>LkÄ;Ôs E튅âÍB1káÌ‚zÑ.s_¸œx‡znwø�õaÙ$hgÇåiq#eÔ uB5,nçÂïב�ËÜ7]Y—¹/µ+ø�õ¡�µ‹† ¼C=·`Ñ ^´wÞ¡ž[P'ŠÚ ê„zÑÞ¡ž[¸Ì}á2÷Õ°¸� ¿ñáÉÂÛ‡üÇú NL{Þ>œÇ“#„Æ37]Yªaq;Ô‰ß'.ü>q¡ñÌÆ†w¨çÔ‹Öà{2PÔ®X¸Ì}áê¹uˆÚEî.¼}8‘Ôyd ªaq;Þ¡ž[GÞ¡ž[¸î.øž <9B(û�wÔ‰ \ž¦7ø�õáqÓ•51íYP'Þ>œà?Ö‹†iÏ‚jXÜÎõ¢µƒvv\ž¦÷¡·s!/¨­aZ#|OŠÑX xÜteMøž 䋆âÍ:~;âƒø§]D,–MbÚ³uâqÓ•5!þi1B¼Yh<³±Á¢aZ#2à{2pyšFܸq!/¼C=·`Ñ þi¡N4žÙØ�Õ°¸�ëP'.OÓˆ�›®¬ ß“�ß'.X4¨†Åí\ðqw�ÿX~;âCÙþc}(jW,<9Bøíˆ—§iÄ�·'2pyšFÜ(Fc-¼C=·à{20­e|Ü]xûp‚ÿXÞ>œÿ´‹xûpâê¹…w¨çÖ¡N\æ¾À¬—¹/¨Ë&‘ø�õáÉBQ»bÁ÷d8s‡0­¾'—§iÄ�·',.s_(ûŽËÜ.s_ø}â´F\ž¦7ŠÑX eø�õaZ#Ô‹Ö ^´wÞ¡ž[(ûð¸éÊš0Ø¡Nø¸» ^´†âͲÉ#ãh<³±�vvø¸»@;û¡NL{¦= �g664žÙØŽw¨çÔ‰3wüÇúPŒÆZ˜ÖˆâÍÂåiqƒvvLkÄoG|È@Ùub„x³°ly¾'ïPÏ-”}!Þ,dàíÉi�˜ö,¨­á·#>øž äwÔ‹Ö��âÍB.s_0£±|Ü]xr„�Ïllx‡zná·#>ŒoÔ‹ÖðõÜ‚zÑÔy¼}8Á¬ïPÏ­C� �gîÏllxûpB�(û�qøž ¨­aÚ³PÔ®Xxr„pyšFÜÇÛ‡üÇú0B¼Yxr„`ð=Çeî �›®¬y\ž¦7,Fˆ7 ¾' e.OÓˆyÁ¢Á@;;¦= yá·#>µ+Ê>Œo.s_øíˆÓžu¨­áqÓ•5ñ¸éÊšÈ@Ô‰e“P'¦=ëxûp"/¨ªaq;2`Ñð¸éÊšÈÀ;Ôs yá·#>~;âòIœ¹Cøíˆ¿O\‡AüÓ.bZã¡·saZ#ž!¨†Åí\X6yˆÚE¨Óž…ËÓ4âÆ“#u¢ìÃeî �g66L{òBQ»bá·#>¼}8‘¦5B½híxr„��iÏB|OFˆ7 �›®¬‰i�(û ^´†iÏÂ;Ôs oNÞ>œÈ eò“#ƒECÎÜ!¨†Åí\P/ZƒzѦ= oNˆÚEœ¹CP'ŠÑX Óžþc}h<³±ªaq;Þ¡ž[h<³±´³C�Çã¦+kB�!Þ,ðëÃåiqOŽÞ¡ž[˜ÖñO»ß“qLkÄ´ga„x³à{2��²OŽԉߎøðäáê¹…¼à{2ðÛ,¦= âŸvOŽòBã™� âŸv¾'�›®¬ Õ°¸� y!¿O\x‡znáqÓ•5±l>î.µ+7]Y¿O\xûpâqÓ•51B¼Yø}â‚jXÜÎ…i�ÿ´‹˜Öˆi�ðqwáê¹…ß'.X4œ¹C(ûpæA½h à?Ö‡Æ3–M‚ÿXßa°hÿ´‹ÈÀ“#„ ,Þ>œP'¦5‚ÿXÎÜ!dà÷‰ ÿ´‹(ûðöáíìP'.OÓˆ¾'gîÎÜ!L{,2°l—§iÄ�iÏ‚EôgAüÓ.B�à?Ö‡ËÓ4âÆ´ÆcÙ$Ê>¼}8¡^´ÚÙñÛÊ>d ¨]± NÐÎŽ'G�g6¶C½h ¿O\ðqw¡ìòI¨†Åí\ø}â‚zÑÔ‹Ö@;;ŠÑX † ¼}8A;;Ô‰Ëܦ= êDFˆ7 �g66¼}81B¼YX6 ƒjXÜÎ… œ¹C¸ŒoFˆ7 Åh¬u”}øíˆêÄ™;t4žÙØPŒÆZxûpíh<³±üÇú þiQÔ®XÇ´FÐÎŽ <9BøíˆïxûpÂÇÝu\æ¾ N ¿ñA�˜Öx£±ŠÑX ¾'†ÇMWÖDã™�íøíˆgî,TÃâv.£±|OÎÜ!,›Äñf!êÄÛ‡¾'¿O\Ç;Ôs ÓñûÄu¨†Åí\xÜteMdÀÇÝ…i�Ç“#ß“qµ+Þ>œÈ8Ô‹ÖÐxfcôgÁÇÝÕ°¸� gî.OÓˆgîÏll˜ÖuâqÓ•5±l#Ä›… œ¹CÈ ÿ´‹¸î.øž ¼C=· þiq™û‚EC1k—¹/\ž¦7Ô‰Æ32pæ�vvLk„ïÉ€ø§]ÿ±>d@üÓ.â2÷…Æ3Fˆ7 �›®¬ ‹ÚÙQŒÆZ˜ö,£±ž!ÐÎŽb4Ö²IˆÚEµ+7]YgîБ�ËÜŠÚ ê„¡ìƒEÃ;Ôsëðqw#Ä›… œ¹C �êEk(û��Æ3ŠÑX Óž‹†²Ó�ߎø°lêDFˆ7 Ó!þi¡N£±|Ü]¸î.ŒoÎÜ!ü>q¡�µ ^´†²#Ä›…3wEíŠñO»ˆâÍ:¦= ¾'�›®¬‰3w#Ä›‹†iÏ´F¨†Åí\P ‹Û¹�q¨óxr„PŒÆZ¸Ì}a„x³0B¼Yxr„°lh<³±�vvX4<9BP' Óž…ߎøðõÜBòÂ;Ôs #Ä›…·'ø�õÁ÷dÀÇÝuœø}âÂåiqãê¹…¼0íY �‹†ß'.œ¹CX6‰iÏÂã¦+kbÚ³pæá÷‰ üÇú�~Ÿ¸à{2`Ñpæ¡ñÌÆõ¢5ÐÎþc}‡:ñöáÄã¦+k¢Á÷d˜ÖñO»ˆËÓ4â†:Á¬êEkG1kAüÓ.â÷‰ êEkxÜteMdÀ¢áò4�¸ñûÄu¢ì;.OÓˆüÇú þi¡^´†¢vÅB|O–MB½h ¿O\˜Öˆi�˜ö,d€vö#ªaq;×áãîBQ»b!ãðqwa„x³uB½h ªaq;ŠÚ Åh¬Ù;ÚÙax‡znáqÓ•5‘�·'ø�õáê¹ud`Ú³ðä!—¹/ŒoÞ>œÿ´‹˜Öx¨oNŒoÖ1íYP/ZÃåiqcÚ³Ãåiq#�›®¬‰iÏÂï~;âÃÛ‡ ´³£ñÌÆv2 ^´†ËÜÄ?í"Ô‰b4Ö‚:ñä¡ìÃoG|˜ÖˆËÜTÃâv.ü>qáò4�¸ÑxfcƒzÑòÂÛ‡ïPÏ-<9BX6 Õ°¸� êD^ÈÀ™;„e“¸Ì}áqÓ•5að= �OŽ.s_øíˆï°høíˆªaq;Ô‹Ö��b4ÖBÆÁ¬êIJId`„x³��b4ÖB~;âC2ÐxfcÃÛ‡ÓžñO»xœ¹CÇï¦5"gîÞ>œÈ eßA;;|OÔ wÄ?í"Ô‰3wâŸvyA½h êíì˜Öˆw¨çÎÜ!”}P/Zƒø§]„zÑ2ðûċհ¸� gîòÂ;Ôs êEkxÜteMd`Ú³ ^´† ÐÎuâê¹…'G—§iÄ Õ°¸� Ë&Ñxfcƒ:¡ÎâAüÓ.B5,nç‚ø§]IJIÔ Õ°¸� >î.LkÄã¦+k"y¡¨]±pyšFÜø}â“#„¢vÅ“#wÏlløíˆyA�¸Ì}Á¢ÁÇÝñO»ˆß'.4žÙØ0B¼YÈ@Q»bA½h ïPÏ-¨¿ñ¡�µðäa„x³°l—¹/ðëÙ;„âÍ‚ïÉÀeî ¾'oÎãò4�¸1íYxr„°l—¹/dàqÓ•5‘�ËÜ|Ü]ðqwaÚ³ðÛÞ>œø}âBã™� #Ä›…ß'.LkÄ™;uâqÓ•5qyšFÜ!Þ,¨¿ñá÷‰ êEk¸Ì}áÉ‚:1­êEk!Þ,X4œ¹C‡ïÉÀã¦+kªaq;ø�õ�ÿX¦5¢ìòÉCüÓ.¢�µ�� ü>qA�Èëøíˆ¿ñáÉ™;„¼�Õ°¸� ¿ñ¡ñÌÆuâò4�¸axûpâqÓ•5ÑxfcÃÛ‡ÓQŒÆZíìX6‰ X4ÐÎŽËÜÞ>œ0¼C=·ðÛø�õaÚ³ðöáÄeî oÎcÚ³ðõÜ‚áê¹…'G¾'yáíà ߓ�iÏBŠÑX �›®¬‰ß'.¨8s‡ðûÄ…i�h<³±�vv¨Åh¬uâò4�¸ñ¸éÊš˜ÖˆËÜÏllP'Þ¡ž[xûpâíÉߎø@;;¦= �g66d ¨]±ð¸éÊš(ûðõÜ‚jXÜÎuB5,nç‚:Á¬ïPÏ-<9Bxûpâ·#>œ¹Cxr„ðõÜÂoG|x‡znÓ‘q<9Bx‡znE튅e“ÈÀ´gÁ÷d€vvLkDÔ‰âÍÂïŠÚ y¿ñÁ÷d@üÓ.B5,nç:2�~;âÃñfaÙ$.s_8s‡0íY°h°hh<³±!ªaq;Ô‰iÏ:ÎÜ!¨­A5,nçÂeî —¹/¼C=·PŒÆZxÜteMˆÚEœ¹Cx‡znÁ¢aÚ³0­Óž…ߎøÐxfcÃeî âŸveß1B¼YP ‹Û¹PöáÌÂ;Ôs oN”}Ç;Ôs ¿O\x‡zn¡¨]±Ž3w¾'ªaq;Ô‰²(Fc-ˆÚEä…iÏ‚ø§]<–Mâ÷‰ ¿O\ÿ±>¨êDQ»b!#ěߓqü>qÁPö¡ìÃoG|ø}âB7]Y¿O\8s‡p™û:–MB5,nç‚:ñäA5,nç‚ïÉÀ™;„3wPçáãî‚ø§]Äåiq¿ñá·#>.OÓˆÓž…ËÜ2À¬�g66”}P ‹Û¹w~Ÿ¸@;;7]YïPÏ-¼C=·pæ!ðqwaÙ$Ä?í"Þ>œ¸\ž¦÷‘�iÏÿoÇ–Ã ÿŤÆ1£GB×ëì·û�ùÁ΢#åC4„Ã΢cɳÑ,¤¦wØì£PƒWøŽ%Ͼš…ÔôÊ=PüW'‰%Jü¾âF4Ô j$EÑ,¤¦wÔ R>Øì£ð;î–(a³�B B°eÍBjzGåïÆ}%]™ï˜F„£YHMïø÷Ó‹�‰¤+sCy‡R‘¬“¾Q9Å»qcz±3ÑÄl£rŠwãF8ÄáX¢D "éÊÜX¢DÒ•¹Ñ,¤¦wDÃ;kÄ)<1½ G b‰ÍBjzG8–(A¹¦;É:é5ˆ'¦×%®¨A¼³FœB â�5âÄv�IµÈuEC�¤(âŠéÅÎÄôbg‚ÌﬧÐ,¤¦÷+üc~¨A,Q^w/¼³FœB âÓˆDÒ•¹Á?æqÅÓ âŠÊ)Þ�6û¨kz±3±äÙWÔ Â‘tenüŽû‡d�ô�'¦š˜mL/v&R>ü¾âÆ;kÄ)Øì£®%ÏFʇ¤+sƒrØYtØYt<&Õ"ž˜^àóCåïÆ�â¿:IlYÄ︠Ü5›}Ô•ò¡YHMïxg�8…'¦’®Ì�;Ž“j‘ vá˜^ìL41Ûø}Å�éÅ΄Í> +É:éﬧðÎq +¿ãþa‰òŠåJÅï¸(þ«“„�E‡ò¥¢‰Ùÿ˜jð²ÙG!éÊÜÇ;kÄ)¼c±äÙÇcR-r!éÊܨœâݸQ9Å»qcË"Þ1�àóCʇ-‹WlYÄ;kÄ)ÿÕIâ÷7ÞY#N!Y'}ƒÌIWæ¾löQø}Å�hW41ÛˆÊ=P9Å»q_[ñŽiåxLªE®+Úõ˜T‹\G�¤(¢az±3¯;ŽÂ!®Ø²xQî�ÄÓ MÌ6–(åJEÒ•¹qÇñBÒ•¹¯wL#(÷À%Šÿê$‘teî+ÑP9Å»q£rŠwㆸâ1©¹ðÎq +ﬧðŽiD³�šÞQ#)ŠÊ)Þ�MÌöÅ?æ;‹ŽD�¤(’®Ì þ1?„£rŠwãF8löQX¢„Í> +üc~hRÓûÕ,¤¦wˆ+löQ¨‘E�¤èU9Å»q£rŠwã†Àf…ßqÿð˜T‹\¨‘E8¢!ì,:¢á�5â¢áwÜ?Pî�pÔ øÇüP#)Ф+s#Y'}cz±3Q#)Š;Ž*§x7n(ïP*R>„C\!ˆv…£rŠwã†Í> +)jðWj5ˆ;Ž–(±D‰ßqÿð˜T‹\àóC²NúF8R>ð�ù!ì,úÅ?æwÙYtˆ+ž˜^hRÓ;’®Ì�IQDÃ;¦â +þ1¿+Y'}£FRÊ;” +Ê=Pƒ°ÙG¡‰Ù¾¦;áàóƒ`Ë"*§x7nØYtDC³�šÞñ;îlöQHùŽ%J<&Õ"ÞY#Ná÷7ì,:j$E±D ›}R>¼³FœBʇ&fMÌ6j•S¼7š…Ôôþ1?ˆëµevá¨AL/v&~ÇýÃ%ì,:jüc~xg�8åJE "löQ‡Í> +OL/,y6¢!üZ¢Ä–E¼³FœÂï+nÿÕI"éÊÜG�¤èUüW'‰wL#~_qCy‡R Ê=®D4„cz±3ñ;î–<[±e�IµÈ…p,y6ÞY#N¡YHMïG8¢á1©¹ðÄô‚Í> +”{àŽãu…_�IµÈ…-‹˜^ìLð�ùaɳQƒø÷5åJÅï+n<1½À?æ‡wÖˆSHùÐÄl_üc~W üc~xÇ4B ø÷5’¢¨A41Û¨AÔHŠâ1©¹Ð,¤¦w(ïP*¶,By‡R¯p¤|hRÓ;š…Ôô~ÙYtØYt(ïP*jÍBjzÇ’gƒr„£‰ÙF³�šÞ‘teî‹r,Q"éÊÜ×’g£±e‚p$]™üc~Hº2÷egÑÁ?æ‡éÅÎÄ;kÄ)ÔHŠâwÜ?(ïP*¢aɳQ#) +þ1?¼³Fœ‚ò¥"éÊÜW³�šÞþ1?¼cQƒxg�8…%ÏF8j$EñŽi„\É:éÅu’زˆ%φ¸â1©¹PüW'‰éÅÎD "”{@@¹(÷@³�-‹lY„@\Ñ,¤¦wÔHŠ"K”W¼³FœÂ–ÅË΢ãÓxM/v&š˜mPîqÕ ¦;ﬧð;îjÑŽ”)ÂÑ,¤¦wÔ ”w(Ê;”ŠpPîqUNñnÜWlY„ò¥Â΢Ã΢£YHMïxbz!�IµÈ…„ò¥bɳQƒxLªE.<&Õ"*§x7n¼c vÊ;”Šp–<6û(<&Õ"~ÇýC²Nú†ò¥"üc~°ÙG�rˆ+~_qã�5âÞY#NáÓˆ-‹HÖIßxLªE.ÔHŠ^IWæ¾~Çý»–(±eOL/ØYt,Q¢ø¯NòzLªE.$ë¤o(ïP*¯IQ„£FR”{ rŠwãF8j5’¢(þ«“DÒ•¹‘ÿS1ø­ \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/level_1.raw b/crates/lumen-image/tests/corpus/level_1.raw new file mode 100644 index 0000000..4a55119 --- /dev/null +++ b/crates/lumen-image/tests/corpus/level_1.raw @@ -0,0 +1,528 @@ +a point count every texture on the thread point of renders point made every point ray on texture bunny and the a each bunny floating the floating a renders platform platform bytes count bytes on every ray maps triangles integer maps count without same integer thread while renders count light without triangles made lumen every the same bytes platform ray on count thread floating count light decoded made bunny a falls falls lumen on the the platform integer maps returns +platform ray maps made light integer +texture floating +maps of and +triangles lumen decoded each thread light bunny falls +platform decoded a count +lumen +while bunny lumen made platform on falls and returns each and decoded platform ray returns decoded falls +the each on triangles on maps a on bunny every ray lumen maps while floating same triangles renders every floating +bytes falls and lumen bytes same +without bytes the bytes renders bunny +each the the every on on without the made bunny renders a count falls made a the without +floating same decoded maps every +same +ray returns integer point without ray the of bunny +returns every texture every thread ray the light platform texture +light integer the lumen on while a while ray of lumen made of platform integer of point count +integer count count bytes platform every of light +integer on count maps and floating integer and decoded same floating falls same without bytes platform ray ray returns each of lumen falls point triangles the platform made same bytes a made triangles the without and texture point point renders maps bunny triangles ray each thread on renders bytes the ray the of integer lumen platform platform every every integer +of ray +on +every count same the count renders triangles +ray texture made integer +count texture decoded the without +point without each without and lumen triangles floating while floating on triangles bytes of a the every lumen platform count triangles same on integer while +ray on maps returns the ray while every returns bunny a falls made on on count triangles +on and renders on without +renders a +lumen falls the thread on bytes on every lumen on platform the bunny count light and on while lumen falls +decoded same maps of on each +integer ray bunny bunny thread triangles a light texture maps floating platform point on count each renders +every without platform texture while while on texture on floating on +while count integer renders renders lumen on texture thread each +on triangles count maps +of lumen on point same bunny the returns renders thread integer made on decoded thread the made +ray same maps integer each falls +while same the integer thread and on +floating point on platform the point maps texture on on while platform +bunny triangles of light while bunny triangles each same every falls of floating same floating on +and bunny light floating count bytes platform triangles same ray on made maps every made while floating without and while on ray bunny falls every lumen same a on on integer count +bunny bytes bytes maps falls the count without without point triangles lumen each count of ray a on texture on light floating bytes without platform on on bytes falls of the and on +texture +thread of +made on lumen and each triangles made +made triangles without light falls made returns light on platform light point +the maps count same +bunny made a bytes the renders while of of thread falls without while every bunny made light +on integer without without lumen integer light and and the ray bytes integer count +renders the count every +triangles ray bytes floating +the triangles each renders a each each +a triangles returns lumen light integer on each decoded triangles platform integer count falls decoded light light of thread made thread light +point bytes triangles on lumen texture lumen count maps light renders floating same every falls every same floating bunny without the +integer light each +without renders every on decoded bytes point platform platform lumen of ray light while thread point renders every floating +and texture decoded while lumen the each thread and texture count thread texture triangles every light +texture the ray on a platform light count returns the bunny texture bytes decoded triangles while while the made returns integer made returns light decoded bunny platform on platform light returns point made count on +maps light of light triangles while bunny bunny integer every point +count and while ray platform returns floating +point bunny on floating count lumen made thread floating on integer light lumen and every decoded the of on decoded the and bytes the light falls triangles on the same texture thread of +triangles lumen renders without +thread a integer returns returns decoded +same falls platform lumen platform +count without on of decoded every ray texture ray returns same every triangles while +made point lumen ray thread on ray made decoded on +bunny triangles every on lumen the texture renders on +ray falls and lumen maps same each of returns ray ray decoded +maps count without point on on same without point the while +falls every each of texture platform lumen integer returns maps while thread thread +while ray floating bunny ray decoded the renders every ray each bytes each +on thread bunny of +integer returns +count thread without every and integer while bunny integer each triangles ray lumen falls same platform renders point made made falls of the +maps light and a triangles returns while on a decoded and while falls bunny triangles maps count and on platform maps the integer the +on on on same point returns ray platform bunny the ray decoded maps point light +lumen and returns point bytes decoded of a without integer on maps on a +decoded without same texture same bytes lumen made thread renders made light bytes triangles the and floating the ray the texture bunny lumen on every the and maps and light of ray the triangles +without while maps +texture returns while platform the platform floating each integer on and lumen returns the the a renders of point count and on and platform point texture integer bytes ray count maps every floating count the light platform +a decoded the same thread every renders integer texture +integer a decoded without every same and light and light returns floating integer texture platform while bytes of returns while same platform the each texture each and +texture point without each integer texture +ray integer every while count the each floating count and decoded thread while and light made a platform ray returns a same texture renders every lumen the floating thread same renders returns bunny and made the while made while floating the lumen point of light point each on thread decoded texture integer bytes a of maps point bytes on without each a lumen the texture renders of decoded triangles renders while texture and on each the floating renders texture platform point while and thread triangles on the point count same on renders and the returns integer +renders +the point platform lumen +light each thread count decoded integer made lumen light the floating maps bytes every integer and the same without same floating every on bytes ray +integer point point point platform each renders light the maps floating integer lumen point light decoded point of point bunny the of ray and count made +platform and falls +of count returns while the on lumen same renders made same bunny renders on without count each count made each floating on lumen falls of triangles bytes on thread point on integer lumen the lumen of the on triangles floating made renders and while every on while decoded ray +falls the each falls same while and bytes platform thread +floating maps while on while on every bytes integer returns without of lumen bytes returns every bunny +returns +falls bunny thread maps bytes renders while renders on every ray without light while decoded +on bunny falls without decoded lumen decoded thread bytes floating ray floating point light +of integer +count floating made +the bunny renders each maps every +bytes platform on renders ray renders +a light a light integer platform integer and every point +count +while a ray bunny while renders decoded integer the and returns every count same falls point platform +same without maps platform thread +bytes lumen count bytes the floating platform triangles point lumen while thread same same decoded bunny texture ray falls returns point a every of and the texture every thread on +platform the the count on decoded of a floating +triangles triangles count count thread count count decoded point ray texture made count and bytes point floating ray the on renders the +the ray on triangles light on floating triangles same on the texture while made and while falls falls same integer a count bytes the a bunny thread floating maps bytes integer platform returns light bunny count +on +bunny texture the decoded renders renders light maps a without the +returns without while integer every light decoded and on bunny falls lumen renders without maps integer on falls lumen the texture renders lumen thread +thread of of the maps a decoded lumen integer floating +each each triangles the without count thread of and renders floating +platform same triangles light of on falls every light floating and of count and +the same each every triangles without +on maps +on on made returns made lumen light light each bunny lumen and thread of every falls returns made while count floating a made texture lumen +lumen decoded while the triangles on falls floating the the the triangles of falls bunny thread each a a point integer each while platform the returns each made every integer ray made made platform texture platform integer ray made the same +on on on on renders bunny made the each maps +renders on integer a decoded falls floating and platform decoded bunny same light same count without on a on while ray +integer ray ray triangles thread each +a on without on texture same maps bunny every every the light triangles integer floating platform falls ray count renders each thread a the floating bytes floating and point while bunny maps triangles +decoded and lumen same while a floating the +floating +while decoded +and count a bunny the falls count bytes of +each and bytes point every ray while bunny texture a platform same integer floating maps bunny without on renders maps while renders triangles +every bytes same the renders texture on renders light same on light count point bunny a bunny without the without integer count without renders on maps maps and decoded lumen same the thread triangles light the of floating same renders while the lumen while and each +floating a on returns floating renders renders light while same on +and same thread same +integer count returns the decoded texture without without and every decoded bytes on of on the triangles count count the lumen bunny floating triangles on returns light light platform floating on +falls texture maps maps +returns point the bytes without falls decoded the without while returns platform and floating point renders without +bunny +thread ray made floating each made of ray the the decoded triangles falls bytes texture on +ray of triangles made +floating falls floating thread without returns bunny +point same floating light on thread and floating while thread made each bytes each same of falls every +floating light made every returns and and made without integer renders on light floating a integer +thread on floating triangles on light lumen +a thread the bytes on renders each a each maps on without each same platform on lumen made on each +every without integer of falls maps on maps on integer a lumen lumen thread every without texture made of triangles floating platform thread each without on floating returns integer floating maps every on bunny made bunny decoded the same each +thread floating bunny count +maps of integer triangles of the thread integer platform each floating while texture +of texture point of returns maps platform on a returns on thread the count renders ray +thread same falls on the the light bytes bunny bunny without decoded every same renders +lumen texture and texture bunny triangles the lumen +floating platform on the bunny floating bunny without count +the each bytes texture count maps +triangles +the bunny renders same ray returns returns while bunny renders count integer platform on +a decoded decoded of maps floating texture point decoded bunny on +made decoded thread and count returns triangles returns on light bytes texture made ray +integer count platform count and bunny every lumen +ray platform on of count lumen on +lumen made count light floating point a light integer decoded same bytes point without floating on texture ray falls +same +decoded the of returns same of texture bunny on the made of made point integer of on light without +floating count on the a while falls the thread +on thread the a maps floating each bunny bunny renders while triangles falls count +renders bunny platform renders light of thread decoded bytes triangles the while each the ray renders same maps each floating ray triangles texture point count floating texture on platform floating point a floating renders and every each lumen bunny each renders bunny maps returns light decoded made point made the lumen decoded lumen on +decoded while +integer thread renders floating ray light same of every falls +same thread thread falls point platform +light same renders integer without platform same bunny returns and +decoded light renders thread returns same integer maps ray while point while texture the point platform on maps +point every each bunny made texture of +while maps a each returns a bytes falls a bytes integer while every triangles falls a without ray +and returns each renders texture integer platform on decoded bunny on on made the platform each +while on the floating without count made the floating falls same made +light +triangles +bytes point and maps while on falls same point without same on floating decoded thread ray and made triangles platform maps the ray +lumen point on triangles and lumen each every on every of point renders +renders light on and integer light without count the each on bytes light the floating on +maps decoded made triangles a +while each integer the without falls falls floating falls the texture lumen triangles on count ray while ray a floating point count maps thread decoded of floating on made made floating integer on and light +lumen decoded a decoded bunny while lumen each on decoded on lumen triangles made on +every +texture lumen +bytes lumen made without same triangles falls bytes on light without +platform +texture the a decoded bunny thread and the triangles renders point +floating decoded falls ray while without renders the the ray light triangles decoded without without on each bunny renders without and lumen a bunny bytes decoded light same +bytes +thread count the maps integer each platform integer lumen texture while bytes floating made returns returns without +count renders falls bunny maps light every falls light each +bytes without renders bytes +triangles same without falls of +every of light on texture floating on while bytes and maps and on a bunny the returns texture +texture integer +falls of +every same on +without the and ray on ray texture lumen same floating texture texture +thread count bytes and the bunny on a integer bytes falls integer light the thread ray renders lumen the a triangles a +each lumen ray of each count on light platform while +renders the renders and returns bunny bytes bunny bunny while bunny decoded count +the lumen every bytes lumen on a thread point the platform bytes floating point bytes lumen without renders every returns platform integer maps on +bunny maps bytes texture returns falls and ray maps and texture falls +and of bunny while returns integer of and made light floating texture the +the thread same bunny decoded texture lumen lumen every floating and bunny made made on bytes made same decoded count bytes texture and triangles texture the each count maps falls texture each renders renders maps lumen returns thread lumen bytes thread on lumen falls on and +platform thread thread without point falls triangles while falls on point same returns on bunny the without triangles the triangles point the same on texture lumen +of the thread count returns light integer ray light floating the bunny renders while ray returns on of +on the made falls integer thread the triangles on thread without maps floating without ray falls lumen the made point ray ray on decoded same renders bytes the +floating count platform bytes lumen the bytes decoded floating falls point platform falls same triangles floating each bunny integer made light bytes bunny thread while on point of +floating while the texture returns the texture decoded bytes floating count falls triangles triangles ray a made a maps floating returns and +and bunny point the count of while ray +lumen texture each count each made ray integer while lumen decoded every bytes on texture bytes bunny of and triangles integer thread thread bytes count bunny texture platform platform decoded thread lumen without renders thread triangles each thread ray thread renders every ray ray decoded maps without the same texture +every decoded bytes light each of on returns a without the +bytes on while +point thread texture triangles decoded bunny while decoded lumen each on while and point point same thread the texture lumen a bytes without on maps +while triangles triangles without each falls point made count bytes +and +returns point falls made integer count returns renders platform made renders on count bytes decoded on a bunny made thread on each thread without triangles maps decoded light each bytes point renders integer and light decoded same the on and bytes count texture while +each each bytes texture +floating on lumen on a same falls made texture maps lumen point without integer texture of on bytes +of +light on while falls and and the of count same bunny the +thread light on each integer falls made count bunny renders point +on while light on ray on point the +without point and on and triangles lumen same on triangles bunny +texture texture point bytes same while on without texture point on and bunny and returns while every while point +a floating the without texture without +integer while +integer of light made of the +the while +the of integer decoded lumen +floating +every renders on returns returns decoded ray triangles bytes on platform platform triangles returns light floating the integer floating light returns made the renders same maps made texture a platform count without thread without bytes lumen +each a maps triangles light triangles light on +on +lumen triangles returns on lumen and +lumen lumen a +returns maps +the of ray ray +texture count bytes and ray the +light each decoded lumen +every point integer +the +a floating maps floating +point count the the falls of triangles the and +platform each bytes light light on maps a the on the the every count texture and +each on floating ray on decoded count made a while triangles falls and +without thread falls the same and maps and +bunny on on +platform bytes and bytes light light while bunny +triangles a without without on of platform +thread without renders triangles thread floating of same +lumen returns every same every +thread bytes of of each same floating each a triangles texture renders thread floating the returns returns light the while each platform the decoded bunny ray point of while platform without count each without maps triangles integer and falls while platform a bytes floating decoded platform ray while platform returns bunny each on the lumen made +decoded the falls decoded floating integer falls decoded each the maps lumen of bunny every decoded ray returns integer +and while same thread the a thread while returns bunny light platform the platform made floating bytes renders returns of on bunny on made integer bunny thread count light of falls and maps renders +returns a +renders every +the made decoded without light falls thread a ray texture falls point bunny maps and decoded each count point each on integer the integer a bytes bunny each each decoded returns maps a falls without point on ray the on every platform ray and decoded texture renders +decoded renders count renders decoded lumen bytes on without falls light the falls lumen the renders bunny bytes +floating renders every renders floating renders the +integer ray bunny while same lumen falls decoded triangles each platform of +falls on integer of while +of lumen texture each decoded integer each and renders a bunny on on returns each bunny bytes on same without every +the +same point decoded returns returns bytes point decoded count same of the +texture texture without same the returns a ray count integer +ray texture renders bunny decoded a count floating decoded light every a light ray +ray platform light bytes +ray on the the count floating of decoded maps ray renders of decoded bytes texture decoded the ray while same while +on and returns triangles decoded ray on bunny made thread light of texture platform integer of bunny count on same point returns +returns returns decoded lumen thread thread light count a same decoded without +the light point count integer bunny +of while of the +ray triangles the while a floating made bunny ray ray of renders renders floating count without maps light +triangles lumen triangles bunny platform integer on +falls the light point renders each returns and falls made +returns a texture platform renders renders on the lumen renders +lumen floating count same triangles without falls light thread point returns floating bunny same on floating without triangles without falls triangles the texture ray renders on bunny platform falls ray while +the a while without ray ray integer bunny ray count lumen a and +each returns thread falls without bytes while a renders returns on point returns maps on returns renders floating texture +on integer made returns on +maps made light lumen returns a without made +made maps while triangles while floating maps decoded of lumen lumen falls point count made decoded same +returns integer +of count while falls returns renders bunny bunny on +every triangles each platform lumen returns texture point bunny ray on the platform without falls integer lumen and integer platform returns falls made on ray a decoded the decoded platform lumen a platform and returns on made texture count of point maps texture count ray platform platform falls +every and on each light platform made point made lumen ray every falls without bytes maps +lumen ray and the of lumen without light triangles a floating a each +platform on +renders without platform each renders of each while each count same a a bytes without triangles lumen bytes count the of count the light returns same ray thread lumen made and +on renders the light lumen lumen light bunny +count a falls while on ray bytes maps floating integer maps lumen without on +renders triangles on while +while each ray light on integer lumen thread integer thread and +point while triangles texture on count platform and the renders +without bunny light the ray and a every bytes falls without the +and the triangles thread made of of light texture on light made ray on each renders of texture while each same renders integer +point triangles each renders platform on floating floating made on platform decoded the +lumen the point each renders falls of bunny without bunny bunny count and platform and made falls +a falls renders maps integer on integer falls every on same point a ray ray while light +each a and made renders and light same triangles while +a each +maps on count bunny decoded each count lumen decoded without returns integer decoded a floating of on platform each maps the on lumen decoded platform triangles every lumen made thread returns maps floating +thread texture falls point count point the the made platform and lumen while bunny +falls of each decoded platform returns a bunny the every and falls made bunny renders bytes platform same +of point falls bunny renders count +platform +ray texture decoded renders +on and same maps while bytes a texture light the +decoded point renders +every texture count on +integer renders on triangles on and each on bunny and falls and +made renders ray decoded and platform integer of decoded count without ray every triangles falls maps every light integer each bytes integer ray texture same thread same without the light every each +falls texture platform made renders each +falls falls count without maps floating same made thread a on thread +bunny renders decoded light returns count falls a +made decoded thread bytes a light falls thread without of bytes decoded bytes and on a integer triangles +made returns maps thread decoded bunny ray +floating triangles +integer point +ray without +ray made the without integer light point falls +the while made made the maps point returns light point each decoded triangles the +integer falls every while made falls and on on returns on made bytes ray on bytes texture on +of maps maps a texture returns a on made the integer of and floating on +decoded texture +integer falls maps on of +the renders light the +on returns maps each +light falls floating point ray +falls platform every made same platform while the same bytes every renders returns platform same on without maps the while every integer made +every on without without renders a made platform lumen triangles +of on count light light light on floating count while floating decoded texture same ray point falls bytes the of triangles +maps renders point +platform same bunny maps every maps +without thread and triangles platform thread triangles every point thread +point a light thread platform point made texture without on on same +triangles of a count texture while a without the each falls lumen the point on falls triangles +on lumen made made +without integer a the point ray while falls the thread floating bunny +triangles count floating a lumen +renders a made while while triangles falls bunny on while count light +without platform same a of falls bytes on every the a falls platform ray on of same each lumen thread ray every of point made bytes decoded +platform light floating a point a renders on without same a lumen renders a on returns without without while while and a count of each each on the +point integer +the returns while a platform +bunny while a ray made light of the while and same integer returns of +and the bunny thread light floating bytes thread point platform same lumen thread maps made thread +falls count each every lumen lumen of a a +same lumen light while returns on bytes while on +light renders the on falls of light the triangles ray returns floating ray +texture point same count +floating thread lumen ray platform platform on renders triangles on bunny texture of the renders renders point made made +count without point +a on and and made ray ray floating and ray point renders a integer +without a lumen bunny without integer of made point the count of on floating texture triangles made point the decoded bunny lumen renders +and +integer platform +texture the triangles each every every triangles on each every floating integer every platform thread point decoded made without renders decoded maps on decoded platform and of bunny +thread decoded ray triangles and triangles and every +the floating on the point platform floating point the and texture decoded the count count ray light light decoded count the +point point integer of +floating +the thread returns without returns on on while and a ray each integer of +on count integer the without texture each lumen point +floating bunny +bunny +count falls bunny +ray every +lumen falls without maps without texture count light and light on +each bunny lumen floating maps while the maps renders decoded lumen texture same renders renders falls bunny lumen same +thread ray the maps thread a the light returns without thread +made of floating renders bunny maps falls +renders on each count of returns made of +count of the returns on made triangles and count floating thread maps on point renders maps texture and returns and maps on the bytes +thread light floating triangles maps on same and point ray floating floating maps each on returns while of made returns the falls falls returns light floating light lumen +on of decoded integer ray and while platform +every platform the bytes and bunny same of bunny renders point and while integer every on bytes falls +renders while floating light same bytes on the count the made of decoded without without every made a bunny light falls bunny texture decoded on count +made triangles +and point of point light every on of every maps count bytes and floating bunny thread same on renders platform +texture the lumen ray while made bytes made while a falls made on while ray same texture +returns a the falls on +while the while maps of platform floating made each floating platform maps on each +made a integer on thread point made lumen count without +of ray made without maps renders count bytes +maps falls lumen and falls integer point bytes bunny the light bytes light without maps ray a +and platform floating while light +bunny made same on triangles without renders triangles point each and triangles decoded on count each point integer decoded triangles texture renders thread thread returns while count floating on decoded +ray without same bytes +lumen bunny a bytes floating made a on integer while and light made +while triangles on +triangles platform count each and same maps integer thread on +ray thread bunny texture floating +every +integer the point ray maps ray falls while count bunny returns thread maps count same light platform ray integer texture returns on every on triangles integer the triangles on ray count a falls bunny point each on a maps the +on count platform while bunny triangles renders on +floating +lumen while every floating point while count +while floating triangles while decoded bytes bunny triangles on the on thread platform +on while light a bunny platform falls the every bunny returns triangles bytes falls point the the every without returns renders integer on each without and on +bunny of platform triangles returns integer every and thread the without integer texture and +of lumen +texture on while and a light renders the light ray without the platform renders ray +bunny count count returns triangles each while while every each +bunny floating floating while renders on integer same without of floating +maps maps the lumen count falls triangles floating of +without without maps falls each triangles ray count a count platform +integer each point without lumen made +returns while without light +maps integer +point returns each texture lumen the lumen floating triangles triangles on floating decoded bytes bunny point integer ray of decoded floating +lumen made thread floating floating light count while of the integer made lumen of same returns made point the ray +without lumen bunny renders each on on decoded on each +made bytes falls and point and every count decoded +count ray every of integer renders bytes thread +returns same maps made and +triangles on on bunny same bytes same the same on and the every each point the while decoded a integer on bytes light and floating renders bunny thread lumen integer +each and the and falls decoded decoded lumen every made lumen floating floating falls falls decoded point +point thread a floating while the the triangles made and the the count of on same +light triangles bytes maps point the and and on point on on each of of thread on on renders without lumen renders +bunny each triangles floating light and without count texture +while lumen same on bunny a of each each bunny on falls bunny texture platform of maps count falls ray on on decoded returns triangles on each the on a without count falls same +every bunny decoded texture count falls triangles the falls while of +a while point maps returns +falls made every on +the and +and +of lumen each +on the bunny maps a maps maps while lumen falls a bunny +point floating the +and ray bunny platform without same maps on integer bunny a of integer falls lumen lumen the point every +of floating integer and on light triangles lumen integer falls count decoded decoded bytes every on while count and platform integer lumen +bytes count decoded of of the falls texture +ray texture on +count decoded lumen on every a a while on returns each floating while +without same every texture each every decoded same on same +on floating bunny lumen renders integer while light light bunny returns falls on texture platform and maps made bunny the returns the ray without +without decoded on without the floating light integer count texture bytes bytes +every floating of falls light lumen made +ray on on a same count same the without and ray point without returns ray decoded every without and triangles integer integer returns decoded on same same thread light +a the without the +bunny +renders ray point returns the triangles renders +lumen while +bytes renders +bunny count maps +bytes without renders +without the made same +maps ray platform the bunny renders ray on without texture the floating and texture +ray +light made made each lumen ray each the texture of a the count and triangles floating without maps the floating on thread bytes without on lumen a light of ray maps falls maps every while renders every texture the floating maps triangles made point the triangles while each and made each and on ray on without while floating while and the decoded a returns point count platform texture point light while triangles +renders texture and without and same on platform thread bunny lumen platform falls and falls platform +renders decoded bytes floating returns each integer integer +integer +ray on thread integer integer the same ray the +bytes point maps lumen while count and bunny bunny returns and decoded light a bytes bytes triangles bytes the +lumen falls without while ray +every of platform the light made on triangles +maps falls while bytes of each bytes triangles floating a light while while platform point renders each each light while platform every same of on maps a on same light the lumen decoded on renders floating ray point bunny same integer the thread falls triangles triangles while ray lumen a the thread the renders point the on without thread platform the returns +texture same bunny decoded triangles on floating +of +renders bytes light +point ray made each decoded returns count bunny texture texture without the each returns and +integer texture renders renders +light every point each the made decoded every on point maps of bunny +light the lumen point falls without each on on renders bunny point light falls lumen decoded and falls every on same maps each on and thread every floating on count ray each light floating without made bunny the bytes on light ray on point decoded of returns point light same of and ray +a the each point same light each bunny lumen falls on each floating +returns bunny +decoded and maps falls texture on point point made without renders bytes while falls and ray every a ray light bunny lumen bytes every on made while falls a of without every while floating +lumen texture point on the bytes the every +bytes lumen +point triangles platform while +the while +every a light each decoded point of same point the same while maps floating on texture count of on decoded integer same +maps the platform renders +bunny each count platform every decoded decoded thread texture light texture and platform made integer of on every the point renders and +lumen bytes while ray +and platform bunny and integer decoded triangles thread texture texture and on the lumen the +integer same bunny light texture bytes bytes falls ray decoded +ray of platform the on the falls floating same returns bytes lumen and falls the light every falls and the count count triangles thread +and of falls on maps maps floating of ray without the integer platform integer maps +bunny point and bunny and on lumen bunny floating count lumen platform on bytes made without the maps triangles without of texture on same of +lumen and count lumen falls lumen light maps texture each ray on count count of made without the triangles without platform lumen texture same while the of count ray without integer and on triangles a same +texture the decoded point and lumen decoded same +same thread the triangles decoded point every returns made while +on platform maps returns maps +count lumen thread while renders thread the and each decoded texture on falls platform thread falls on same the platform light on texture lumen while without the thread triangles falls texture and platform the falls maps texture lumen texture light floating thread bunny returns decoded a on while and texture thread on count decoded lumen decoded while floating renders the same thread floating a and bytes light the each without returns of without bunny falls point decoded decoded point triangles without maps texture +same made on ray the while renders point renders triangles of thread and light the maps made +same on on without platform light platform and maps on triangles made a triangles ray lumen ray same without bytes falls every on triangles every the maps integer of made same triangles decoded point maps while maps point +same floating lumen bunny each maps returns every ray same thread light integer maps on maps maps each while count thread and bunny point light on platform point bytes +falls renders the and maps +maps same and integer +ray made texture triangles integer integer lumen returns lumen thread integer +bytes bytes point made every floating a falls maps +platform light each platform every bunny without point renders triangles the the maps without light bunny every +triangles light decoded each and on integer a a thread the decoded of +thread renders +each returns +returns the each lumen made point decoded each count while +made returns point returns the the platform count renders count decoded a platform a on lumen point and count renders bytes returns the a without every made platform platform thread every every and made returns a triangles a on every and each and of light of ray falls renders on texture renders +count bytes decoded +each on triangles triangles renders falls maps count integer bytes platform ray returns a every integer bytes light of made on every of made triangles integer while triangles point texture while triangles count texture bunny same made made the the on without on lumen returns light +falls returns floating the and ray texture on triangles platform bytes without without thread decoded decoded while platform ray made the same maps ray every while thread +decoded and +while +floating the while every returns on of a every platform of bytes renders +bytes on without light thread +maps same same falls returns a of ray the maps the every renders floating the light of +the ray of on bunny the falls +thread thread and +the a bytes without lumen lumen thread ray same on +of bytes made count lumen point triangles of +falls on count bunny made +returns same bytes of the of bytes +the the texture decoded same on on thread on of the without texture integer light decoded +on falls decoded returns falls the integer falls light triangles renders of texture a the point +falls maps same without every light ray +same bytes a while a on +floating the and made on lumen a of +on returns falls floating bunny on while triangles made on without bytes and a lumen lumen integer point +without on ray +and lumen triangles without renders decoded renders the platform platform the and bytes while on bunny triangles +texture lumen each returns +of while count decoded each without without maps the integer made light floating point light without +on bytes returns same ray same +every +falls returns same bytes on on triangles ray on falls the ray light every falls the light triangles thread +made same decoded bunny +returns ray every integer +decoded returns texture count triangles made +lumen and count without the on bunny point ray the triangles each +bunny lumen thread triangles on maps same falls bytes while on and every on r \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/level_1.zlib b/crates/lumen-image/tests/corpus/level_1.zlib new file mode 100644 index 0000000..54aff0b Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_1.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_2.zlib b/crates/lumen-image/tests/corpus/level_2.zlib new file mode 100644 index 0000000..3057cf7 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_2.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_3.zlib b/crates/lumen-image/tests/corpus/level_3.zlib new file mode 100644 index 0000000..f5d2e71 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_3.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_4.zlib b/crates/lumen-image/tests/corpus/level_4.zlib new file mode 100644 index 0000000..6dd7704 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_4.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_5.zlib b/crates/lumen-image/tests/corpus/level_5.zlib new file mode 100644 index 0000000..7f2f8c5 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_5.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_6.zlib b/crates/lumen-image/tests/corpus/level_6.zlib new file mode 100644 index 0000000..c276ec6 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_6.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_7.zlib b/crates/lumen-image/tests/corpus/level_7.zlib new file mode 100644 index 0000000..daac928 Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_7.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_8.zlib b/crates/lumen-image/tests/corpus/level_8.zlib new file mode 100644 index 0000000..3f7084a Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_8.zlib differ diff --git a/crates/lumen-image/tests/corpus/level_9.zlib b/crates/lumen-image/tests/corpus/level_9.zlib new file mode 100644 index 0000000..3f7084a Binary files /dev/null and b/crates/lumen-image/tests/corpus/level_9.zlib differ diff --git a/crates/lumen-image/tests/corpus/make_corpus.py b/crates/lumen-image/tests/corpus/make_corpus.py new file mode 100644 index 0000000..8e76490 --- /dev/null +++ b/crates/lumen-image/tests/corpus/make_corpus.py @@ -0,0 +1,236 @@ +"""Builds the zlib corpus of lumen-image's inflate tests, outside the repository's build. + +Run as `python3 -I make_corpus.py OUT_DIR` with CPython's standard library only. Each case +writes OUT_DIR/.raw (the encoder's input, which is the expected output of decoding) +and OUT_DIR/.zlib (the stream). Streams come from CPython's `zlib` module, except where +zlib cannot produce the shape under test: there a small bit writer below assembles the deflate +blocks, and the stream is checked to decompress to the raw bytes with `zlib.decompress` before +it is written. The script prints, for each stream, its raw file, sizes, block types (read back by `block_types`) +and SHA-256, then each raw file's SHA-256: the tables in the corpus README. +""" + +import hashlib +import random +import struct +import sys +import zlib + +OUT = sys.argv[1] + + +def text(seed, size): + """Deterministic pseudo-English: words from a fixed list, chosen by a seeded generator.""" + words = ("the light falls on a bunny made of integer triangles while every ray " + "returns the same bytes on each platform and thread count lumen renders " + "texture maps decoded without floating point").split() + rng = random.Random(seed) + out = bytearray() + while len(out) < size: + out += rng.choice(words).encode() + (b"\n" if rng.random() < 0.08 else b" ") + return bytes(out[:size]) + + +def noise(seed, size): + rng = random.Random(seed) + return bytes(rng.getrandbits(8) for _ in range(size)) + + +def deflate(raw, level=6, wbits=15, strategy=zlib.Z_DEFAULT_STRATEGY, mem=8): + c = zlib.compressobj(level, zlib.DEFLATED, wbits, mem, strategy) + return c.compress(raw) + c.flush() + + +class Bits: + """An LSB-first bit writer (RFC 1951 section 3.1.1).""" + + def __init__(self): + self.out, self.acc, self.n = bytearray(), 0, 0 + + def put(self, value, count): + self.acc |= value << self.n + self.n += count + while self.n >= 8: + self.out.append(self.acc & 0xFF) + self.acc >>= 8 + self.n -= 8 + + def huff(self, code, length): + """A Huffman code, most significant bit first (RFC 1951 section 3.1.1).""" + for i in range(length - 1, -1, -1): + self.put((code >> i) & 1, 1) + + def align(self): + if self.n: + self.put(0, 8 - self.n) + return bytes(self.out) + + +def fixed_literal(bits, byte): + if byte < 144: + bits.huff(0x30 + byte, 8) + else: + bits.huff(0x190 + byte - 144, 9) + + +def zlib_wrap(raw_deflate, raw): + return b"\x78\x01" + raw_deflate + struct.pack(">I", zlib.adler32(raw)) + + +def max_distance(): + """32 768 literals, then one length-258 match at distance 32 768, in one fixed block. + + zlib's encoder never emits a distance beyond 32 506 (MAX_DIST), so this is assembled. + Length 258 is symbol 285 (8-bit code 11000101, no extra bits); distance 32 768 is code + 29 (5-bit code 11101) with 13 extra bits of 8 191 (base 24 577). + """ + head = noise(11, 32768) + bits = Bits() + bits.put(1, 1) + bits.put(1, 2) + for b in head: + fixed_literal(bits, b) + bits.huff(0b11000101, 8) + bits.huff(29, 5) + bits.put(8191, 13) + bits.huff(0, 7) + raw = head + head[:258] + return raw, zlib_wrap(bits.align(), raw) + + +def final_stored(): + """A dynamic or fixed block from zlib, a sync flush (an empty stored block), then a final + stored block assembled by hand (BFINAL 1, BTYPE 00, LEN, NLEN, the bytes).""" + a, b = text(21, 3000), text(22, 700) + c = zlib.compressobj(6, zlib.DEFLATED, -15) + body = c.compress(a) + c.flush(zlib.Z_SYNC_FLUSH) + body += b"\x01" + struct.pack("> 3] >> (pos[0] & 7)) & 1 + pos[0] += 1 + return b + + def bits(n): + return sum(bit() << i for i in range(n)) + + def table(lengths): + codes, code = {}, 0 + for length in range(1, 16): + for sym, l in enumerate(lengths): + if l == length: + codes[(length, code)] = sym + code += 1 + code <<= 1 + return codes + + def decode(codes): + code, length = 0, 0 + while True: + code, length = (code << 1) | bit(), length + 1 + if (length, code) in codes: + return codes[(length, code)] + + lbase = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, + 99, 115, 131, 163, 195, 227, 258] + lext = [0] * 8 + [i // 4 for i in range(4, 24)] + [0] + dext = [0, 0] + [i // 2 - 1 for i in range(2, 30)] + kinds = [] + while True: + final, kind = bit(), bits(2) + kinds.append(["stored", "fixed", "dynamic"][kind]) + if kind == 0: + pos[0] = (pos[0] + 7) & ~7 + n = bits(16) + bits(16) + pos[0] += 8 * n + else: + if kind == 1: + lit = table([8] * 144 + [9] * 112 + [7] * 24 + [8] * 8) + dist = table([5] * 30) + else: + hlit, hdist, hclen = bits(5) + 257, bits(5) + 1, bits(4) + 4 + order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15] + cl = [0] * 19 + for i in range(hclen): + cl[order[i]] = bits(3) + clt, lengths = table(cl), [] + while len(lengths) < hlit + hdist: + s = decode(clt) + if s < 16: + lengths.append(s) + elif s == 16: + lengths += [lengths[-1]] * (3 + bits(2)) + elif s == 17: + lengths += [0] * (3 + bits(3)) + else: + lengths += [0] * (11 + bits(7)) + lit, dist = table(lengths[:hlit]), table(lengths[hlit:]) + while True: + s = decode(lit) + if s == 256: + break + if s > 256: + bits(lext[s - 257]) + bits(dext[decode(dist)]) + if final: + return kinds + + +def summary(kinds): + """Runs of equal block types: `stored x2, fixed`.""" + out = [] + for k in kinds: + if out and out[-1][0] == k: + out[-1][1] += 1 + else: + out.append([k, 1]) + return ", ".join(k if n == 1 else f"{k} x{n}" for k, n in out) + + +def main(): + made = {name: (raw, make(raw)) for name, (raw, make) in CASES.items()} + made["max_distance"] = max_distance() + made["final_stored"] = final_stored() + raws = {} + for name, (raw, stream) in sorted(made.items()): + assert zlib.decompress(stream) == raw, name + # Equal inputs share one raw file, named for the first case that uses it. + raw_name = raws.setdefault(raw, name) + files = [(f"{name}.zlib", stream)] + if raw_name == name: + files.append((f"{name}.raw", raw)) + for file, data in files: + with open(f"{OUT}/{file}", "wb") as f: + f.write(data) + print(f"| `{name}` | `{raw_name}.raw` | {len(raw)} | {len(stream)} | " + f"{summary(block_types(stream))} | `{hashlib.sha256(stream).hexdigest()}` |") + for raw, name in sorted(raws.items(), key=lambda kv: kv[1]): + print(f"| `{name}.raw` | {len(raw)} | `{hashlib.sha256(raw).hexdigest()}` |") + + +main() diff --git a/crates/lumen-image/tests/corpus/max_distance.raw b/crates/lumen-image/tests/corpus/max_distance.raw new file mode 100644 index 0000000..42d1d10 Binary files /dev/null and b/crates/lumen-image/tests/corpus/max_distance.raw differ diff --git a/crates/lumen-image/tests/corpus/max_distance.zlib b/crates/lumen-image/tests/corpus/max_distance.zlib new file mode 100644 index 0000000..33b0d1a Binary files /dev/null and b/crates/lumen-image/tests/corpus/max_distance.zlib differ diff --git a/crates/lumen-image/tests/corpus/noise.raw b/crates/lumen-image/tests/corpus/noise.raw new file mode 100644 index 0000000..b312d4c Binary files /dev/null and b/crates/lumen-image/tests/corpus/noise.raw differ diff --git a/crates/lumen-image/tests/corpus/noise.zlib b/crates/lumen-image/tests/corpus/noise.zlib new file mode 100644 index 0000000..32e5427 Binary files /dev/null and b/crates/lumen-image/tests/corpus/noise.zlib differ diff --git a/crates/lumen-image/tests/corpus/one_byte.raw b/crates/lumen-image/tests/corpus/one_byte.raw new file mode 100644 index 0000000..083b700 --- /dev/null +++ b/crates/lumen-image/tests/corpus/one_byte.raw @@ -0,0 +1 @@ +L \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/one_byte.zlib b/crates/lumen-image/tests/corpus/one_byte.zlib new file mode 100644 index 0000000..c7bebd6 Binary files /dev/null and b/crates/lumen-image/tests/corpus/one_byte.zlib differ diff --git a/crates/lumen-image/tests/corpus/rle.raw b/crates/lumen-image/tests/corpus/rle.raw new file mode 100644 index 0000000..fce5310 --- /dev/null +++ b/crates/lumen-image/tests/corpus/rle.raw @@ -0,0 +1,265 @@ +texture falls integer +a same lumen renders +same lumen floating thread each texture thread thread returns falls returns the renders and on each maps every maps bytes count bytes the of triangles on without made thread lumen same platform decoded bytes +renders and without platform ray triangles same +returns ray the falls thread the maps falls same maps falls thread same point the integer every bytes floating returns returns integer thread a same texture every floating ray integer ray lumen floating on +the bunny +renders thread every same light a platform +texture maps falls on point and while and count and lumen and +on maps bunny floating maps the the a made the the integer each +texture every point +bytes integer same floating count maps of light while light lumen point returns falls thread on lumen falls every the count triangles bytes ray point each a bunny of the each renders ray the bytes thread of texture integer a and falls +light light count thread light +of of count triangles falls decoded +without on count light the thread returns triangles of decoded on made the texture count while falls and +every of the count returns light the +falls the falls platform a on thread platform bytes same integer without +renders texture on texture +bunny each same bytes on same and a the decoded +returns a each every renders falls platform floating made a floating bytes light renders floating while each integer texture integer on platform a bytes count point maps on while lumen of bunny a lumen platform platform texture every while floating +renders +without same the the lumen floating on decoded maps every same texture +on a the without a same same count on decoded while on triangles without on count bytes thread the maps on decoded +the each a integer count every lumen the without each bunny and ray platform and returns +without platform of light and bytes integer every returns on on and integer +bytes thread light +on +returns bunny every +integer every each maps lumen texture lumen triangles the renders decoded of and lumen on point on +integer falls renders a decoded +made without count each while the bunny of a each each integer platform each lumen +of each floating without texture integer returns every each without +and triangles thread on each each point while +returns the on same light maps maps every bunny same ray on +maps platform integer platform without integer ray point +every bunny texture the made +light same on while same every on floating integer every a renders lumen made without bytes ray bytes light and floating decoded lumen thread texture renders each while bunny renders point +while each platform +triangles bytes thread returns on platform falls decoded on point platform count returns ray the triangles returns light while every every maps a and and the and a +on platform +made light maps same every decoded the integer decoded and lumen platform on floating +triangles made returns the texture made each ray lumen light on platform point bunny platform triangles of a on on on +every integer of each while the on texture decoded decoded returns ray bytes each thread count +without same lumen on +and light +the the count platform same the and every a returns of count renders floating ray thread +triangles and on each and renders every integer and the made returns integer every decoded maps count +lumen bunny maps the a on decoded made on count count and falls lumen thread floating floating without returns each floating platform and texture count platform the triangles the on the lumen on on every maps lumen integer the on floating the integer bunny +thread +the the light integer of while integer light point of bytes same ray bytes a light decoded the and bunny texture maps bunny made bunny each and the lumen decoded light thread point on on the falls ray +point a +light +maps bunny made same falls platform renders platform texture every on the and count on lumen same floating without of decoded decoded returns +on decoded on on platform ray triangles and without of +floating floating and on returns every integer integer every count while maps every ray without point texture returns +while triangles +decoded made platform of the returns of every made floating on platform the a and decoded platform same decoded without +ray point bunny maps texture without same integer floating of bytes without decoded +maps and on bytes platform the bytes on +platform returns made made bunny triangles point bunny platform lumen +the floating a triangles on maps +falls ray count falls renders and light and +returns light the texture triangles renders while +integer point +and of each the made a bunny and the a +each each returns on +texture a on decoded light point platform bytes bytes point floating without without on same renders floating triangles renders +same returns returns the count the light a bytes the the without platform +the while point bytes without returns integer count point texture thread and platform made +a made the integer without the renders triangles every falls made falls made maps made light the +decoded triangles the falls on light platform bytes ray made texture on while thread and on made lumen on the on made returns +the a every decoded a while triangles triangles falls on every of renders made returns ray each the light light lumen count and light and renders without triangles the made each thread lumen while lumen +integer and the the falls the platform the triangles every lumen without and +texture maps thread bytes count renders made renders +integer renders triangles same falls on each +maps bunny and the point returns floating on bytes texture point the while triangles platform same falls triangles a while point light maps every count the returns floating light ray decoded texture a floating the of while on ray +made on decoded maps on each light returns +floating texture renders ray maps texture while made integer every and texture each made texture falls bunny made triangles while returns floating thread same same maps thread maps point the +decoded platform texture light on floating platform the point falls every of bunny ray renders every a +bunny texture maps made falls triangles the lumen made decoded while +bytes +made made each platform on same a decoded bunny same ray of a triangles while without and triangles each triangles of bunny lumen bunny a returns a count +and texture lumen same without +point made integer bunny same the maps thread renders renders of ray renders texture falls of a on while integer and the renders triangles point lumen on on the the renders decoded a and made bytes platform a ray +falls +of integer renders while +light lumen on maps platform renders returns floating the bytes thread the ray on lumen maps same +bunny light count thread light each +a while thread the count the lumen texture integer bunny each lumen platform without on point every integer on maps every falls triangles the a point returns integer the maps point ray made made lumen integer thread light renders on decoded of triangles the maps thread every decoded light +falls triangles of integer maps lumen texture ray thread count renders count of triangles made floating platform each of bunny point made renders same decoded texture falls count while of +each ray ray while renders while each thread thread texture on the while the ray +falls platform maps integer ray while bytes without on the decoded on a bytes the on and returns platform point made floating ray light +floating and each count every light each floating and maps texture made integer triangles each the on of floating thread floating point the falls the made without of without thread of the of decoded lumen and on the renders without falls while count each made bunny of each count a of a bytes triangles same +returns on the thread each integer on floating returns without made made made on platform thread the every thread renders +texture lumen each returns of light falls every lumen thread decoded without integer point decoded integer maps decoded the floating count count the bunny without count bunny +and triangles returns each light decoded and while on returns every every a lumen a the falls floating the each renders without bytes each the integer renders every returns of count of point lumen returns returns integer while every bytes platform on and bytes +ray returns decoded texture point decoded of and on a and and thread bunny light decoded without while on +point and of triangles platform texture made ray texture decoded falls falls light decoded +a decoded renders maps every +every same on integer on each the thread on and point while falls lumen the on triangles falls texture falls falls and returns a integer a light every light bytes every texture of returns and a without count maps same each on decoded each the same bunny +decoded while on the on light on count floating the count integer same point maps +the bunny +light +bunny and each decoded the texture +maps a returns made a point platform floating on maps thread floating lumen a +light +of floating triangles ray the the on on thread +bytes ray texture bytes triangles same on triangles decoded texture every while thread light while bytes triangles thread +each +light texture on renders returns thread +count falls while maps same ray texture texture platform and texture a on falls count while made same same decoded the maps lumen on falls the on while of without each and +ray floating decoded falls +floating integer decoded on decoded falls triangles the the thread platform platform on renders on falls every count on made platform triangles light triangles a returns while on falls +without a point triangles bunny same the floating returns the every platform platform light thread made falls every every point bytes decoded on ray decoded a triangles while maps light of renders of same texture +platform on falls floating triangles on lumen renders light on bytes light the maps light ray decoded floating bytes lumen floating lumen bytes lumen thread of ray every thread +renders each a +returns floating bunny the integer and returns texture point on light falls platform maps returns light +thread floating bytes light without ray without bunny on every the triangles every floating lumen decoded without same bytes ray floating +returns without falls the point renders bunny and each +light the thread decoded thread point lumen while on maps while +made thread count ray renders every on on light on the +integer +without floating ray while point maps and the returns texture +platform and every maps point while while each bunny renders +lumen each texture every triangles texture same count texture floating bytes +floating light +made floating made without while same and a +decoded +made made +decoded each made point thread made made made decoded floating on each count returns floating +the floating count thread returns point renders each the light count light every the floating thread without renders on without on without of returns +and same the of +the bytes lumen floating lumen thread returns on decoded integer every the made while +while a platform triangles made integer a floating thread texture renders lumen integer the on +without +on floating thread +each thread on on while the count +bunny lumen of integer +made bunny point floating light +thread floating point without maps thread each the a each without decoded thread falls floating +a same triangles decoded thread on platform thread the on light thread platform a a ray +point a same falls returns integer +lumen texture same same thread lumen +of on floating without decoded +on without falls maps platform point count floating texture on renders falls texture ray of renders on +decoded the light bytes thread maps on made each texture bunny platform decoded without maps while returns +renders bytes the on ray while every on and each while platform of and same a maps light of lumen falls +and bunny point bytes maps every same +decoded and each light bunny +on same on platform +on ray of count +the renders maps same of floating of and light same texture light each each bunny +bunny same a the without +maps same triangles the integer point point texture and lumen +on lumen light thread bunny +bytes renders of texture bunny the without +on decoded ray while falls thread decoded point on on integer falls ray made floating ray point point on each made of bytes maps of +bunny floating bunny each +of without on the count decoded count floating lumen integer of texture on +platform a lumen made point light falls bytes lumen decoded point on without the each while light and +made the and of maps maps bunny decoded decoded a point returns decoded on platform floating each of count the renders a ray the thread count the without bunny floating a integer and every while +platform thread bunny bytes point +made point the each +made bytes same without made of +bunny lumen on returns bytes floating lumen falls of +and maps renders maps integer each on floating bytes while bunny a platform the made +lumen same lumen point maps +made decoded of point triangles +light returns +while floating while renders of same of made texture on +without every decoded the each the renders same each texture and +each while while while integer returns every and same every same and ray +maps texture maps made on made and decoded bytes of each integer bunny without floating lumen while point of every without each integer bunny of floating each decoded the and returns renders falls +ray on decoded while the on a +same point thread and of renders maps the triangles light each floating each bunny decoded count made renders the light a each point +light lumen +of a thread ray count made returns integer of the decoded +and +a falls bytes ray platform point each the on +light on decoded thread floating floating light renders +bytes decoded point same renders on point on renders +returns every renders decoded platform +thread thread ray light lumen decoded platform triangles each of each point +texture the same returns renders maps floating bytes made while platform ray ray on decoded made +of same every a the ray point on every of made returns on while +without triangles and +ray the returns without lumen light floating and triangles returns point floating ray +thread count renders renders on renders +and thread thread a platform the and renders while made renders texture lumen falls on point falls texture light bunny returns falls the thread lumen falls without triangles the renders bunny each maps triangles without on bunny on light a +without light same without +texture floating every platform each lumen the each integer while ray triangles made bunny returns made a maps integer same on ray falls bytes bunny made texture each on maps +each ray bytes maps +lumen made returns falls on returns +bunny the a bunny texture decoded and texture triangles +decoded decoded and the falls the on a of thread +bunny integer +triangles falls platform +made +count without ray +and light of the bunny lumen renders +every light ray floating bytes and texture without the on falls and renders bytes the count point every while made renders bytes thread +on returns ray the bytes triangles triangles +integer decoded decoded same every +platform triangles renders +platform and of the +returns each while and lumen decoded light and every the +platform +a point decoded every light falls light a count every count integer decoded each made while light on same floating renders each +ray +maps triangles decoded each ray floating count count texture light +bytes same texture count bunny lumen bytes made every same point light thread renders maps returns decoded while on point floating maps +the triangles maps +renders same every while on and same every floating on lumen thread light on lumen triangles a triangles on while platform of bunny without point decoded platform count triangles thread returns bunny on each thread same without renders +every count the the on same point decoded a texture +on a ray light of floating every triangles while a thread on bytes a renders integer bunny of the renders made every +platform bytes lumen the each decoded renders the of made same renders bytes falls +made decoded without the each light floating and maps lumen every platform same decoded bytes every each count made while decoded without without same maps made returns +count and returns platform while thread ray triangles +of bytes thread while falls without platform the bunny +count without bunny +falls every and point +maps lumen a same a +of each platform triangles renders +decoded every each on while a and decoded the light and and returns +texture thread the light point the the integer returns while floating made on bunny bunny +renders every bunny the without the every lumen ray decoded the a on a every thread a integer same +falls of of floating maps texture made bunny integer decoded +falls and ray count +same renders triangles count the each point on bunny on the of decoded platform while on a thread the the light platform made +platform thread platform and on maps a of ray a +on thread +made count each decoded lumen triangles platform ray decoded bytes count maps +thread texture the renders same floating decoded integer maps light decoded point renders lumen +on maps +count lumen lumen on on point count on point point maps returns light returns each thread every the every platform bunny same every +falls bunny made integer texture thread maps +bunny each bytes floating count on thread bytes platform a of falls point on texture every maps integer integer maps +renders ray every texture floating thread returns lumen same returns renders bunny the +decoded every same bytes on a maps light platform floating integer and a point triangles while falls bytes while returns lumen ray thread renders +while bytes platform of +bytes falls thread on the ray lumen point a texture decoded maps integer every made bunny the on on ray +renders ray bytes ray +platform decoded light falls count platform renders and point same lumen and every ray on of +each every integer each triangles returns maps of on bytes point of each +on of renders of point bunny the a of integer thread ray every +a on bunny while while +light ray each returns made texture floating triangles renders ray renders platform light ray without maps lumen integer the maps triangles integer the count triangles on renders triangles bunny on same the the lumen thread light of same maps every bunny every lumen bunny integer texture +and bytes on triangles floating thread same bytes a ray returns made thread bunny lumen decoded a and triangles count decoded triangles made renders bytes bytes ray thread light triangles the each same triangles on maps the light without the lumen lumen bunny texture thread every while on decoded renders while the thread while of floating the on +of the lumen bytes +the +of without triangles returns +point the returns and on on bunny +the light each decoded bunny triangles +the floating every light +and +count while bytes bytes on bytes point returns bunny floating on the count same renders point +count made floating lumen ray every maps light +without the lumen each ray ray the returns ray falls on integer the decoded ray light ray bunny a decoded a maps integer each the while renders ray decoded on of on every on texture point platform point and light same the made a integer point a falls without on without floating returns made light integer each count point +texture floating light point on count bytes the texture returns +maps platform while returns while a and platform light +made bytes platform bytes renders a the platform ray point while point same bunny without made count every while light integer each floating each on the floating texture light renders +triangles lumen renders every count renders returns thread bunny triangles each thread ray falls without light decoded light of +thread renders on texture +same and ray renders bunny bunny on of and platform the bunny light every on count while bunny +every integer on light count the while decoded +every texture byt \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/rle.zlib b/crates/lumen-image/tests/corpus/rle.zlib new file mode 100644 index 0000000..659a9ff Binary files /dev/null and b/crates/lumen-image/tests/corpus/rle.zlib differ diff --git a/crates/lumen-image/tests/corpus/run_258.raw b/crates/lumen-image/tests/corpus/run_258.raw new file mode 100644 index 0000000..5770a2a --- /dev/null +++ b/crates/lumen-image/tests/corpus/run_258.raw @@ -0,0 +1 @@ +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/run_258.zlib b/crates/lumen-image/tests/corpus/run_258.zlib new file mode 100644 index 0000000..6d2cd03 Binary files /dev/null and b/crates/lumen-image/tests/corpus/run_258.zlib differ diff --git a/crates/lumen-image/tests/corpus/short_text.raw b/crates/lumen-image/tests/corpus/short_text.raw new file mode 100644 index 0000000..bbb1305 --- /dev/null +++ b/crates/lumen-image/tests/corpus/short_text.raw @@ -0,0 +1,2 @@ +of a platform each +the same of count maps ray a a bytes the falls point triangles maps same floating count returns textu \ No newline at end of file diff --git a/crates/lumen-image/tests/corpus/short_text.zlib b/crates/lumen-image/tests/corpus/short_text.zlib new file mode 100644 index 0000000..5ef42dc --- /dev/null +++ b/crates/lumen-image/tests/corpus/short_text.zlib @@ -0,0 +1,3 @@ +xœ-ÌA„0 CÑ=§ðÕ<(�JiS¥©4Üž‚Xû}»‚èÆT� +á~ny +«À»Ï–¨ìÁkQâw¥ &mut Writer { + if symbol <= 12 { + w.code(symbol, 4) + } else { + w.code(0b11010 + symbol - 13, 5) + } +} + +/// A dynamic block's header for literal/length lengths `literals` and distance lengths +/// `distances`, each length written as its own code-length symbol. +fn dynamic(w: &mut Writer, last: bool, literals: &[u8], distances: &[u8]) { + w.block(last, 2); + let (hlit, hdist) = (literals.len() - 257, distances.len() - 1); + w.value(u32::try_from(hlit).unwrap(), 5).value(u32::try_from(hdist).unwrap(), 5).value(15, 4); + // The code-length lengths, in the order of section 3.2.7. + for symbol in [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15] { + w.value(if symbol <= 12 { 4 } else { 5 }, 3); + } + for &length in literals.iter().chain(distances) { + length_symbol(w, u32::from(length)); + } +} + +/// Literal/length lengths with `lengths` set and the rest zero. +fn lengths(set: &[(usize, u8)]) -> [u8; N] { + let mut all = [0; N]; + for &(symbol, length) in set { + all[symbol] = length; + } + all +} + +/// One fixed block, final, holding "aaaa" as a literal and a match, built by hand: +/// +/// ```text +/// field value code (sent first to last) bits on the wire, in order +/// BFINAL 1 1 +/// BTYPE 01 (value, LSB first) 1 0 +/// 'a' = 97 lit 00110000 + 97 = 10010001 1 0 0 1 0 0 0 1 +/// length 3 257 0000000 + 1 = 0000001 0 0 0 0 0 0 1 +/// distance 1 0 00000 0 0 0 0 0 +/// end 256 0000000 0 0 0 0 0 0 0 +/// ``` +/// +/// The 30 bits, packed least significant first: `1101_0010 0010_0000 0100_0000 0000_00`, read +/// right to left per byte: 0x4b, 0x04, 0x02, 0x00. The header is `78 01` (0x7801 = 31 * 991), +/// the trailer Adler-32("aaaa") = 0x03ce0185 (A = 1 + 4 * 97 = 389, B = 98 + 195 + 292 + 389 = +/// 974 = 0x3ce). +#[test] +fn a_hand_assembled_fixed_block_decodes() { + let stream = [0x78, 0x01, 0x4b, 0x04, 0x02, 0x00, 0x03, 0xce, 0x01, 0x85]; + assert_eq!(inflate_zlib(&stream, ROOM).unwrap(), b"aaaa"); +} + +/// One dynamic block, final, holding "aa" with two one-bit literal/length codes and the single +/// one-bit distance code of section 3.2.7, built by hand: +/// +/// ```text +/// BFINAL 1, BTYPE 10 1 | 0 1 +/// HLIT 0 (257), HDIST 0 (1), HCLEN 14 00000 | 00000 | 0111 +/// code-length lengths, order 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1: +/// 18 and 1 have length 1, the rest 0 000 000 100 000 ... 000 100 (18 fields, 3 bits each) +/// code-length code (section 3.2.2): symbol 1 -> 0, symbol 18 -> 1 +/// lengths: 97 zeros 18 + 86 (7 bits) 1 | 0110101 +/// 'a' = 1 1 0 +/// 138 zeros 18 + 127 1 | 1111111 +/// 20 zeros 18 + 9 1 | 1001000 +/// 256 = 1 1 0 +/// dist 0 = 1 1 0 +/// literal/length code: 97 -> 0, 256 -> 1; data 'a' 'a' end 0 0 1 +/// ``` +/// +/// 101 bits; packed, `05 c0 81 00 00 00 00 00 90 56 ff 13 10`. Adler-32("aa") = 0x012500c3 (A +/// = 195, B = 98 + 195 = 293 = 0x125). The stream was checked to decompress to "aa" with +/// CPython's zlib. +#[test] +fn a_hand_assembled_dynamic_block_with_one_distance_code_decodes() { + let stream = [ + 0x78, 0x01, 0x05, 0xc0, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x56, 0xff, 0x13, 0x10, + 0x01, 0x25, 0x00, 0xc3, + ]; + assert_eq!(inflate_zlib(&stream, ROOM).unwrap(), b"aa"); +} + +/// RFC 1950's smallest stream: a final fixed block holding only its end code, `03 00`. +#[test] +fn the_empty_stream_decodes_to_nothing_even_with_a_zero_limit() { + let stream = [0x78, 0x9c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01]; + assert_eq!(inflate_zlib(&stream, OutputLimit::new(0)).unwrap(), b""); +} + +#[test] +fn a_header_that_is_not_a_multiple_of_31_is_refused() { + refused(&[0x78, 0x02, 0x03, 0x00], InflateErrorKind::HeaderCheck { cmf: 0x78, flg: 0x02 }, 1); +} + +#[test] +fn a_method_other_than_deflate_is_refused() { + let cmf = 0x77; + refused(&[cmf, flg_for(cmf, 0)], InflateErrorKind::CompressionMethod { method: 7 }, 1); +} + +#[test] +fn a_window_field_of_7_is_accepted_and_8_is_refused() { + let mut w = Writer::zlib(0x78, flg_for(0x78, 0)); + w.block(true, 1).code(0, 7); + assert_eq!(inflate_zlib(&w.trailer(b""), ROOM).unwrap(), b""); + refused(&[0x88, flg_for(0x88, 0)], InflateErrorKind::WindowSize { cinfo: 8 }, 1); +} + +#[test] +fn a_preset_dictionary_is_refused_by_name() { + refused(&[0x78, flg_for(0x78, 0x20)], InflateErrorKind::PresetDictionary, 1); +} + +#[test] +fn the_reserved_block_type_is_refused() { + let mut w = Writer::deflate(); + w.block(true, 3); + refused(&w.finish(), InflateErrorKind::ReservedBlockType, w.last_byte()); +} + +#[test] +fn a_stored_length_that_does_not_match_its_complement_is_refused() { + let mut w = Writer::deflate(); + w.block(true, 0).align().bytes(&[5, 0, 0xfa, 0xfe]); + let kind = InflateErrorKind::StoredLengthMismatch { len: 5, nlen: 0xfefa }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn a_stored_block_of_the_largest_length_decodes() { + let data: Vec = (0..65_535_u32).map(|i| u8::try_from(i % 251).unwrap()).collect(); + let mut w = Writer::deflate(); + w.block(true, 0).align().bytes(&[0xff, 0xff, 0, 0]).bytes(&data); + assert_eq!(inflate_zlib(&w.trailer(&data), ROOM).unwrap(), data); +} + +#[test] +fn literal_length_codes_are_accepted_up_to_286_and_refused_at_287() { + let mut literals = lengths::<286>(&[(97, 1), (256, 1)]); + let mut w = Writer::deflate(); + dynamic(&mut w, true, &literals, &[0]); + w.code(0, 1).code(1, 1); + assert_eq!(inflate_zlib(&w.trailer(b"a"), ROOM).unwrap(), b"a"); + + let mut w = Writer::deflate(); + w.block(true, 2).value(30, 5).value(0, 5).value(15, 4); + let kind = InflateErrorKind::TooManyCodes { alphabet: Alphabet::LiteralLength, count: 287 }; + refused(&w.finish(), kind, w.last_byte()); + literals[0] = 0; +} + +#[test] +fn distance_codes_are_accepted_up_to_30_and_refused_at_31() { + let literals = lengths::<257>(&[(97, 1), (256, 1)]); + let mut w = Writer::deflate(); + dynamic(&mut w, true, &literals, &[0; 30]); + w.code(0, 1).code(1, 1); + assert_eq!(inflate_zlib(&w.trailer(b"a"), ROOM).unwrap(), b"a"); + + let mut w = Writer::deflate(); + w.block(true, 2).value(0, 5).value(30, 5).value(15, 4); + let kind = InflateErrorKind::TooManyCodes { alphabet: Alphabet::Distance, count: 31 }; + refused(&w.finish(), kind, w.last_byte()); +} + +/// Code-length lengths written in section 3.2.7's order, `HCLEN` + 4 of them. +fn code_length_header(lengths: &[u32]) -> Writer { + let mut w = Writer::deflate(); + w.block(true, 2).value(0, 5).value(0, 5).value(u32::try_from(lengths.len() - 4).unwrap(), 4); + for &length in lengths { + w.value(length, 3); + } + w +} + +#[test] +fn an_over_subscribed_code_length_code_is_refused() { + // Symbols 16, 17 and 18 each with one bit: three codes where two fit. + let w = code_length_header(&[1, 1, 1, 0]); + let kind = InflateErrorKind::OverSubscribedCode { alphabet: Alphabet::CodeLength }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn a_code_length_code_of_one_symbol_is_refused_as_incomplete() { + // Only symbol 18, with one bit: the one-code shape is admitted for no code-length code. + let w = code_length_header(&[0, 0, 1, 0]); + let kind = InflateErrorKind::IncompleteCode { alphabet: Alphabet::CodeLength }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn an_incomplete_literal_length_code_is_refused() { + // 'a' and 256 with two bits each: half the code space unused. + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<257>(&[(97, 2), (256, 2)]), &[0]); + let kind = InflateErrorKind::IncompleteCode { alphabet: Alphabet::LiteralLength }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn an_over_subscribed_distance_code_is_refused() { + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<257>(&[(97, 1), (256, 1)]), &[1, 1, 1]); + let kind = InflateErrorKind::OverSubscribedCode { alphabet: Alphabet::Distance }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn an_incomplete_distance_code_of_two_symbols_is_refused() { + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<257>(&[(97, 1), (256, 1)]), &[2, 2]); + let kind = InflateErrorKind::IncompleteCode { alphabet: Alphabet::Distance }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn a_literal_length_code_of_only_the_end_symbol_decodes_an_empty_block() { + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<257>(&[(256, 1)]), &[0]); + w.code(0, 1); + assert_eq!(inflate_zlib(&w.trailer(b""), ROOM).unwrap(), b""); +} + +#[test] +fn the_unused_half_of_a_one_symbol_distance_code_is_refused() { + // 257 -> 0, 'a' -> 10, 256 -> 11 (section 3.2.2); one distance code, 0 -> 0. + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<258>(&[(97, 2), (256, 2), (257, 1)]), &[1]); + w.code(0b10, 2).code(0, 1).code(1, 1); + refused(&w.finish(), InflateErrorKind::UnusedCode { alphabet: Alphabet::Distance }, w.last_byte()); +} + +#[test] +fn a_match_in_a_block_with_no_distance_code_is_refused() { + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<258>(&[(97, 2), (256, 2), (257, 1)]), &[0]); + w.code(0b10, 2).code(0, 1); + refused(&w.finish(), InflateErrorKind::UnusedCode { alphabet: Alphabet::Distance }, w.last_byte()); +} + +#[test] +fn a_repeat_with_no_previous_length_is_refused() { + let mut w = Writer::deflate(); + w.block(true, 2).value(0, 5).value(0, 5).value(15, 4); + for symbol in [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15] { + w.value(if symbol <= 12 { 4 } else { 5 }, 3); + } + length_symbol(&mut w, 16); + refused(&w.finish(), InflateErrorKind::RepeatWithoutLength, w.last_byte()); +} + +#[test] +fn lengths_that_run_past_the_declared_codes_are_refused() { + // 258 lengths declared; 138 + 138 zeros run past them. + let mut w = Writer::deflate(); + w.block(true, 2).value(0, 5).value(0, 5).value(15, 4); + for symbol in [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15] { + w.value(if symbol <= 12 { 4 } else { 5 }, 3); + } + length_symbol(&mut w, 18).value(127, 7); + length_symbol(&mut w, 18).value(127, 7); + refused(&w.finish(), InflateErrorKind::CodeLengthsOverrun, w.last_byte()); +} + +#[test] +fn a_block_whose_end_symbol_has_no_code_is_refused() { + let mut w = Writer::deflate(); + dynamic(&mut w, true, &lengths::<257>(&[(97, 1), (98, 1)]), &[0]); + refused(&w.finish(), InflateErrorKind::MissingEndOfBlock, w.last_byte()); +} + +#[test] +fn fixed_literal_length_symbols_286_and_287_are_refused() { + for (symbol, code) in [(286, 0b1100_0110), (287, 0b1100_0111)] { + let mut w = Writer::deflate(); + w.block(true, 1).code(code, 8); + let kind = InflateErrorKind::InvalidSymbol { alphabet: Alphabet::LiteralLength, symbol }; + refused(&w.finish(), kind, w.last_byte()); + } +} + +#[test] +fn fixed_distance_symbols_30_and_31_are_refused() { + for symbol in [30, 31] { + let mut w = Writer::deflate(); + w.block(true, 1).fixed_literal(b'a').code(1, 7).code(u32::from(symbol), 5); + let kind = InflateErrorKind::InvalidSymbol { alphabet: Alphabet::Distance, symbol }; + refused(&w.finish(), kind, w.last_byte()); + } +} + +#[test] +fn a_distance_to_the_first_byte_decodes_and_one_further_is_refused() { + // 'a' 'b', then length 3 at distance 2 (symbol 1, no extra bits): "ababa". + let mut w = Writer::deflate(); + w.block(true, 1).fixed_literal(b'a').fixed_literal(b'b').code(1, 7).code(1, 5).code(0, 7); + assert_eq!(inflate_zlib(&w.trailer(b"ababa"), ROOM).unwrap(), b"ababa"); + + // Distance 3 (symbol 2) with two bytes decoded. + let mut w = Writer::deflate(); + w.block(true, 1).fixed_literal(b'a').fixed_literal(b'b').code(1, 7).code(2, 5); + let kind = InflateErrorKind::DistanceTooFar { distance: 3, available: 2 }; + refused(&w.finish(), kind, w.last_byte()); +} + +/// A header with `CINFO` 0 (a 256-byte window), 300 literals, then a 3-byte match at +/// `distance` (256 is symbol 15, base 193, 6 extra bits of 63; 257 is symbol 16, base 257, 7 +/// extra bits of 0). +fn small_window(distance: u32) -> (Writer, Vec) { + let mut w = Writer::zlib(0x08, flg_for(0x08, 0)); + let literals: Vec = (0..300_u32).map(|i| u8::try_from(i % 256).unwrap()).collect(); + w.block(true, 1); + for &b in &literals { + w.fixed_literal(b); + } + w.code(1, 7); + if distance == 256 { + w.code(15, 5).value(63, 6); + } else { + w.code(16, 5).value(distance - 257, 7); + } + (w, literals) +} + +#[test] +fn a_distance_equal_to_the_declared_window_decodes_and_one_past_is_refused() { + let (mut w, mut decoded) = small_window(256); + w.code(0, 7); + let start = decoded.len() - 256; + decoded.extend_from_within(start..start + 3); + assert_eq!(inflate_zlib(&w.trailer(&decoded), ROOM).unwrap(), decoded); + + let (w, _) = small_window(257); + let kind = InflateErrorKind::DistanceBeyondWindow { distance: 257, window: 256 }; + refused(&w.finish(), kind, w.last_byte()); +} + +#[test] +fn a_stream_cut_inside_its_header_is_truncated_at_its_length() { + refused(&[0x78], InflateErrorKind::Truncated, 1); + refused(&[], InflateErrorKind::Truncated, 0); +} + +#[test] +fn a_wrong_adler32_is_refused() { + let stream = [0x78, 0x9c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x02]; + let kind = InflateErrorKind::Adler32Mismatch { stored: 2, computed: adler32(b"") }; + refused(&stream, kind, 7); +} + +#[test] +fn a_byte_after_the_trailer_is_refused() { + let stream = [0x78, 0x9c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00]; + refused(&stream, InflateErrorKind::TrailingBytes { count: 1 }, 8); +} + +#[test] +fn a_stored_block_beyond_the_limit_is_refused_before_its_data_is_read() { + // The block declares 10 bytes and holds none: the limit, not the truncation, is reported. + let mut w = Writer::deflate(); + w.block(true, 0).align().bytes(&[10, 0, 0xf5, 0xff]); + let error = inflate_zlib(&w.finish(), OutputLimit::new(9)).unwrap_err(); + assert_eq!((error.kind(), error.offset()), (&InflateErrorKind::OutputLimit { limit: 9 }, 6)); +} + +#[test] +fn a_match_beyond_the_limit_is_refused_at_the_match() { + // "aaaa" is 'a' and a 3-byte match: a limit of 3 admits the literal and refuses the match. + let stream = [0x78, 0x01, 0x4b, 0x04, 0x02, 0x00, 0x03, 0xce, 0x01, 0x85]; + let error = inflate_zlib(&stream, OutputLimit::new(3)).unwrap_err(); + assert_eq!(error.kind(), &InflateErrorKind::OutputLimit { limit: 3 }); + assert_eq!(inflate_zlib(&stream, OutputLimit::new(4)).unwrap(), b"aaaa"); +} diff --git a/crates/lumen-image/tests/writer/mod.rs b/crates/lumen-image/tests/writer/mod.rs new file mode 100644 index 0000000..a92fcdd --- /dev/null +++ b/crates/lumen-image/tests/writer/mod.rs @@ -0,0 +1,106 @@ +//! A deflate bit writer for the tests: it assembles streams bit by bit from RFC 1951 and RFC +//! 1950 as written, sharing no code with the decoder, so a test's stream and its expected +//! offsets come from the RFCs and not from what the decoder reads. + +/// Bits packed least significant first into bytes (RFC 1951 section 3.1.1). +#[derive(Default)] +pub struct Writer { + bits: Vec, +} + +impl Writer { + /// A stream that starts with the zlib header `cmf`, `flg`. + pub fn zlib(cmf: u8, flg: u8) -> Self { + let mut w = Self::default(); + w.value(u32::from(cmf), 8); + w.value(u32::from(flg), 8); + w + } + + /// The default header: deflate, a 32 KiB window, no dictionary (`78 01`). + pub fn deflate() -> Self { + Self::zlib(0x78, 0x01) + } + + /// `count` bits of `value`, least significant first: header fields and extra bits. + pub fn value(&mut self, value: u32, count: u32) -> &mut Self { + self.bits.extend((0..count).map(|i| u8::try_from((value >> i) & 1).unwrap())); + self + } + + /// A Huffman code of `length` bits, most significant first (section 3.1.1). + pub fn code(&mut self, code: u32, length: u32) -> &mut Self { + self.bits.extend((0..length).rev().map(|i| u8::try_from((code >> i) & 1).unwrap())); + self + } + + /// A block header: `BFINAL`, then `BTYPE` in two bits. + pub fn block(&mut self, last: bool, kind: u32) -> &mut Self { + self.value(u32::from(last), 1).value(kind, 2) + } + + /// Zero bits to the next byte boundary. + pub fn align(&mut self) -> &mut Self { + while self.bits.len() % 8 != 0 { + self.bits.push(0); + } + self + } + + /// Whole bytes, after [`Self::align`]. + pub fn bytes(&mut self, bytes: &[u8]) -> &mut Self { + for &b in bytes { + self.value(u32::from(b), 8); + } + self + } + + /// The offset of the byte that holds the last bit written so far: where a decoder that + /// faults on that bit must report the fault. + pub fn last_byte(&self) -> usize { + (self.bits.len() - 1) / 8 + } + + /// The bits so far, zero-padded to a whole byte. + pub fn finish(&self) -> Vec { + self.bits + .chunks(8) + .map(|byte| byte.iter().enumerate().map(|(i, &b)| b << i).sum()) + .collect() + } + + /// The bits so far, aligned, then the Adler-32 trailer of `decoded`: a complete stream. + pub fn trailer(&mut self, decoded: &[u8]) -> Vec { + self.align(); + self.bytes(&adler32(decoded).to_be_bytes()); + self.finish() + } + + /// A fixed-Huffman literal (section 3.2.6): 0-143 as `00110000` plus the byte in 8 bits, + /// 144-255 as `110010000` plus the byte less 144 in 9 bits. + pub fn fixed_literal(&mut self, byte: u8) -> &mut Self { + if byte < 144 { + self.code(0x30 + u32::from(byte), 8) + } else { + self.code(0x190 + u32::from(byte) - 144, 9) + } + } +} + +/// The second header byte that makes `cmf` and `flags` (the top three bits, `FDICT` and +/// `FLEVEL`) a multiple of 31 (RFC 1950 section 2.2, `FCHECK`). +pub fn flg_for(cmf: u8, flags: u8) -> u8 { + let base = u32::from(cmf) * 256 + u32::from(flags & 0xe0); + flags & 0xe0 | u8::try_from((31 - base % 31) % 31).unwrap() +} + +/// Adler-32 straight from its definition (RFC 1950 section 8): A is one plus the sum of the +/// bytes and B the sum of each step's A, both modulo 65 521, reduced at every byte. +pub fn adler32(bytes: &[u8]) -> u32 { + let (mut a, mut b) = (1_u32, 0_u32); + for &byte in bytes { + a = (a + u32::from(byte)) % 65_521; + b = (b + a) % 65_521; + } + b * 65_536 + a +}