| 1 |
extern crate plist; |
| 2 |
|
| 3 |
use plist::{Error, Value}; |
| 4 |
use std::io::Cursor; |
| 5 |
|
| 6 |
#[test] |
| 7 |
fn too_large_allocation() { |
| 8 |
let data = b"bplist00\"&L^^^^^^^^-^^^^^^^^^^^"; |
| 9 |
test_fuzzer_data_err(data); |
| 10 |
} |
| 11 |
|
| 12 |
#[test] |
| 13 |
fn too_large_allocation_2() { |
| 14 |
let data = b"bplist00;<)\x9fX\x0a<h\x0a:hhhhG:hh\x0amhhhhhhx#hhT)\x0a*"; |
| 15 |
test_fuzzer_data_err(data); |
| 16 |
} |
| 17 |
|
| 18 |
#[test] |
| 19 |
fn empty_offset_table() { |
| 20 |
let data = b"bplist00;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<)\x9fXTX("; |
| 21 |
test_fuzzer_data_err(data); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn binary_circular_reference() { |
| 26 |
let data = b"bplist00\xd6\x01\x02\x03\x04\x05\x06\x07\x0a\x0b\x0c\x0d\x0eULinesUDeathVHeightYBirthdateVAutbplist00\xd6\x01\x02\x03\x04\x05\x06\x07\x0a\x0b\x0c\x0d\x0eULinesUDeathVHeightYBirthdateVAuthorTData\xa2\x08\x09_\x10\x1eIt is nifying nothing.\x11\x06\x1c#?\xf9\x99\x99\x99\x99\x99\x9a3\xc1\xc2v\x00e\x00\x00\x00_\x10\x13William ShakespeareO\x10\x0f\x00\x00\x00\xbe\x00\x00\x00\x03\x00\x00\x00\x1e\x00\x00\x00\x08\x15\x1b!(58>Ab\x90\x93\x9c\xa5\xbb\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcd"; |
| 27 |
test_fuzzer_data_err(data); |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn binary_zero_offset_size() { |
| 32 |
let data = include_bytes!("data/binary_zero_offset_size.plist"); |
| 33 |
test_fuzzer_data_err(data); |
| 34 |
} |
| 35 |
|
| 36 |
#[test] |
| 37 |
fn binary_nan_date() { |
| 38 |
let data = b"bplist00\xd6\x01\x02\x01\x04\x05\x06\x07\x0a\x0b\x0c\x0d\x0eULinesUDeathVHeightYBthridateVAuthorTData\xa2\x08\x09_\x10\x1eIt is a tale told by an idiot,_\x10+Full of sound and fury, signifying nothing.\x11\x06\x1c#?\xf9\x99\x99\x99\x99\x99\x9a3\xff\xff\xff\xffe\x00\x00\x00_\x13\x10William ShakespeareO\x10\xe5\x00\x00\x00\xbe\x00\x00\x00\x03\x00\x00\x00\x1e\x00\x00\x00\x08\x15\x1b!(14>Ab\x90\x93\x9c\xa5\xbb\xd4\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcd"; |
| 39 |
test_fuzzer_data_err(data); |
| 40 |
} |
| 41 |
|
| 42 |
#[test] |
| 43 |
fn binary_circular_array() { |
| 44 |
let data = include_bytes!("data/binary_circular_array.plist"); |
| 45 |
test_fuzzer_data_err(data); |
| 46 |
} |
| 47 |
|
| 48 |
// Issue 20 - not found by fuzzing but this is a convenient place to put the test. |
| 49 |
#[test] |
| 50 |
fn issue_20_binary_with_data_in_trailer() { |
| 51 |
let data = |
| 52 |
b"bplist00\xd0\x08\0\0\0\0\0\0\x01\x01\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\t"; |
| 53 |
test_fuzzer_data_ok(data); |
| 54 |
} |
| 55 |
|
| 56 |
#[test] |
| 57 |
fn issue_22_binary_with_byte_ref_size() { |
| 58 |
let data = b"bplist00\xd1\x01\x02TTestQ1\x08\x0b\x10\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12"; |
| 59 |
test_fuzzer_data_ok(data); |
| 60 |
} |
| 61 |
|
| 62 |
#[test] |
| 63 |
fn overflow_instant_add() { |
| 64 |
let data = b"bplist00\x10\x01\x00\x00\x00\x00\x00\x003~\x00\x00\x00\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00"; |
| 65 |
|
| 66 |
test_fuzzer_data_err(data); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
fn overflow_instant_sub() { |
| 71 |
let data = b"bplist00\x10\x01\x00\x00\x00\x00\x00\x003\xfe\x00\x00\x00\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00"; |
| 72 |
|
| 73 |
test_fuzzer_data_err(data); |
| 74 |
} |
| 75 |
|
| 76 |
fn test_fuzzer_data(data: &[u8]) -> Result<Value, Error> { |
| 77 |
let cursor = Cursor::new(data); |
| 78 |
Value::from_reader(cursor) |
| 79 |
} |
| 80 |
|
| 81 |
fn test_fuzzer_data_ok(data: &[u8]) { |
| 82 |
test_fuzzer_data(data).unwrap(); |
| 83 |
} |
| 84 |
|
| 85 |
fn test_fuzzer_data_err(data: &[u8]) { |
| 86 |
assert!(test_fuzzer_data(data).is_err()); |
| 87 |
} |