1 | // SPDX-License-Identifier: Apache-2.0 |
2 | |
3 | //! This test validates that we don't get stack overflows. |
4 | //! |
5 | //! If container types cause recursion, then a long list of prefixes which |
6 | //! indicate nested container types could cause the stack to overflow. We |
7 | //! test each of these types here to ensure there is no stack overflow. |
8 | |
9 | use ciborium::{ |
10 | de::{from_reader, Error}, |
11 | value::Value, |
12 | }; |
13 | |
14 | #[test] |
15 | fn array() { |
16 | let bytes = [0x9f; 128 * 1024]; |
17 | match from_reader::<Value, _>(&bytes[..]).unwrap_err() { |
18 | Error::RecursionLimitExceeded => (), |
19 | e => panic!("incorrect error: {:?}" , e), |
20 | } |
21 | } |
22 | |
23 | #[test] |
24 | fn map() { |
25 | let bytes = [0xbf; 128 * 1024]; |
26 | match from_reader::<Value, _>(&bytes[..]).unwrap_err() { |
27 | Error::RecursionLimitExceeded => (), |
28 | e => panic!("incorrect error: {:?}" , e), |
29 | } |
30 | } |
31 | |
32 | #[test] |
33 | fn bytes() { |
34 | let bytes = [0x5f; 128 * 1024]; |
35 | match from_reader::<Value, _>(&bytes[..]).unwrap_err() { |
36 | Error::Io(..) => (), |
37 | e => panic!("incorrect error: {:?}" , e), |
38 | } |
39 | } |
40 | |
41 | #[test] |
42 | fn text() { |
43 | let bytes = [0x7f; 128 * 1024]; |
44 | match from_reader::<Value, _>(&bytes[..]).unwrap_err() { |
45 | Error::Io(..) => (), |
46 | e => panic!("incorrect error: {:?}" , e), |
47 | } |
48 | } |
49 | |