xorshift icon indicating copy to clipboard operation
xorshift copied to clipboard

XorShift1024 index out of bounds on reseed with longer array

Open lambdaupb opened this issue 8 years ago • 0 comments

xorshift1024.rs: line 99

impl<'a> SeedableRng<&'a [u64]> for Xorshift1024 {
    fn reseed(&mut self, seed: &'a [u64]) {
        if seed.len() < 16 {
            panic!("Xorshift1024 seed needs at least 16 u64s for seeding.");
        }

        for (index, element) in seed.iter().enumerate() {
            self.state[index] = *element;
        }
    }

If the seed array is longer than 16, the for loop will write out of bounds into the self.state array.

I think the following should work:

 for i in 0..self.state.len() {
    self.state[i] = seed[i];
 }

Maybe this also happens in the other RNGs.

Thanks for the nice crate :)

lambdaupb avatar Jul 05 '17 17:07 lambdaupb