Add more tests on truncated data.
This commit is contained in:
parent
35e2ccc33b
commit
7de2ff0ddd
|
@ -442,6 +442,44 @@ mod tests {
|
|||
assert!(buf.ends_with(b"xif\0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_before_ftyp() {
|
||||
let data =
|
||||
b"\0\0\0\x09XXXXx\
|
||||
\0\0\0\x14ftypmif1\0\0\0\0mif1\
|
||||
\0\0\0\x57meta\0\0\0\0\
|
||||
\0\0\0\x18iloc\x01\0\0\0\0\0\0\x01\x1e\x1d\0\x01\0\0\0\x01\
|
||||
\0\0\0\x22iinf\0\0\0\0\0\x01\
|
||||
\0\0\0\x14infe\x02\0\0\0\x1e\x1d\0\0Exif\
|
||||
\0\0\0\x11idat\0\0\0\x01xabcd";
|
||||
assert!(is_heif(data));
|
||||
let exif = get_exif_attr(&mut Cursor::new(&data[..])).unwrap();
|
||||
assert_eq!(exif, b"abcd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_exif_data_block() {
|
||||
let data =
|
||||
b"\0\0\0\x14ftypmif1\0\0\0\0mif1\
|
||||
\0\0\0\x52meta\0\0\0\0\
|
||||
\0\0\0\x18iloc\x01\0\0\0\0\0\0\x01\x1e\x1d\0\x01\0\0\0\x01\
|
||||
\0\0\0\x22iinf\0\0\0\0\0\x01\
|
||||
\0\0\0\x14infe\x02\0\0\0\x1e\x1d\0\0Exif\
|
||||
\0\0\0\x0cidat\0\0\0\x01";
|
||||
assert_err_pat!(get_exif_attr(&mut Cursor::new(&data[..])),
|
||||
Error::InvalidFormat("Invalid Exif header offset"));
|
||||
|
||||
let data =
|
||||
b"\0\0\0\x14ftypmif1\0\0\0\0mif1\
|
||||
\0\0\0\x51meta\0\0\0\0\
|
||||
\0\0\0\x18iloc\x01\0\0\0\0\0\0\x01\x1e\x1d\0\x01\0\0\0\x01\
|
||||
\0\0\0\x22iinf\0\0\0\0\0\x01\
|
||||
\0\0\0\x14infe\x02\0\0\0\x1e\x1d\0\0Exif\
|
||||
\0\0\0\x0bidat\0\0\0";
|
||||
assert_err_pat!(get_exif_attr(&mut Cursor::new(&data[..])),
|
||||
Error::InvalidFormat("ExifDataBlock too small"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parser_box_header() {
|
||||
// size
|
||||
|
|
|
@ -125,6 +125,12 @@ mod tests {
|
|||
assert_err_pat!(get_exif_attr(&mut Cursor::new(data)),
|
||||
Error::InvalidFormat("Broken JPEG file"));
|
||||
}
|
||||
|
||||
let mut data = b"\xff\xd8\xff\xe1\x00\x08Exif\0\0".to_vec();
|
||||
get_exif_attr(&mut Cursor::new(&data)).unwrap();
|
||||
while let Some(_) = data.pop() {
|
||||
get_exif_attr(&mut &data[..]).unwrap_err();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
11
src/tiff.rs
11
src/tiff.rs
|
@ -531,6 +531,17 @@ mod tests {
|
|||
assert_eq!(format!("{:^10}", In(65535)), " IFD65535 ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncated() {
|
||||
let mut data =
|
||||
b"MM\0\x2a\0\0\0\x08\
|
||||
\0\x01\x01\0\0\x03\0\0\0\x01\0\x14\0\0\0\0\0\0".to_vec();
|
||||
parse_exif(&data).unwrap();
|
||||
while let Some(_) = data.pop() {
|
||||
parse_exif(&data).unwrap_err();
|
||||
}
|
||||
}
|
||||
|
||||
// Before the error is returned, the IFD is parsed multiple times
|
||||
// as the 0th, 1st, ..., and n-th IFDs.
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue