diff --git a/API.md b/API.md index e8facc2..5754a18 100644 --- a/API.md +++ b/API.md @@ -140,14 +140,18 @@ Notes: - `max_pixels` checks AV1 and HEVC coded frame area before pixel decoding, including auxiliary alpha frames and HEIC grid tiles. Container dimensions and post-decode geometry checks still apply. -- Auxiliary alpha must match the primary geometry. HEVC conformance-window - padding is allowed up to the coded block boundary; cropping cannot hide an - oversized coded frame. +- Auxiliary alpha must match the primary's visible geometry. Its coded frame, + including any conformance-window padding, counts against `max_pixels` and + the decoded-byte allowance below, so cropping cannot hide an oversized coded + frame. - HEVC preflight estimates decoded planes and normalized bitstream storage. The byte allowance is 12 bytes per allowed pixel plus 64 MiB, with the primary area limiting auxiliary frames and the composed output area limiting - grids. Every grid tile, including the first, and the sum of all tile estimates - must fit this allowance. This estimate is not a process RSS limit. + grids. A grid dimension covered by a single tile row or column counts as at + least 512 pixels when tiles are stacked along the other dimension, matching + the fixed tile span encoders use for narrow images. Every grid tile, + including the first, and the sum of all tile estimates must fit this + allowance. This estimate is not a process RSS limit. ## Error Handling Contract diff --git a/src/av1_geometry.rs b/src/av1_geometry.rs index 4feee99..4a6b448 100644 --- a/src/av1_geometry.rs +++ b/src/av1_geometry.rs @@ -34,9 +34,6 @@ pub(crate) fn coded_dimensions(mut bytes: &[u8]) -> Result> { let mut sequence = None; while !bytes.is_empty() { let header = bytes[0]; - if header & 0x81 != 0 { - return Err(invalid()); - } let kind = (header >> 3) & 15; let mut offset = 1; let extension = if header & 4 != 0 { @@ -243,4 +240,29 @@ mod tests { assert!(coded_dimensions(&bytes).is_err()); } } + + #[test] + fn obu_header_forbidden_and_reserved_bits_are_ignored_like_the_decoder() { + let obus = |sequence_header: u8, frame_header: u8| { + vec![ + sequence_header, + 0x04, + 0x18, + 0x00, + 0x00, + 0x15, + frame_header, + 0x01, + 0x00, + ] + }; + let expected = coded_dimensions(&obus(0x0a, 0x1a)).unwrap(); + assert!(expected.is_some()); + for (sequence_header, frame_header) in [(0x0b, 0x1a), (0x0a, 0x1b), (0x8a, 0x9a)] { + assert_eq!( + coded_dimensions(&obus(sequence_header, frame_header)).unwrap(), + expected + ); + } + } } diff --git a/src/geometry.rs b/src/geometry.rs index cd2aa46..2c44742 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -32,6 +32,14 @@ fn single_span_tile_extent(output_extent: u32, alignment: u32, stacks_tiles: boo } } +fn grid_budget_extent(output_extent: u32, spans: u16, other_spans: u16) -> u64 { + if spans == 1 && other_spans > 1 { + u64::from(output_extent).max(GRID_SINGLE_SPAN_TILE_EXTENT_LIMIT) + } else { + u64::from(output_extent) + } +} + fn byte_limit(stage: &'static str, actual_bytes: u64, max_decoded_bytes: u64) -> DecodeError { DecodeGuardrailError::DecodedByteCountExceeded { stage, @@ -74,20 +82,12 @@ fn check_sps( sps.pic_width_in_luma_samples, sps.pic_height_in_luma_samples, )?; - if let Some((width, height)) = expected { - if (metadata.width, metadata.height) != (width, height) { - return Err(invalid( - "auxiliary HEVC geometry does not match primary image", - )); - } - let alignment = sps.ctb_size(); - if u64::from(sps.pic_width_in_luma_samples) > padded_extent(width, alignment) - || u64::from(sps.pic_height_in_luma_samples) > padded_extent(height, alignment) - { - return Err(invalid( - "auxiliary HEVC coded geometry exceeds primary image padding", - )); - } + if let Some(expected) = expected + && (metadata.width, metadata.height) != expected + { + return Err(invalid( + "auxiliary HEVC geometry does not match primary image", + )); } Ok(estimate_heic_grid_sps_decode_bytes(sps)?) } @@ -140,11 +140,17 @@ pub(super) fn preflight_grid( validate_heic_grid_descriptor_and_tile_count(grid)?; let descriptor = &grid.descriptor; guardrails.enforce_pixel_count(descriptor.output_width, descriptor.output_height)?; - let output_pixels = u64::from(descriptor.output_width) * u64::from(descriptor.output_height); + let budget_pixels = + grid_budget_extent(descriptor.output_width, descriptor.columns, descriptor.rows) + * grid_budget_extent( + descriptor.output_height, + descriptor.rows, + descriptor.columns, + ); let pixel_budget = guardrails .max_pixels - .unwrap_or(output_pixels) - .min(output_pixels); + .unwrap_or(budget_pixels) + .min(budget_pixels); let decoded_budget = decoded_byte_budget(pixel_budget); let mut aggregate = 0u64; for tile in &grid.tiles { @@ -197,7 +203,7 @@ pub(super) fn preflight_grid( "HEVC tile coded geometry exceeds visible geometry padding", )); } - for transform in &tile.transforms { + for transform in tile.transforms.iter() { if let isobmff::PrimaryItemTransformProperty::Rotation(rotation) = transform && rotation.rotation_ccw_degrees % 180 == 90 { diff --git a/src/geometry_tests.rs b/src/geometry_tests.rs index 8a44362..76a6314 100644 --- a/src/geometry_tests.rs +++ b/src/geometry_tests.rs @@ -259,9 +259,9 @@ fn grid_fixture() -> isobmff::HeicGridPrimaryItemData { tiles: vec![isobmff::HeicGridTileItemData { item_id: 1, construction_method: 1, - hvcc, + hvcc: hvcc.into(), colr: Default::default(), - transforms: vec![], + transforms: Default::default(), payload: hevc_payload(), }], } @@ -458,20 +458,19 @@ fn avif_auxiliary_container_geometry_is_checked_before_backend() { #[test] fn heic_grid_tile_crop_cannot_hide_oversized_coded_frame() { let mut grid = grid_fixture(); - grid.tiles[0] - .transforms - .push(isobmff::PrimaryItemTransformProperty::CleanAperture( - isobmff::ImageCleanApertureProperty { - clean_aperture_width_num: 16, - clean_aperture_width_den: 1, - clean_aperture_height_num: 16, - clean_aperture_height_den: 1, - horizontal_offset_num: 0, - horizontal_offset_den: 1, - vertical_offset_num: 0, - vertical_offset_den: 1, - }, - )); + grid.tiles[0].transforms = [isobmff::PrimaryItemTransformProperty::CleanAperture( + isobmff::ImageCleanApertureProperty { + clean_aperture_width_num: 16, + clean_aperture_width_den: 1, + clean_aperture_height_num: 16, + clean_aperture_height_den: 1, + horizontal_offset_num: 0, + horizontal_offset_den: 1, + vertical_offset_num: 0, + vertical_offset_den: 1, + }, + )] + .into(); let (result, largest) = tracked(|| decode_primary_heic_grid_to_image(&grid)); assert!(result.is_err()); assert!( @@ -494,7 +493,8 @@ fn heic_grid_checks_later_tiles_before_decoding_first_tile() { second.item_id = 3; second.hvcc = isobmff::parse_boxes(&config).unwrap()[0] .parse_hvcc() - .unwrap(); + .unwrap() + .into(); grid.tile_item_ids.push(3); grid.tiles.push(second); let (result, largest) = tracked(|| decode_primary_heic_grid_to_image(&grid)); @@ -511,7 +511,8 @@ fn heic_grid_checks_replacement_sps_in_payload() { let config = hevc_configuration(small_hevc_sps()); grid.tiles[0].hvcc = isobmff::parse_boxes(&config).unwrap()[0] .parse_hvcc() - .unwrap(); + .unwrap() + .into(); let replacement = large_hevc_sps(); grid.tiles[0].payload = [ &(replacement.len() as u32).to_be_bytes()[..], @@ -825,7 +826,8 @@ fn grid_with_filler(tile_count: u16, filler_bytes: usize) -> isobmff::HeicGridPr let config = hevc_configuration(small_hevc_sps()); grid.tiles[0].hvcc = isobmff::parse_boxes(&config).unwrap()[0] .parse_hvcc() - .unwrap(); + .unwrap() + .into(); let mut filler = vec![0xffu8; filler_bytes]; filler[..2].copy_from_slice(&[0x4c, 0x01]); *filler.last_mut().unwrap() = 0x80; @@ -1139,9 +1141,10 @@ fn grid_tile_streams_with_hidden_parameter_sets_decode_strictly() { construction_method: 1, hvcc: isobmff::parse_boxes(&config).unwrap()[0] .parse_hvcc() - .unwrap(), + .unwrap() + .into(), colr: Default::default(), - transforms: vec![], + transforms: Default::default(), payload: hevc_payload(), }; let (decoded, largest) = tracked(|| crate::decode_heic_grid_tile_to_image(&tile).unwrap()); @@ -1356,9 +1359,9 @@ fn tiled_grid( let first = isobmff::HeicGridTileItemData { item_id: 1, construction_method: 1, - hvcc, + hvcc: hvcc.into(), colr: Default::default(), - transforms: vec![], + transforms: Default::default(), payload: hevc_payload(), }; let tile_count = u32::from(columns) * u32::from(rows); @@ -1424,3 +1427,77 @@ fn heic_grid_single_tile_keeps_the_padded_extent_bound() { let grid = tiled_grid(1, 1, (300, 8000), sps); assert!(geometry::preflight_grid(&grid, &DecodeGuardrails::default()).is_err()); } + +#[test] +fn heic_grid_budget_counts_the_fixed_tile_span_of_narrow_grids() { + let sps = sps_with_tile_dimensions(512, 512); + for (columns, rows, output) in [ + (1u16, 59u16, (40u32, 30000u32)), + (59, 1, (30000, 40)), + (1, 79, (100, 40000)), + ] { + let grid = tiled_grid(columns, rows, output, sps.clone()); + assert!( + geometry::preflight_grid(&grid, &DecodeGuardrails::default()).is_ok(), + "{}x{} grid with output {}x{}", + columns, + rows, + output.0, + output.1 + ); + } +} + +#[test] +fn heic_grid_narrow_budget_stays_capped_by_max_pixels() { + let sps = sps_with_tile_dimensions(512, 512); + let grid = tiled_grid(1, 59, (40, 30000), sps); + let result = geometry::preflight_grid( + &grid, + &DecodeGuardrails { + max_pixels: Some(40 * 30000), + ..DecodeGuardrails::default() + }, + ); + assert!(matches!( + result, + Err(DecodeError::Guardrail( + DecodeGuardrailError::DecodedByteCountExceeded { + stage: "HEIC grid", + .. + } + )) + )); +} + +fn assert_alpha_ramp(input: &[u8], width: u32, height: u32, x_step: u32) { + let decoded = decode_bytes_to_rgba(input).unwrap(); + assert_eq!((decoded.width, decoded.height), (width, height)); + let DecodedRgbaPixels::U8(pixels) = decoded.pixels else { + panic!("expected 8-bit RGBA output"); + }; + for (index, pixel) in pixels.chunks_exact(4).enumerate() { + let (x, y) = (index as u32 % width, index as u32 / width); + let expected = x_step * x + y; + assert!( + u32::from(pixel[3]).abs_diff(expected) <= 2, + "alpha at ({x}, {y}) is {}, expected {expected}", + pixel[3] + ); + } +} + +#[test] +fn apple_monochrome_alpha_plane_decodes() { + assert_alpha_ramp( + include_bytes!("testdata/apple-alpha-192x64.heic"), + 192, + 64, + 1, + ); +} + +#[test] +fn apple_alpha_coded_at_the_minimum_frame_size_is_kept() { + assert_alpha_ramp(include_bytes!("testdata/apple-alpha-40x30.heic"), 40, 30, 5); +} diff --git a/src/heic-decoder/hevc/ctu.rs b/src/heic-decoder/hevc/ctu.rs index 77fb295..4cc595e 100644 --- a/src/heic-decoder/hevc/ctu.rs +++ b/src/heic-decoder/hevc/ctu.rs @@ -1848,6 +1848,9 @@ impl<'a> SliceContext<'a> { /// - If first bin is 1: read 2 fixed-length bypass bits → modes 0-3 /// - If candidate mode collides with luma mode → Angular34 fn decode_intra_chroma_mode(&mut self, luma_mode: IntraPredMode) -> Result { + if self.sps.chroma_array_type() == 0 { + return Ok(luma_mode); + } let ctx_idx = context::INTRA_CHROMA_PRED_MODE; let first_bin = self.cabac.decode_bin(&mut self.ctx[ctx_idx]); let intra_chroma_mode = if first_bin == 0 { diff --git a/src/isobmff.rs b/src/isobmff.rs index ea7f45c..d31dcfc 100644 --- a/src/isobmff.rs +++ b/src/isobmff.rs @@ -4,6 +4,7 @@ use std::collections::btree_map::Entry; use std::error::Error; use std::fmt::{Display, Formatter}; use std::mem::size_of; +use std::sync::Arc; const BASIC_HEADER_SIZE: usize = 8; const LARGE_SIZE_FIELD_SIZE: usize = 8; @@ -739,9 +740,9 @@ pub struct HeicGridDescriptor { pub struct HeicGridTileItemData { pub item_id: u32, pub construction_method: u8, - pub hvcc: HevcDecoderConfigurationBox, - pub colr: PrimaryItemColorProperties, - pub transforms: Vec, + pub hvcc: Arc, + pub colr: Arc, + pub transforms: Arc<[PrimaryItemTransformProperty]>, pub payload: Vec, } @@ -4615,7 +4616,8 @@ fn extract_primary_heic_item_data_with_grid_internal( } else { None }; - let mut property_cache = BTreeMap::new(); + let mut property_cache = GridTilePropertyCache::default(); + let mut tile_properties_by_item = BTreeMap::new(); let tile_payload_budget = source .as_ref() .map_or(input.len() as u64, |source| source.len()) @@ -4648,18 +4650,24 @@ fn extract_primary_heic_item_data_with_grid_internal( }); } - let tile_associations = associations_by_item - .get(&tile_item_id) - .map(Vec::as_slice) - .unwrap_or_default(); let (tile_hvcc, tile_colr, tile_transforms) = - resolve_grid_tile_hvcc_colr_and_transforms_indexed( - item_id, - tile_item_id, - tile_associations, - &flattened_properties, - &mut property_cache, - )?; + match tile_properties_by_item.entry(tile_item_id) { + Entry::Occupied(entry) => entry.into_mut(), + Entry::Vacant(entry) => { + let tile_associations = associations_by_item + .get(&tile_item_id) + .map(Vec::as_slice) + .unwrap_or_default(); + entry.insert(resolve_grid_tile_hvcc_colr_and_transforms_indexed( + item_id, + tile_item_id, + tile_associations, + &flattened_properties, + &mut property_cache, + )?) + } + } + .clone(); let tile_location = &resolved.iloc.items[*iloc_index.get(&tile_item_id).ok_or( ExtractHeicItemDataError::MissingGridTileLocation { @@ -4682,10 +4690,12 @@ fn extract_primary_heic_item_data_with_grid_internal( item_id, length: u64::MAX, })?; - if total_tile_payload_bytes > tile_payload_budget { + let total_tile_data_bytes = + total_tile_payload_bytes.saturating_add(property_cache.color_profile_bytes); + if total_tile_data_bytes > tile_payload_budget { return Err(ExtractHeicItemDataError::PayloadTooLarge { item_id, - length: total_tile_payload_bytes, + length: total_tile_data_bytes, }); } tiles.push(HeicGridTileItemData { @@ -4708,9 +4718,22 @@ fn extract_primary_heic_item_data_with_grid_internal( })) } +type GridTileProperties = ( + Arc, + Arc, + Arc<[PrimaryItemTransformProperty]>, +); + +#[derive(Default)] +struct GridTilePropertyCache { + properties: BTreeMap, + colors: BTreeMap<(Option, Option), Arc>, + color_profile_bytes: u64, +} + #[derive(Clone)] enum CachedGridProperty { - Hvcc(HevcDecoderConfigurationBox), + Hvcc(Arc), Colr(ColorInformationProperty), Transform(PrimaryItemTransformProperty), Ignored, @@ -4722,13 +4745,15 @@ fn parse_grid_tile_property( property: &ParsedBox<'_>, ) -> Result { if property.header.box_type.as_bytes() == HVCC_BOX_TYPE { - return Ok(CachedGridProperty::Hvcc(property.parse_hvcc().map_err( - |source| ExtractHeicItemDataError::GridTileCodecConfiguration { - item_id, - tile_item_id, - source, - }, - )?)); + return Ok(CachedGridProperty::Hvcc(Arc::new( + property.parse_hvcc().map_err(|source| { + ExtractHeicItemDataError::GridTileCodecConfiguration { + item_id, + tile_item_id, + source, + } + })?, + ))); } if property.header.box_type.as_bytes() == COLR_BOX_TYPE { return Ok(CachedGridProperty::Colr(property.parse_colr().map_err( @@ -4780,14 +4805,7 @@ fn resolve_grid_tile_hvcc_colr_and_transforms( tile_item_id: u32, associations: &[ItemPropertyAssociationBox], flattened_properties: &[ParsedBox<'_>], -) -> Result< - ( - HevcDecoderConfigurationBox, - PrimaryItemColorProperties, - Vec, - ), - ExtractHeicItemDataError, -> { +) -> Result { let mut tile_associations = Vec::new(); for association_box in associations { for entry in &association_box.entries { @@ -4802,7 +4820,7 @@ fn resolve_grid_tile_hvcc_colr_and_transforms( } } } - let mut property_cache = BTreeMap::new(); + let mut property_cache = GridTilePropertyCache::default(); resolve_grid_tile_hvcc_colr_and_transforms_indexed( item_id, tile_item_id, @@ -4817,15 +4835,8 @@ fn resolve_grid_tile_hvcc_colr_and_transforms_indexed( tile_item_id: u32, associations: &[&ItemPropertyAssociation], flattened_properties: &[ParsedBox<'_>], - property_cache: &mut BTreeMap, -) -> Result< - ( - HevcDecoderConfigurationBox, - PrimaryItemColorProperties, - Vec, - ), - ExtractHeicItemDataError, -> { + property_cache: &mut GridTilePropertyCache, +) -> Result { let mut hvcc = None; let mut last_nclx = None; let mut last_icc = None; @@ -4854,12 +4865,12 @@ fn resolve_grid_tile_hvcc_colr_and_transforms_indexed( }, ); } - if let Entry::Vacant(entry) = property_cache.entry(property_index) { + if let Entry::Vacant(entry) = property_cache.properties.entry(property_index) { let parsed = parse_grid_tile_property(item_id, tile_item_id, property)?; entry.insert(parsed); } - match &property_cache[&property_index] { - CachedGridProperty::Hvcc(parsed) => hvcc = Some(parsed.clone()), + match &property_cache.properties[&property_index] { + CachedGridProperty::Hvcc(parsed) => hvcc = Some(Arc::clone(parsed)), CachedGridProperty::Colr(parsed) => match &parsed.information { ColorInformation::Nclx(_) => last_nclx = Some(property_index), ColorInformation::Icc(_) => last_icc = Some(property_index), @@ -4869,19 +4880,27 @@ fn resolve_grid_tile_hvcc_colr_and_transforms_indexed( } } - let mut colr = PrimaryItemColorProperties::default(); - if let Some(index) = last_nclx - && let Some(CachedGridProperty::Colr(parsed)) = property_cache.get(&index) - && let ColorInformation::Nclx(profile) = &parsed.information - { - colr.nclx = Some(profile.clone()); - } - if let Some(index) = last_icc - && let Some(CachedGridProperty::Colr(parsed)) = property_cache.get(&index) - && let ColorInformation::Icc(profile) = &parsed.information - { - colr.icc = Some(profile.clone()); + let color_key = (last_nclx, last_icc); + if !property_cache.colors.contains_key(&color_key) { + let mut colr = PrimaryItemColorProperties::default(); + if let Some(index) = last_nclx + && let Some(CachedGridProperty::Colr(parsed)) = property_cache.properties.get(&index) + && let ColorInformation::Nclx(profile) = &parsed.information + { + colr.nclx = Some(profile.clone()); + } + if let Some(index) = last_icc + && let Some(CachedGridProperty::Colr(parsed)) = property_cache.properties.get(&index) + && let ColorInformation::Icc(profile) = &parsed.information + { + property_cache.color_profile_bytes = property_cache + .color_profile_bytes + .saturating_add(profile.profile.len() as u64); + colr.icc = Some(profile.clone()); + } + property_cache.colors.insert(color_key, Arc::new(colr)); } + let colr = Arc::clone(&property_cache.colors[&color_key]); let hvcc = hvcc.ok_or( ExtractHeicItemDataError::MissingGridTileCodecConfiguration { @@ -4889,7 +4908,7 @@ fn resolve_grid_tile_hvcc_colr_and_transforms_indexed( tile_item_id, }, )?; - Ok((hvcc, colr, transforms)) + Ok((hvcc, colr, transforms.into())) } /// Colour properties for the primary HEIC item, mirroring libheif: the primary @@ -4952,7 +4971,7 @@ pub fn primary_heic_color_properties(input: &[u8]) -> Option HeicGridPrimaryItemData { + let HeicPrimaryItemDataWithGrid::Grid(grid) = + extract_primary_heic_item_data_with_grid(file).expect("grid should resolve") + else { + panic!("expected grid"); + }; + grid + } + + #[test] + fn grid_tile_transforms_are_shared_across_duplicate_references() { + let mut tile_property_indices = vec![1_u8]; + tile_property_indices.extend([2_u8; 254]); + let rotations = [2_u8; 255]; + let extra_rotations: Vec<(u16, &[u8])> = + (0..256).map(|_| (2_u16, &rotations[..])).collect(); + + let grid = resolved_grid(&minimal_heic_grid_file( + (16, 16), + (64, 64), + &[2_u16; 256], + &[0x11; 16], + &[hvcc_box(), plain_box(b"irot", &[1])], + &tile_property_indices, + &extra_rotations, + )); + + assert_eq!(grid.tiles.len(), 256); + assert_eq!(grid.tiles[0].transforms.len(), 254 + 256 * 255); + assert!( + grid.tiles + .iter() + .all(|tile| Arc::ptr_eq(&tile.transforms, &grid.tiles[0].transforms)) + ); + } + + #[test] + fn grid_tile_codec_configurations_are_shared_across_duplicate_references() { + let nal_count = 65_535_u16; + let mut hvcc = vec![0_u8; 23]; + hvcc[0] = 1; + hvcc[22] = 1; + hvcc.push(32); + hvcc.extend_from_slice(&nal_count.to_be_bytes()); + for _ in 0..nal_count { + hvcc.extend_from_slice(&1_u16.to_be_bytes()); + hvcc.push(0x40); + } + + let grid = resolved_grid(&minimal_heic_grid_file( + (16, 16), + (64, 64), + &[2_u16; 256], + &[0x11; 16], + &[plain_box(b"hvcC", &hvcc)], + &[1], + &[], + )); + + assert_eq!(grid.tiles.len(), 256); + assert_eq!( + grid.tiles[0].hvcc.nal_arrays[0].nal_units.len(), + usize::from(nal_count) + ); + assert!( + grid.tiles + .iter() + .all(|tile| Arc::ptr_eq(&tile.hvcc, &grid.tiles[0].hvcc)) + ); + } + + #[test] + fn grid_tile_color_profiles_are_shared_across_distinct_tiles() { + let profile = vec![0x5A_u8; 3 * 1024 * 1024]; + let tile_ids: Vec = (2..66).collect(); + + let grid = resolved_grid(&minimal_heic_grid_file( + (8, 8), + (512, 512), + &tile_ids, + &[0x11; 16], + &[hvcc_box(), colr_icc_box(&profile)], + &[1, 2], + &[], + )); + + assert_eq!(grid.tiles.len(), 64); + assert_eq!(grid.tiles[0].colr.icc.as_ref().unwrap().profile, profile); + assert!(grid.tiles.iter().all(|tile| { + Arc::ptr_eq(&tile.colr, &grid.tiles[0].colr) + && Arc::ptr_eq(&tile.hvcc, &grid.tiles[0].hvcc) + })); + } + + #[test] + fn grid_tile_color_profile_copies_are_budgeted_across_distinct_compositions() { + let profile = vec![0x5A_u8; 3 * 1024 * 1024]; + let tile_ids: Vec = (2..66).collect(); + let mut properties = vec![hvcc_box(), colr_icc_box(&profile)]; + properties.extend((0..64).map(|_| colr_nclx_box(1, 13, 6, true))); + let nclx_indices: Vec<[u8; 1]> = (3..67).map(|index| [index]).collect(); + let extra_associations: Vec<(u16, &[u8])> = tile_ids + .iter() + .zip(&nclx_indices) + .map(|(&tile_id, index)| (tile_id, &index[..])) + .collect(); + + let err = extract_primary_heic_item_data_with_grid(&minimal_heic_grid_file( + (8, 8), + (512, 512), + &tile_ids, + &[0x11; 16], + &properties, + &[1, 2], + &extra_associations, + )) + .expect_err("per-composition profile copies must be budgeted"); + assert!(matches!( + err, + ExtractHeicItemDataError::PayloadTooLarge { .. } + )); + } + #[test] fn grid_tile_payload_reuse_within_budget_still_resolves() { let tile_payload = vec![0xAB_u8; 3 * 1024 * 1024]; diff --git a/src/lib.rs b/src/lib.rs index 5636bc9..082ad37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14484,9 +14484,10 @@ mod tests { nal_units: vec![sps_nal.clone()], }], 4, - ), + ) + .into(), colr: Default::default(), - transforms: Vec::new(), + transforms: Default::default(), payload: Vec::new(), }; @@ -14536,9 +14537,10 @@ mod tests { nal_units: vec![small_sps.clone()], }], 4, - ), + ) + .into(), colr: Default::default(), - transforms: Vec::new(), + transforms: Default::default(), payload, }; diff --git a/src/testdata/apple-alpha-192x64.heic b/src/testdata/apple-alpha-192x64.heic new file mode 100644 index 0000000..5ccaaf6 Binary files /dev/null and b/src/testdata/apple-alpha-192x64.heic differ diff --git a/src/testdata/apple-alpha-40x30.heic b/src/testdata/apple-alpha-40x30.heic new file mode 100644 index 0000000..5744cab Binary files /dev/null and b/src/testdata/apple-alpha-40x30.heic differ