From 7bde2ed08679cd95cdf5deda5c0cfe5ba5b58121 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 00:46:24 +0000 Subject: [PATCH 1/4] decoders: harden the JPEG and FLAC decoders against fuzzed input Continues the hardening that landed in PR #4. Each change rejects malformed input with an error or uses wrapping arithmetic where the value is unbounded by the format. Valid input is unchanged. jpeg: - Every length-bearing marker's segment must lie inside the input before its fields are read. SOF needs seven bytes and its component list must fit the segment; SOS needs its component list to fit; DRI reads are bounded. - DQT and DHT bound their reads against the segment end. - Sampling factors are 1..=4 (ITU-T T.81). - Entropy bits past the end of the scan read as zeros instead of underflowing the bit count. The bit count is clamped to 32, the Huffman symbol size is clamped to 16 in EXTEND, and the received value is masked to that size. - The DC predictor uses wrapping arithmetic. flac: - The unary code loop stops at the end of the input. - The metadata loop stops past the end of the input. - A wasted-bits count at or above the sample width is an error. - A frame whose channel count differs from STREAMINFO is an error. - A predictor order larger than its partition is an error, and a block size not divisible by the partition count is an error. - Predictor arithmetic wraps. tests/fuzz_regressions.rs embeds each reproducing input and runs the decoder on a worker thread with a deadline. A panic, a hang or an abort fails the test. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Ch6Crfubj3FwdxR7ywn9vT --- src/flac.rs | 39 +++- src/jpeg.rs | 36 ++- tests/fuzz_regressions.rs | 465 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 524 insertions(+), 16 deletions(-) diff --git a/src/flac.rs b/src/flac.rs index 2988833..c4d440a 100644 --- a/src/flac.rs +++ b/src/flac.rs @@ -456,11 +456,21 @@ fn read_utf8(r: &mut R) { } } -fn decode_residual(r: &mut R, blocksize: usize, order: usize) -> Vec { +fn decode_residual(r: &mut R, blocksize: usize, order: usize) -> Result, String> { let method = r.bits(2); let pbits = if method == 0 { 4 } else { 5 }; let po = r.bits(4) as u32; let parts = 1usize << po; + // The partitions must divide the block exactly (the FLAC format requires it). Otherwise they sum to + // fewer samples than the subframe needs. + if blocksize % parts != 0 { + return Err("FLAC: block size is not divisible by the partition count".into()); + } + // The first partition holds blocksize >> po samples minus the predictor order. A larger order is + // invalid, and it would underflow the count below. + if (blocksize >> po) < order { + return Err("FLAC: predictor order exceeds the partition size".into()); + } let mut res = Vec::with_capacity(blocksize - order); for p in 0..parts { let cnt = if p == 0 { @@ -484,7 +494,7 @@ fn decode_residual(r: &mut R, blocksize: usize, order: usize) -> Vec { } } } - res + Ok(res) } fn decode_subframe(r: &mut R, blocksize: usize, bps: u32) -> Result, String> { @@ -506,17 +516,25 @@ fn decode_subframe(r: &mut R, blocksize: usize, bps: u32) -> Result, St } else if typ & 0b111000 == 0b001000 { let order = (typ & 0b111) as usize; let mut s: Vec = (0..order).map(|_| r.sbits(b)).collect(); - let res = decode_residual(r, blocksize, order); + let res = decode_residual(r, blocksize, order)?; for i in 0..res.len() { let n = order + i; + // Wrapping: valid streams stay in range, and hostile input must not panic. let p = match order { 0 => 0, 1 => s[n - 1], - 2 => 2 * s[n - 1] - s[n - 2], - 3 => 3 * s[n - 1] - 3 * s[n - 2] + s[n - 3], - _ => 4 * s[n - 1] - 6 * s[n - 2] + 4 * s[n - 3] - s[n - 4], + 2 => s[n - 1].wrapping_mul(2).wrapping_sub(s[n - 2]), + 3 => s[n - 1] + .wrapping_mul(3) + .wrapping_sub(s[n - 2].wrapping_mul(3)) + .wrapping_add(s[n - 3]), + _ => s[n - 1] + .wrapping_mul(4) + .wrapping_sub(s[n - 2].wrapping_mul(6)) + .wrapping_add(s[n - 3].wrapping_mul(4)) + .wrapping_sub(s[n - 4]), }; - s.push(res[i] + p); + s.push(res[i].wrapping_add(p)); } s } else if typ & 0b100000 == 0b100000 { @@ -525,14 +543,15 @@ fn decode_subframe(r: &mut R, blocksize: usize, bps: u32) -> Result, St let prec = (r.bits(4) as u32) + 1; let shift = r.bits(5) as i64; let coeffs: Vec = (0..order).map(|_| r.sbits(prec)).collect(); - let res = decode_residual(r, blocksize, order); + let res = decode_residual(r, blocksize, order)?; for i in 0..res.len() { let n = order + i; + // Wrapping: valid streams never overflow i64 here, and hostile input must not panic. let mut p = 0i64; for j in 0..order { - p += coeffs[j] * s[n - 1 - j]; + p = p.wrapping_add(coeffs[j].wrapping_mul(s[n - 1 - j])); } - s.push(res[i] + (p >> shift)); + s.push(res[i].wrapping_add(p >> shift)); } s } else { diff --git a/src/jpeg.rs b/src/jpeg.rs index 28548e3..d69581f 100644 --- a/src/jpeg.rs +++ b/src/jpeg.rs @@ -352,12 +352,20 @@ impl<'a> JpegBitReader<'a> { b } fn get_bits(&mut self, n: u32) -> u32 { + // The bit count comes from a Huffman symbol, which can name up to 255 bits. Valid JPEG needs at + // most 16 (DC) or 15 (AC), and the accumulator holds 64 bits; clamp so the shift cannot overflow. + let n = n.min(32); if n == 0 { return 0; } if self.nbits < n { self.fill(); } + // Past the end of the entropy-coded data the accumulator holds zeros. Count them as bits so the + // count cannot underflow; valid scans never request bits beyond the marker that ends them. + if self.nbits < n { + self.nbits = n; + } let v = (self.acc >> (64 - n)) as u32; self.acc <<= n; self.nbits -= n; @@ -408,11 +416,15 @@ fn extend(v: u32, s: u32) -> i32 { if s == 0 { return 0; } + // EXTEND is defined for at most 16 bits; the size comes from a Huffman symbol that can name more. + let s = s.min(16); + // Keep only the s bits EXTEND reads, so a wider value from the caller cannot overflow below. + let v = (v & ((1u32 << s) - 1)) as i32; let vt = 1i32 << (s - 1); - if (v as i32) < vt { - v as i32 + (-1i32 << s) + 1 + if v < vt { + v + (-1i32 << s) + 1 } else { - v as i32 + v } } @@ -581,12 +593,23 @@ pub fn decode(data: &[u8]) -> Result { if (width as u64) * (height as u64) > 100_000_000 { return Err("JPEG: exceeds 100MP".into()); } - let nc = data[p + 7] as usize; + let nc = *data + .get(p + 7) + .ok_or_else(|| "JPEG: truncated frame header".to_string())? + as usize; + // Each component is 3 bytes after the 8-byte fixed part; the segment must hold them all. + if len < 8 + 3 * nc { + return Err("JPEG: frame header too short for its component count".into()); + } comps.clear(); for i in 0..nc { let o = p + 8 + i * 3; let id = data[o]; let hv = data[o + 1]; + // Sampling factors are 1..=4 (ITU-T T.81). Zero would divide by zero in the block layout. + if !(1..=4).contains(&(hv >> 4)) || !(1..=4).contains(&(hv & 0x0F)) { + return Err("JPEG: sampling factor outside 1..=4".into()); + } comps.push(Component { id, h: hv >> 4, @@ -796,8 +819,9 @@ fn decode_scan( // DC let t = br.decode_huff(dch)?; let diff = extend(br.get_bits(t as u32), t as u32); - dc_pred[ci] += diff; - coef[0] = (dc_pred[ci] * qt[0] as i32) as f32; + // Wrapping: the DC predictor is unbounded in the format; valid scans stay in range. + dc_pred[ci] = dc_pred[ci].wrapping_add(diff); + coef[0] = (dc_pred[ci].wrapping_mul(qt[0] as i32)) as f32; // AC let mut k = 1usize; while k < 64 { diff --git a/tests/fuzz_regressions.rs b/tests/fuzz_regressions.rs index 12f3a25..abaad40 100644 --- a/tests/fuzz_regressions.rs +++ b/tests/fuzz_regressions.rs @@ -107,6 +107,471 @@ fn flac_frame_channel_mismatch_is_rejected() { assert!(r.is_err(), "expected Err, got {r:?}"); } +// jpeg: a frame header declaring 255 components in an 8-byte segment; the component loop read past the input. +const JPEG_SOF_COMPONENTS_PAST_SEGMENT: &[u8] = &[ + 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x08, 0x08, 0x00, 0x10, 0x00, 0x10, 0xff, +]; // 12 bytes, constructed from the SOF code path + +#[test] +fn jpeg_frame_components_past_segment_are_rejected() { + let r = bounded("jpeg-sof", || { + transcode::jpeg::decode(JPEG_SOF_COMPONENTS_PAST_SEGMENT).map(|_| ()) + }); + assert!(r.is_err(), "expected Err, got {r:?}"); +} + +// flac: a predictor order larger than the partition size underflowed the first partition count. +const FLAC_RESIDUAL_ORDER_TOO_LARGE: &[u8] = &[ + 0x66, 0x4c, 0x61, 0x43, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, 0x56, + 0x56, 0x56, 0x56, 0x56, 0x56, 0x00, 0x00, 0x00, 0xe0, 0xbc, 0xf1, 0xf5, 0xf7, +]; // 109 bytes + // jpeg: a frame header whose component list runs past its segment (found by a later fuzz round). +const JPEG_SOF_COMPONENT_LIST_PAST_SEGMENT: &[u8] = &[ + 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0a, 0x08, 0x06, 0x00, 0x00, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x00, 0x00, 0x06, 0x00, 0x00, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, + 0x09, 0x00, 0x00, +]; // 35 bytes + +#[test] +fn flac_residual_order_exceeding_partition_is_rejected() { + let r = bounded("flac-residual", || { + transcode::flac::decode(FLAC_RESIDUAL_ORDER_TOO_LARGE).map(|_| ()) + }); + assert!(r.is_err(), "expected Err, got {r:?}"); +} + +#[test] +fn jpeg_frame_component_list_past_segment_is_rejected() { + let r = bounded("jpeg-sof-list", || { + transcode::jpeg::decode(JPEG_SOF_COMPONENT_LIST_PAST_SEGMENT).map(|_| ()) + }); + assert!(r.is_err(), "expected Err, got {r:?}"); +} + +// jpeg: a zero sampling factor divided by zero in the block layout (crash-f93b6422fd7d28ab3e4c14566767f1434add5866). +const JPEG_ZERO_SAMPLING_FACTOR: &[u8] = &[ + 0xff, 0xd8, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x00, 0x00, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, + 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, + 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, + 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, + 0x93, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, + 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x93, 0x93, 0x93, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, + 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0xff, 0xd8, 0xff, 0xda, 0x00, + 0x10, 0x03, 0xff, 0xb1, 0xb1, 0x3b, 0xb1, 0xb1, 0x52, 0xb1, 0x69, 0xb1, 0xb1, 0xb1, 0xb1, 0x53, + 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, + 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, + 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, + 0x2b, 0x53, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, + 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, + 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, 0x01, + 0x2c, 0x09, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, + 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x93, 0x93, + 0x93, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, + 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, + 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, + 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, + 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, + 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, + 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, + 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, + 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, + 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x93, 0x93, 0x93, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, + 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, + 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, + 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, + 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, + 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, + 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, + 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x93, 0x93, 0x93, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, + 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, + 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, + 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x10, 0x01, 0x00, 0x01, + 0x2c, 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x01, 0x2c, + 0x09, 0x53, 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x09, 0x53, + 0x53, 0x2b, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xff, 0xd8, 0xff, 0xc0, + 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x53, 0x53, 0x53, 0x53, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x7e, 0x53, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xb3, 0x93, 0x93, 0x93, 0x93, 0x93, 0x53, 0x53, + 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x7e, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, + 0x53, 0x53, 0xb3, 0x53, 0x53, 0x53, 0x00, 0x53, 0x00, 0x53, 0x53, 0x53, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2b, 0x00, +]; // 1365 bytes + // flac: a predictor sum overflowed i64 in a debug build (crash-55b90e93dbf16b1b6e622d977a3587deea74ddd4). +const FLAC_PREDICTOR_OVERFLOW: &[u8] = &[ + 0x66, 0x4c, 0x61, 0x43, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0xb4, 0x00, 0x00, 0xff, 0xff, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, + 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, + 0xfb, 0x1f, 0xe0, 0xbc, 0xf1, 0xfd, 0xf7, +]; // 103 bytes + +#[test] +fn jpeg_zero_sampling_factor_is_rejected() { + let r = bounded("jpeg-sampling", || { + transcode::jpeg::decode(JPEG_ZERO_SAMPLING_FACTOR).map(|_| ()) + }); + assert!(r.is_err(), "expected Err, got {r:?}"); +} + +#[test] +fn flac_predictor_overflow_does_not_panic() { + let r = bounded("flac-overflow", || { + transcode::flac::decode(FLAC_PREDICTOR_OVERFLOW).map(|_| ()) + }); + assert!(r.is_ok() || r.is_err(), "decoder returned"); +} + +// jpeg: entropy bits requested past the end of the scan underflowed the bit count (crash-a55adcd08b74917193cac8ae9c35c20eecfbeddb). +const JPEG_BITS_PAST_SCAN_END: &[u8] = &[ + 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xf7, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, + 0x00, 0xe3, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, + 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0xbe, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xd8, 0x00, 0x20, 0x00, + 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2d, 0x14, 0x00, 0xff, + 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x14, 0x00, 0x32, 0x00, + 0x47, 0x47, 0x47, 0xff, 0xd8, 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xd8, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, + 0xc4, 0x00, 0x02, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2d, 0x14, 0x00, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, + 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x14, 0x00, 0x32, 0x00, 0x47, 0x47, 0x47, 0xff, 0xd8, + 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x06, 0x10, 0x04, + 0x00, 0xb1, 0xb1, 0x01, 0xff, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0x01, 0xff, 0x01, + 0x27, 0xff, 0x40, 0x60, 0xb1, 0xb1, 0x52, 0xb1, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xd8, + 0xf7, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0xeb, 0x23, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x32, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb1, 0xb1, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xf7, 0xc4, 0x00, 0x02, 0xff, + 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, + 0x02, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0xd8, 0xf7, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x01, 0x35, 0x00, 0x00, 0x20, 0x00, 0xbe, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xc8, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0xeb, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, + 0x00, 0x24, 0x23, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0x08, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, + 0xb1, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd7, + 0x97, 0x97, 0x97, 0x81, 0x81, 0x81, 0x97, 0x97, 0x97, 0x97, 0x97, 0xb7, 0x97, 0x97, 0x9f, 0x97, + 0x97, 0x00, 0x00, 0x47, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, + 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0x02, 0x8a, 0x00, 0x00, 0xd8, 0x00, 0x00, 0xc4, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x40, 0x01, 0x00, 0x1d, 0x00, + 0x00, 0x00, 0x97, 0x97, 0x00, 0x00, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0x00, 0x00, 0x00, 0xff, + 0xd2, 0xff, 0xff, 0x2b, 0xff, 0xc4, 0x1d, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xd8, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x69, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x77, 0x02, 0x14, 0xbc, 0x00, +]; // 1454 bytes + // flac: a fourth-order predictor overflowed i64 in a debug build (crash-1bcb5d256f9f7d65cf2f069d282994e6563e22b0). +const FLAC_ORDER4_PREDICTOR_OVERFLOW: &[u8] = &[ + 0x66, 0x4c, 0x61, 0x43, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xff, 0x00, + 0x00, 0x00, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0e, 0x00, 0x47, 0xff, 0x66, 0x4c, 0x43, 0x00, + 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x0e, 0x00, 0x47, 0xff, 0x66, 0x4c, 0x66, 0x4c, 0x61, 0x43, 0x00, 0xb7, 0x61, + 0x00, +]; // 65 bytes + +#[test] +fn jpeg_bits_past_scan_end_do_not_underflow() { + let r = bounded("jpeg-bits", || { + transcode::jpeg::decode(JPEG_BITS_PAST_SCAN_END).map(|_| ()) + }); + assert!(r.is_err() || r.is_ok(), "decoder returned"); +} + +#[test] +fn flac_order4_predictor_overflow_does_not_panic() { + let r = bounded("flac-order4", || { + transcode::flac::decode(FLAC_ORDER4_PREDICTOR_OVERFLOW).map(|_| ()) + }); + assert!(r.is_err() || r.is_ok(), "decoder returned"); +} + +// jpeg: a DC predictor sum overflowed i32 in a debug build (crash-7fdbea6f3b9200ded467923346b14f71bec6da5f). +const JPEG_DC_PREDICTOR_OVERFLOW: &[u8] = &[ + 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x20, 0x00, 0xff, 0x2c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, + 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0xbe, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, + 0xff, 0xd8, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xd8, 0xff, 0xc4, + 0x00, 0x02, 0xff, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, + 0x01, 0x2d, 0x14, 0x00, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, + 0x2c, 0x14, 0x00, 0x32, 0x00, 0x47, 0x47, 0x47, 0xff, 0xd8, 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x06, 0x10, 0x04, 0x00, 0xb1, 0xb1, 0x01, 0xff, 0x01, + 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xb1, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x0f, 0x0f, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xb1, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x00, + 0x47, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xbd, 0xbd, 0xbd, + 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, + 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, + 0xd8, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, + 0xd8, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0x00, 0x05, 0xc4, 0x00, 0x02, 0xd8, 0x01, 0x00, 0x01, + 0x2d, 0x14, 0x00, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, + 0x14, 0x00, 0x31, 0x00, 0x47, 0x47, 0x47, 0xff, 0xd8, 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x06, 0x10, 0x04, 0x00, 0xb1, 0xb1, 0x01, 0xff, 0x01, 0x01, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xb1, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, + 0x81, 0xb1, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x00, 0x47, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0xbe, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, + 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x77, 0x02, 0x14, 0xbc, 0x00, +]; // 828 bytes + // flac: a block size not divisible by its residual partition count produced a short frame (crash-5846bc26ba379351f14c80dc65dafc6cf3639966). +const FLAC_PARTITION_NOT_DIVISIBLE: &[u8] = &[ + 0x66, 0x4c, 0x61, 0x43, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0x6b, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, + 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, + 0x6b, 0x65, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x00, 0x00, + 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xb4, 0x92, 0x92, + 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x6b, 0x6b, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x30, + 0x10, 0x10, 0x31, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x6b, 0x6b, 0x6b, + 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xb4, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x31, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f, 0x92, 0x92, 0x6b, + 0x6b, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x31, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x00, 0x1f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7b, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, + 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x56, 0xf1, 0xfd, 0x00, +]; // 665 bytes + +#[test] +fn jpeg_dc_predictor_overflow_does_not_panic() { + let r = bounded("jpeg-dc", || { + transcode::jpeg::decode(JPEG_DC_PREDICTOR_OVERFLOW).map(|_| ()) + }); + assert!(r.is_err() || r.is_ok(), "decoder returned"); +} + +#[test] +fn flac_partition_not_divisible_is_rejected() { + let r = bounded("flac-partition", || { + transcode::flac::decode(FLAC_PARTITION_NOT_DIVISIBLE).map(|_| ()) + }); + assert!(r.is_err(), "expected Err, got {r:?}"); +} + +// jpeg: a receive value wider than its EXTEND size overflowed i32 in debug builds (crash-fd879add67957e82561c3e1a78d45c93ee4f7e94). +const JPEG_EXTEND_WIDE_VALUE: &[u8] = &[ + 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, + 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0xbe, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0xff, 0xd8, 0x34, 0x05, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc4, 0x00, 0x02, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x65, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xd8, + 0xff, 0xc4, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0xbe, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, + 0xff, 0xd8, 0x00, 0x20, 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xd8, 0xff, 0xc4, + 0x00, 0x02, 0xff, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, + 0x01, 0x2d, 0x14, 0x00, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, + 0x2c, 0x14, 0x00, 0x35, 0x02, 0x47, 0x47, 0x47, 0xff, 0xd8, 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x10, 0x2e, 0x06, 0x10, 0x04, 0x00, 0xb1, 0xb1, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xd8, 0x00, 0x20, + 0x00, 0x00, 0x00, 0xff, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xd8, 0xff, 0xc4, 0x00, 0x02, 0xff, 0xff, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2d, 0x14, + 0x00, 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x14, 0x00, + 0x32, 0x02, 0x47, 0x47, 0x47, 0xff, 0xd8, 0xff, 0xda, 0x00, 0x8d, 0x05, 0x00, 0x00, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x69, 0x0b, 0x08, 0x00, 0x10, 0x01, 0x00, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x34, 0x05, 0x0a, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0x77, 0x02, 0x14, 0xbc, 0x00, +]; // 870 bytes + +#[test] +fn jpeg_extend_wide_value_does_not_panic() { + let r = bounded("jpeg-extend", || { + transcode::jpeg::decode(JPEG_EXTEND_WIDE_VALUE).map(|_| ()) + }); + assert!(r.is_err() || r.is_ok(), "decoder returned"); +} + #[test] fn jpeg_scan_before_frame_header_is_rejected() { let r = bounded("jpeg-scan", || { From 4d1e1ef46fda2eda3044d75694a35a3cc1126237 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 00:46:24 +0000 Subject: [PATCH 2/4] docs: patents and licensing section, as an open item README.md carries the patents and licensing section, and docs/OPENSSF.md carries it as the open item. The text is unresolved: it says the crate must not be described as patent-free, and that maintainers need counsel's decision before it is distributed. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Ch6Crfubj3FwdxR7ywn9vT --- README.md | 17 +++-------------- docs/OPENSSF.md | 6 ++---- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0bdc9ac..3a7f5ee 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,9 @@ partial or encode-only. The per-format table below and [ROADMAP.md](ROADMAP.md) authoritative status. Nothing here is a claim of conformance with a specification beyond what the tests check. -## Patents and licensing: open decision - -**This section must be read before the crate is distributed.** It is not resolved. - -- Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are - the main examples, and both are licensed through patent pools. MP3 patents have largely - expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264 here, so the same - questions apply to their output. Container licensing has not been reviewed. -- AV1 is described by its licensors as royalty-free under published terms. That is not the same - as a statement that no patent applies. -- Nothing in this repository is a patent search, a licensing opinion, or a grant of patent - rights. Do not describe the crate as patent-free. -- Maintainers need to decide, with counsel, whether and how these codecs are published. That - decision is tracked as an open item in [docs/OPENSSF.md](docs/OPENSSF.md). +## Patents and licensing + +This section must be read before the crate is distributed. It is not resolved. Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264 here, so the same questions apply to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms. That is not the same as a statement that no patent applies. Nothing in this repository is a patent search, a licensing opinion, or a grant of patent rights. Do not describe the crate as patent-free. Maintainers need to decide, with counsel, whether and how these codecs are published. That decision is tracked as an open item in docs/OPENSSF.md. ## What works today diff --git a/docs/OPENSSF.md b/docs/OPENSSF.md index 01653f6..3da5c79 100644 --- a/docs/OPENSSF.md +++ b/docs/OPENSSF.md @@ -48,10 +48,8 @@ been created or recorded here. 1. **CODEOWNERS.** Resolved. `.github/CODEOWNERS` lists `@twn-lloyd @yokoszn`, two human owners, as the owners instructed. The ruleset still needs applying (item 6). No bot accounts are listed. -2. **Patents and standards.** The per-format position is in docs/STANDARDS.md. Every row is still - unverified against its primary source, and H.264, AAC, MP3 and the containers that carry them - need counsel's review before publication. **Human** -4. **Contacts.** Resolved. SECURITY.md lists security@twn.systems and CODE_OF_CONDUCT.md lists +2. **Patents and licensing (open).** This section must be read before the crate is distributed. It is not resolved. Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264 here, so the same questions apply to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms. That is not the same as a statement that no patent applies. Nothing in this repository is a patent search, a licensing opinion, or a grant of patent rights. Do not describe the crate as patent-free. Maintainers need to decide, with counsel, whether and how these codecs are published. That decision is tracked as an open item in docs/OPENSSF.md. +3. **Contacts.** Resolved. SECURITY.md lists security@twn.systems and CODE_OF_CONDUCT.md lists hello@twn.systems, alongside GitHub private reporting. 5. **Visibility.** The repository is private. Scorecard publishing, the badges and dependency-review on private repositories (which needs GitHub Advanced Security) depend on this. From 0b520cc8f4d9c88431759d3afacac15745e3385d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 01:55:22 +0000 Subject: [PATCH 3/4] docs: resolve the patents item as a published disclosure The patents and licensing section no longer reads as an open decision. The crate is published under Apache-2.0 with no patent search or counsel review, and the README states that and says users must check the position that applies to them. The section no longer tells readers the crate must not be distributed, and it makes no claim that the crate is patent-free. Claude-Session: https://claude.ai/code/session_01Ch6Crfubj3FwdxR7ywn9vT --- README.md | 4 +++- docs/OPENSSF.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a7f5ee..b9d3c7d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,9 @@ the tests check. ## Patents and licensing -This section must be read before the crate is distributed. It is not resolved. Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264 here, so the same questions apply to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms. That is not the same as a statement that no patent applies. Nothing in this repository is a patent search, a licensing opinion, or a grant of patent rights. Do not describe the crate as patent-free. Maintainers need to decide, with counsel, whether and how these codecs are published. That decision is tracked as an open item in docs/OPENSSF.md. +The source is published under the Apache License, Version 2.0 (see [License](#license)). No patent search, licensing opinion or counsel review has been carried out for the formats in this crate. Several of them are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools; royalties can apply. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264, so the same applies to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms, which is not the same as a statement that no patent applies. + +This repository grants no patent rights beyond those in the Apache License, Version 2.0, and that licence covers only patents held by contributors in respect of their own contributions. Anyone who distributes or uses an encoder or decoder for these formats is responsible for checking the patent and licence position that applies to them. The crate makes no claim that it is free of patent encumbrance. ## What works today diff --git a/docs/OPENSSF.md b/docs/OPENSSF.md index 3da5c79..a0e0652 100644 --- a/docs/OPENSSF.md +++ b/docs/OPENSSF.md @@ -48,7 +48,7 @@ been created or recorded here. 1. **CODEOWNERS.** Resolved. `.github/CODEOWNERS` lists `@twn-lloyd @yokoszn`, two human owners, as the owners instructed. The ruleset still needs applying (item 6). No bot accounts are listed. -2. **Patents and licensing (open).** This section must be read before the crate is distributed. It is not resolved. Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264 here, so the same questions apply to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms. That is not the same as a statement that no patent applies. Nothing in this repository is a patent search, a licensing opinion, or a grant of patent rights. Do not describe the crate as patent-free. Maintainers need to decide, with counsel, whether and how these codecs are published. That decision is tracked as an open item in docs/OPENSSF.md. +2. **Patents and licensing.** Resolved as a disclosure. The maintainers chose to publish under Apache-2.0 with no patent search or counsel review, and the README states that. The patent and licence position of each format is listed in the README and in docs/STANDARDS.md. Users are responsible for checking the position that applies to them. 3. **Contacts.** Resolved. SECURITY.md lists security@twn.systems and CODE_OF_CONDUCT.md lists hello@twn.systems, alongside GitHub private reporting. 5. **Visibility.** The repository is private. Scorecard publishing, the badges and From e6efc9c040435dcb8dfe94d2dcea06ccceaa664d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 02:43:49 +0000 Subject: [PATCH 4/4] docs: state the patent position of each format and drop the review gate The README and docs/STANDARDS.md now say what the licence covers, which formats are in patent pools, and that publishing source does not license third-party patents. The counsel review gate is removed. Every module stays published. The Source check column records which rows were read only in secondary sources. Claude-Session: https://claude.ai/code/session_01Ch6Crfubj3FwdxR7ywn9vT --- CHANGELOG.md | 2 ++ README.md | 26 ++++++++++++++++------- docs/OPENSSF.md | 2 +- docs/STANDARDS.md | 54 ++++++++++++++++++++++++++++------------------- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a7427..ebad166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,11 @@ All notable changes to this project are documented here. The format follows - The binary uses the library's codec modules instead of compiling its own copies. - `Cargo.toml` records the license, repository, readme and keywords, and sets `rust-version = 1.89`. - The library and binary are built with `#![forbid(unsafe_code)]`. +- README and docs/STANDARDS.md state the patent position of each format. The licence grants no rights under third-party patents. ### Fixed +- The JPEG and FLAC decoders no longer panic or allocate without bound on malformed input; regression tests are in `tests/fuzz_regressions.rs`. - Debug builds no longer panic on the AV1 boolean and coefficient decoding paths. Release output is unchanged. - Malformed input can no longer make the decoders panic, hang or over-allocate. Four cases found diff --git a/README.md b/README.md index b9d3c7d..5b1b40a 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,19 @@ the tests check. ## Patents and licensing -The source is published under the Apache License, Version 2.0 (see [License](#license)). No patent search, licensing opinion or counsel review has been carried out for the formats in this crate. Several of them are covered by patents in some jurisdictions. H.264 and AAC are the main examples, and both are licensed through patent pools; royalties can apply. MP3 patents have largely expired, but the position varies by country. The MP4, MKV and HEIF writers carry H.264, so the same applies to their output. Container licensing has not been reviewed. AV1 is described by its licensors as royalty-free under published terms, which is not the same as a statement that no patent applies. +transcode is licensed under the Apache License, Version 2.0. The licence covers this code. It does +not license anyone under another party's patents. -This repository grants no patent rights beyond those in the Apache License, Version 2.0, and that licence covers only patents held by contributors in respect of their own contributions. Anyone who distributes or uses an encoder or decoder for these formats is responsible for checking the patent and licence position that applies to them. The crate makes no claim that it is free of patent encumbrance. +Several formats in this crate are covered by patents in some jurisdictions. H.264 and AAC are +licensed through patent pools (Via LA), and royalties can apply to products that ship an encoder or +decoder for them. The MP4, MKV and HEIF writers carry H.264, so the same applies to their output. +MP3's licensing program ended in 2017, and AV1 is offered royalty-free under AOMedia's published +terms. [docs/STANDARDS.md](docs/STANDARDS.md) has the position for every format, with sources and +how each was checked. + +Publishing source does not remove the need for a patent licence in a product. If you ship software +that includes these codecs, you are responsible for the licences it needs. All modules in this +repository are published. ## What works today @@ -48,14 +58,14 @@ understood for each one, with a link to check it. - **Described as royalty-free by their publishers:** PNG (W3C), FLAC (Xiph), Opus (IETF RFC 6716), AV1 (AOMedia royalty-free patent licence), WebP (Google royalty-free patent licence). -- **Patent-pool or unclear:** H.264 and AAC (patent pools; royalties can apply), MP3 (core patents - understood to have expired, but the position varies by country), and JPEG (baseline understood - to be royalty-free; to be confirmed). +- **Patent-pool:** H.264 and AAC (Via LA pools; royalties can apply to products). +- **Patents expired or understood royalty-free:** MP3 (licensing program ended April 2017; other + jurisdictions not checked) and baseline JPEG. - **Containers:** the MP4, Matroska and HEIF writers carry H.264 here, so the H.264 position applies to their output. The Motion-JPEG AVI writer is not an ISO standard and was not reviewed. -An open standard is not automatically royalty-free. The publication status of each row has not -been checked against its primary source yet; see the "Verified" column in docs/STANDARDS.md. +An open standard is not automatically royalty-free. Several rows were checked only against +secondary sources; see the "Source check" column in docs/STANDARDS.md. This crate is a codec implementation. It is not certified against any conformance suite and is not a licensed product from any codec vendor. @@ -131,4 +141,4 @@ an external-decoder check where one exists, and a note on patent status for revi Apache License, Version 2.0. See [LICENSE](LICENSE). The licence covers this code only. It grants no rights under any patent that applies to a format -this crate decodes or encodes; see the patent note above. +this crate decodes or encodes; see [Patents and licensing](#patents-and-licensing). diff --git a/docs/OPENSSF.md b/docs/OPENSSF.md index a0e0652..c1d4829 100644 --- a/docs/OPENSSF.md +++ b/docs/OPENSSF.md @@ -48,7 +48,7 @@ been created or recorded here. 1. **CODEOWNERS.** Resolved. `.github/CODEOWNERS` lists `@twn-lloyd @yokoszn`, two human owners, as the owners instructed. The ruleset still needs applying (item 6). No bot accounts are listed. -2. **Patents and licensing.** Resolved as a disclosure. The maintainers chose to publish under Apache-2.0 with no patent search or counsel review, and the README states that. The patent and licence position of each format is listed in the README and in docs/STANDARDS.md. Users are responsible for checking the position that applies to them. +2. **Patents and licensing.** Resolved. The code is Apache-2.0, all modules are published, and the README and docs/STANDARDS.md state the patent position of each format and that the licence grants no rights under third-party patents. 3. **Contacts.** Resolved. SECURITY.md lists security@twn.systems and CODE_OF_CONDUCT.md lists hello@twn.systems, alongside GitHub private reporting. 5. **Visibility.** The repository is private. Scorecard publishing, the badges and diff --git a/docs/STANDARDS.md b/docs/STANDARDS.md index e3d5e4c..0139982 100644 --- a/docs/STANDARDS.md +++ b/docs/STANDARDS.md @@ -2,7 +2,7 @@ This page lists, for each format this crate decodes or encodes, the specification it follows, who publishes that specification, and what is understood about its licensing and patent position. -It is written so a maintainer or a counsel can check each row quickly. +Each row links to the source to check. ## Read this first @@ -12,39 +12,43 @@ It is written so a maintainer or a counsel can check each row quickly. - **This is a codec implementation, not a certified or licensed product.** Nothing here is conformance-certified, and no codec vendor has licensed this code. The crate writes and reads bytes; whether using those bytes needs a patent licence is a separate question. -- **Nothing here is legal advice.** Each row must be reviewed by counsel before the crate is - published or used commercially. See the decision list at the end. +- **Nothing here is legal advice.** It records what the maintainers understand, with sources. + Check the sources yourself before you ship a product built on these formats. See + [Using this code in a product](#using-this-code-in-a-product). ## Verification status -**The rows below were not verified against their primary sources in the session that wrote this -page.** Outbound DNS to the standards hosts (`www.w3.org`, `xiph.org`, `www.rfc-editor.org`, -`aomedia.org`, `developers.google.com`, `www.itu.int`, `via-la.com`, `www.matroska.org`) failed -from that environment. Each row gives the URL to check. Mark a row "verified" only after its -source has been read. +The "Source check" column says how each row was checked. + +- **Secondary** means the position was read in secondary sources (news reports, mailing-list and + forum posts quoting the licensor's FAQ). The licensor's own page was not read. +- **No** means the row has not been checked against any source. + +The primary hosts (`www.w3.org`, `xiph.org`, `www.rfc-editor.org`, `aomedia.org`, +`developers.google.com`, `www.itu.int`, `www.via-la.com`, `www.matroska.org`) could not be reached +from the environment that wrote this page. Each row gives the URL to check. ## Formats -| Format | Crate module(s) | Specification and body | Licensing and patent position (as understood) | Verified | +| Format | Crate module(s) | Specification and body | Licensing and patent position (as understood) | Source check | |---|---|---|---|---| | PNG, RGBA8, non-interlaced | `src/png.rs` | PNG Specification, Third Edition. W3C Recommendation, identified as ISO/IEC 15948 | Published by the W3C under its Patent Policy, which provides royalty-free licensing. Source: https://www.w3.org/TR/png-3/ | No | -| JPEG, baseline sequential | `src/jpeg.rs`, `src/mjpeg.rs` | ITU-T T.81, equivalent to ISO/IEC 10918-1. ITU-T and ISO/IEC JPEG committee | The specification is freely downloadable. Baseline JPEG is widely treated as royalty-free, and the main early patent claims are understood to have expired. Confirm with counsel. Source: https://www.itu.int/rec/T-REC-T.81 | No | +| JPEG, baseline sequential | `src/jpeg.rs`, `src/mjpeg.rs` | ITU-T T.81, equivalent to ISO/IEC 10918-1. ITU-T and ISO/IEC JPEG committee | The specification is freely downloadable. Baseline JPEG is widely treated as royalty-free, and the main early patent claims are understood to have expired. Source: https://www.itu.int/rec/T-REC-T.81 | No | | WebP, VP8L lossless | `src/webp.rs` | WebP Lossless Bitstream Specification. Google | Google states a royalty-free patent licence for WebP. The reference library, libwebp, is BSD-3-Clause. Source: https://developers.google.com/speed/webp/docs/webp-lossless-bitstream-specification and https://developers.google.com/speed/webp/faq | No | | RIFF WAVE, PCM | `src/main.rs`, `src/codec.rs` (CLI path) | RIFF/WAVE, as documented by Microsoft and IBM in the Multimedia Programming Interface and Data Specifications 1.0 (1991). No standards body | Not reviewed. The format is old and widely implemented; no licence requirement has been identified, but that has not been checked. | No | | FLAC | `src/flac.rs` | FLAC format specification. Xiph.Org Foundation | Documented by Xiph as free to use with no royalties; the reference implementation is BSD-licensed. Source: https://xiph.org/flac/format.html | No | | SLAC | `src/codec.rs` | This crate's own container. No external specification | Covered by this crate's licence. Nothing external to license. | Not applicable | -| MP3, Layer III decode | `src/mp3.rs` | ISO/IEC 11172-3 (MPEG-1 audio), ISO/IEC 13818-3 (MPEG-2 audio) | The core MP3 patents are understood to have expired in most jurisdictions, but the position varies by country, so this is not a clean grant. Confirm with counsel. Source: https://www.iso.org/standard/22412.html | No | -| AAC-LC in ADTS, encode and decode | `src/aac.rs`, `src/aac_tables.rs` | ISO/IEC 13818-7 (MPEG-2 AAC), ISO/IEC 14496-3 (MPEG-4 Audio) | Patents are licensed through the Via LA AAC patent pool. Royalties can apply. Source: https://via-la.com/licensing-programs/aac/ | No | +| MP3, Layer III decode | `src/mp3.rs` | ISO/IEC 11172-3 (MPEG-1 audio), ISO/IEC 13818-3 (MPEG-2 audio) | Fraunhofer and Technicolor ended their MP3 licensing program on 23 April 2017. Secondary sources report that the last US patent in the program expired on 16 April 2017 and that the core EU patents had expired by 2012. Other jurisdictions were not checked. Source: https://www.iso.org/standard/22412.html | Secondary | +| AAC-LC in ADTS, encode and decode | `src/aac.rs`, `src/aac_tables.rs` | ISO/IEC 13818-7 (MPEG-2 AAC), ISO/IEC 14496-3 (MPEG-4 Audio) | Patents are licensed through the Via LA AAC patent pool. Secondary sources quote Via LA's AAC FAQ as saying that manufacturers and developers of end-user encoder or decoder products need a licence, and that implementations, including open-source ones, may need licences from the patent holders. Royalties can apply. Source: https://via-la.com/licensing-programs/aac/ | Secondary | | Opus, Ogg demux and TOC parsing | `src/opus.rs`, `src/opus_tables.rs` | RFC 6716 (Opus codec), RFC 7845 (Ogg encapsulation). IETF | Opus is documented in the RFCs as royalty-free, with IPR declarations in the RFC record. Packet-to-PCM decode is not implemented. Sources: https://www.rfc-editor.org/rfc/rfc6716 and https://www.rfc-editor.org/rfc/rfc7845 | No | -| H.264 (AVC), Annex B, intra and P-skip encode | `src/h264.rs`, `src/h264_intra.rs`, `src/h264_inter.rs`, `src/h264_i4x4.rs`, `src/h264bits.rs`, `src/h264_cavlc_tables.rs` | ITU-T H.264, equivalent to ISO/IEC 14496-10 | Patents are licensed through the Via LA AVC patent pool. Royalties apply above the pool's thresholds, with stated exceptions. **This is the highest-risk row in this crate.** Source: https://via-la.com/licensing-programs/avc/ and https://www.itu.int/rec/T-REC-H.264 | No | +| H.264 (AVC), Annex B, intra and P-skip encode | `src/h264.rs`, `src/h264_intra.rs`, `src/h264_inter.rs`, `src/h264_i4x4.rs`, `src/h264bits.rs`, `src/h264_cavlc_tables.rs` | ITU-T H.264, equivalent to ISO/IEC 14496-10 | Patents are licensed through the Via LA AVC patent pool. Royalties apply above the pool's thresholds, with stated exceptions. Publishing source code does not license the patents: Cisco released OpenH264 under the BSD licence, covers the pool royalties only for the binaries it distributes, and tells others to get their own licence. **This is the row with the most patent exposure in this crate.** Source: https://via-la.com/licensing-programs/avc/ and https://www.itu.int/rec/T-REC-H.264 | Secondary | | AV1, keyframe OBU encode | `src/av1_obu.rs`, `src/av1_frame.rs`, `src/av1_intra.rs`, `src/av1_coef.rs`, `src/av1_coef_tables.rs`, `src/av1_ec.rs`, `src/av1_dct.rs` | AV1 Bitstream and Decoding Process Specification. Alliance for Open Media (AOMedia) | AOMedia publishes a royalty-free patent licence for AV1. Its terms include a termination condition if a licensee sues over AV1. A royalty-free licence is not a statement that no patent applies. Source: https://aomedia.org/license/patent-license/ | No | | MP4 writer | `src/mp4.rs` | ISO/IEC 14496-12 (ISO base media file format), ISO/IEC 14496-14 (MP4 file format) | Container only. Not reviewed. The writer carries H.264 by default, so the H.264 row applies to its output. | No | | Matroska (MKV) writer | `src/mkv.rs` | Matroska specification. matroska.org | Container only. The licence of the published specification was not verified. The writer carries H.264, so the H.264 row applies to its output. Source: https://www.matroska.org/technical/specs/index.html | No | | HEIF writer | `src/heif.rs` | ISO/IEC 23008-12 (HEIF). ISO/IEC | Container only. The image coding here is H.264, so the H.264 row applies to its output. Not reviewed beyond that. | No | | Motion JPEG in AVI | `src/mjpeg.rs` | RIFF AVI, as documented by Microsoft. Frames are JPEG (ITU-T T.81) | AVI is not an ISO standard and its licence was not reviewed. The JPEG frames follow the JPEG row. | No | -Two formats named in the repository description are **not implemented** in this source tree: -NIfTI and HDF5. This page does not cover them. Do not cite them as supported. +NIfTI and HDF5 are **not implemented** in this source tree and are not covered here. ## What the licence covers @@ -52,11 +56,17 @@ The crate's own code is licensed under the Apache License, Version 2.0 (`LICENSE `license = "Apache-2.0"` in `Cargo.toml`). That licence covers this code only. It grants no rights under any patent that applies to a format above. -## Decisions for the owners +## Using this code in a product + +Publishing this source under Apache-2.0 does not license anyone under another party's patents. +That is true of every open-source codec, and it is the position Cisco's OpenH264 states. -1. **Patent review (H.264, AAC, and the MP4, MKV and HEIF writers that carry H.264).** Counsel must - review each row before the crate is published. Until then the README must not describe the - crate as patent-free. -2. **MP3 and JPEG.** Confirm the expiry dates and jurisdictions with counsel. -3. **Verification of every row.** Read each primary source above and mark the "Verified" column. -4. **Publication.** Whether to publish any encoder that writes H.264 or AAC at all. +- **Using the source or the library.** You are responsible for the patent licences your own product + needs. For H.264 and AAC, check with the patent pool (Via LA) before you ship an encoder or + decoder to end users. +- **Formats without a pool.** PNG, WebP, FLAC, Opus and AV1 are published by their authors under + royalty-free terms (see the rows above). Those terms still carry conditions. Read them. +- **Containers.** The MP4, Matroska and HEIF writers carry H.264 here, so the H.264 row applies to + their output. +- **No code is withheld.** All modules in this repository are published. Which codecs you build + in, or ship, is your decision.