diff --git a/src/lib.rs b/src/lib.rs index af2c3dc..a7e7495 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -505,7 +505,13 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result, ASN1Decode let v = String::from_iter(body.iter().map(|x| *x as char)); - let y = &v[0..2]; + let y = match v.get(0..2) { + Some(yy) => yy, + None => { + // This wasn't a valid character boundrary. + return Err(ASN1DecodeErr::InvalidDateValue(v)); + } + }; let y_prefix = match y.parse::() { Err(_) => return Err(ASN1DecodeErr::InvalidDateValue(v)), @@ -1438,6 +1444,15 @@ mod tests { Ok(vec![ASN1Block::Integer(0, val)]) } + #[test] + fn utc_time_tests() { + // Check for a regression against issue #27, in which this would + // cause a panic. + let input = [55, 13, 13, 133, 13, 13, 50, 13, 13, 133, 13, 13, 50, 13, 133]; + let output = from_der(&input); + assert!(output.is_err()); + } + #[test] fn generalized_time_tests() { check_spec(