mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
Import plist regression from Craft Anything 15de3661
This commit is contained in:
1 parent
b2f888d788
commit
0bc1989610
1 file changed
+34
@@ -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<u8> {
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user