Skip to content

Commit

Permalink
Test for recursion limit
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <nrc@ncameron.org>
  • Loading branch information
nrc committed May 23, 2019
1 parent 361957d commit 7e9eea4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ pub mod message {
M: Message,
{
let len = msg.encoded_len();
key_len(tag) + encoded_len_varint(len as u64) + msg.encoded_len()
key_len(tag) + encoded_len_varint(len as u64) + len
}

#[inline]
Expand Down
21 changes: 21 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@ mod tests {
};
}

#[test]
fn test_deep_nesting() {
fn build_and_roundtrip(depth: usize) -> Result<(), prost::DecodeError> {
use crate::nesting::A;

let mut top = A::default();
let mut a = &mut top;
for _ in 0..depth {
a.a = Some(Box::new(A::default()));
a = a.a.as_mut().unwrap().as_mut();
}

let mut buf = Vec::new();
top.encode(&mut buf).unwrap();
A::decode(buf).map(|_| ())
}

assert!(build_and_roundtrip(99).is_ok());
assert!(build_and_roundtrip(100).is_err());
}

#[test]
fn test_recursive_oneof() {
use crate::recursive_oneof::{a, A, B, C};
Expand Down

0 comments on commit 7e9eea4

Please sign in to comment.