diff --git a/src/endian.rs b/src/endian.rs index 3ad4435..0778dfd 100644 --- a/src/endian.rs +++ b/src/endian.rs @@ -130,4 +130,13 @@ mod tests { fn out_of_range() { BigEndian::loadu16(&[0x01, 0x02], 1); } + + // "attempt to add with overflow" with the arithmetic overflow + // check, and "slice index starts at 18446744073709551615 but ends + // at 1" without it. + #[test] + #[should_panic(expected = "at")] + fn wrap_around() { + BigEndian::loadu16(&[0x01, 0x02], (-1isize) as usize); + } } diff --git a/src/value.rs b/src/value.rs index a98e801..59f2830 100644 --- a/src/value.rs +++ b/src/value.rs @@ -229,6 +229,7 @@ fn parse_unknown<'a>(data: &'a [u8], offset: usize, count: usize) mod tests { use endian::BigEndian; use super::*; + use super::parse_short; #[test] fn byte() { @@ -448,4 +449,12 @@ mod tests { } } } + + // These functions are never called in a way that an out-of-range access + // could happen, so this test is hypothetical but just for safety. + #[test] + #[should_panic(expected = "index 5 out of range for slice of length 4")] + fn short_oor() { + parse_short::(b"\x01\x02\x03\x04", 1, 2); + } }