diff --git a/dnp3/src/app/parse/bytes.rs b/dnp3/src/app/parse/bytes.rs index 0f5c7374..b26b075d 100644 --- a/dnp3/src/app/parse/bytes.rs +++ b/dnp3/src/app/parse/bytes.rs @@ -140,7 +140,7 @@ impl<'a> Iterator for RangedBytesIterator<'a> { } let bytes = self.cursor.read_bytes(self.size).ok()?; let index = self.index; - self.index += 1; + self.index = self.index.saturating_add(1); self.remaining -= 1; Some((bytes, index)) } diff --git a/dnp3/src/app/parse/parser.rs b/dnp3/src/app/parse/parser.rs index 764a9b3d..753ac564 100644 --- a/dnp3/src/app/parse/parser.rs +++ b/dnp3/src/app/parse/parser.rs @@ -1152,6 +1152,25 @@ mod test { assert_matches!(headers.next(), None); } + #[test] + fn parses_group110var1_at_max_index() { + let input = [0x6E, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA]; + let mut headers = + ObjectParser::parse(ParseOptions::default(), FunctionCode::Response, &input) + .unwrap() + .iter(); + + let bytes: Vec<(&[u8], u16)> = assert_matches!( + headers.next().unwrap().details, + HeaderDetails::TwoByteStartStop(0xFFFF, 0xFFFF, RangedVariation::Group110VarX(0x01, seq)) => { + seq.iter().collect() + } + ); + + assert_eq!(bytes, vec![([0xAA].as_slice(), 0xFFFF)]); + assert_matches!(headers.next(), None); + } + #[test] fn parses_group111var1_as_non_read() { let input = [