From 0bc19896102774e5ffe12ed012fc6cb036e6b9d3 Mon Sep 17 00:00:00 2001 From: BFlat Date: Sun, 15 Nov 2026 07:55:30 -0500 Subject: [PATCH] Import plist regression from Craft Anything 15de3661 --- crates/plist/tests/plist_object_bounds.rs | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 crates/plist/tests/plist_object_bounds.rs diff --git a/crates/plist/tests/plist_object_bounds.rs b/crates/plist/tests/plist_object_bounds.rs new file mode 100644 index 000000000..52d30cb80 --- /dev/null +++ b/crates/plist/tests/plist_object_bounds.rs @@ -0,0 +1,34 @@ +use craft_plist::{Value, parse_binary}; +use craft_anything_testkit::apple as fx; + +fn single_object(object: &[u8], offset: u8) -> Vec { + let mut data = b"bplist00".to_vec(); + data.extend_from_slice(object); + let table = data.len() as u64; + data.push(offset); + data.extend_from_slice(&[0, 0, 0, 0, 0, 0, 1, 1]); + data.extend_from_slice(&1u64.to_be_bytes()); + data.extend_from_slice(&0u64.to_be_bytes()); + data.extend_from_slice(&table.to_be_bytes()); + data +} + +#[test] +fn binary_values_cannot_consume_the_offset_table_or_trailer() { + for object in [&[0x54, b'x'][..], &[0x43, 0x42], &[0x13], &[0x87], &[0x62, 0, b'x']] { + assert!(parse_binary(&single_object(object, 8)).is_err(), "accepted object {object:02x?}"); + } +} + +#[test] +fn binary_offsets_cannot_point_inside_the_file_header() { + assert!(parse_binary(&single_object(&[0x00], 0)).is_err()); + assert!(matches!(parse_binary(&single_object(&[0x00], 8)), Ok(Value::Null))); +} + +#[test] +fn objects_ending_at_the_table_boundary_are_valid() { + assert!(matches!(parse_binary(&single_object(&[0x51, b'x'], 8)), Ok(Value::String(s)) if s == "x")); + let sample = fx::sample_plist(); + assert_eq!(parse_binary(&fx::to_bplist(&sample)).unwrap().get("Count").and_then(Value::as_int), Some(-42)); +}