diff options
| author | Edward Barnard | 2017-05-05 10:03:03 +0100 | 
|---|---|---|
| committer | Edward Barnard | 2017-05-05 10:03:03 +0100 | 
| commit | 645aece10f5b25ba015ef5ff240586a2f38aad7e (patch) | |
| tree | 82bb94247f20490259e8976d8e6b3d4680906948 | |
| parent | 3f67a83b884925288e782033454e72944257b219 (diff) | |
| download | rust-plist-645aece10f5b25ba015ef5ff240586a2f38aad7e.tar.bz2 | |
Check for NaN binary date values.
| -rw-r--r-- | src/date.rs | 4 | ||||
| -rw-r--r-- | tests/fuzzer.rs | 6 | 
2 files changed, 10 insertions, 0 deletions
| diff --git a/src/date.rs b/src/date.rs index 50a0d5d..01c5c9d 100644 --- a/src/date.rs +++ b/src/date.rs @@ -15,6 +15,10 @@ impl Date {      pub fn from_seconds_since_plist_epoch(timestamp: f64) -> Result<Date> {          // Seconds since 1/1/2001 00:00:00. +        if timestamp.is_nan() { +            return Err(Error::InvalidData); +        } +          let millis = timestamp * 1_000.0;          // Chrono's Duration can only millisecond values between ::std::i64::MIN and          // ::std::i64::MAX. diff --git a/tests/fuzzer.rs b/tests/fuzzer.rs index 72be1b8..100e569 100644 --- a/tests/fuzzer.rs +++ b/tests/fuzzer.rs @@ -33,6 +33,12 @@ fn binary_zero_offset_size() {      test_fuzzer_data_err(data);  } +#[test] +fn binary_nan_date() { +    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"; +    test_fuzzer_data_err(data); +} +  // Issue 20 - not found by fuzzing but this is a convenient place to put the test.  #[test]  fn issue_20_binary_with_data_in_trailer() { | 
