-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow for recursive type #107
Comments
This is caused by the behaviour of
This means that, for example,
|
The derive should emit code that does something like if u.is_empty() {
// generate the smallest variant of the enum according to `size_hint` or something
} |
Let's get a little bit more pathological… #[derive(Debug, Arbitrary)]
enum Nah {
Foo(Box<Nah>, Box<Nah>, Box<Nah>),
Bar([u128; 8], Vec<u8>),
}
use arbitrary::{Arbitrary, Unstructured};
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
fn main() {
let mut rng = ChaCha8Rng::seed_from_u64(2);
let mut vec = vec![0; 10_000_000];
rng.fill(&mut vec[..]);
println!("{:#?}", Nah::arbitrary(&mut Unstructured::new(&vec)).ok());
} [Edit:] Had an |
Works fine here:
The only case in which I can plausibly see random data overflowing |
Apologies, I gave the wrong seed. Try 2. (Or just looping through a few of them.) |
The following code
Results in a stack overflow
I guess there isn't any data for the discriminant to go on, so it choses the first one. Upon which it needs to construct a
Succ
, so it needs to construct aNat
. And there's the infinite recursion.This issue is similar to #30.
I have no practical use for this type, I just encountered it while helping someone on a Matrix channel. I know the issue can be side-stepped by reordering the variants.
The text was updated successfully, but these errors were encountered: