Skip to content

Commit

Permalink
Merge pull request #84 from LingMan/master
Browse files Browse the repository at this point in the history
Fix unsoundness: Validate input to C2CPlan::c2c and R2RPlan::r2r
  • Loading branch information
termoshtt authored Jun 19, 2020
2 parents 9c8354a + 93f96dc commit 8dc079d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fftw/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ macro_rules! impl_c2c {
})
}
fn c2c(&mut self, in_: &mut [Self::Complex], out: &mut [Self::Complex]) -> Result<()> {
self.check(in_, out)?;
unsafe { $exec(self.plan, in_.as_mut_ptr(), out.as_mut_ptr()) };
Ok(())
}
Expand Down Expand Up @@ -315,6 +316,7 @@ macro_rules! impl_r2r {
})
}
fn r2r(&mut self, in_: &mut [Self::Real], out: &mut [Self::Real]) -> Result<()> {
self.check(in_, out)?;
unsafe { $exec(self.plan, in_.as_mut_ptr(), out.as_mut_ptr()) };
Ok(())
}
Expand Down
11 changes: 8 additions & 3 deletions fftw/tests/c2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ fn c2c2c_identity() {
let n = 32;
let mut a = vec![c64::zero(); n];
let mut b = vec![c64::zero(); n];
let mut plan: C2CPlan64 =

let mut plan_ab: C2CPlan64 =
C2CPlan::new(&[n], &mut a, &mut b, Sign::Forward, Flag::MEASURE).unwrap();
let mut plan_ba: C2CPlan64 =
C2CPlan::new(&[n], &mut b, &mut a, Sign::Forward, Flag::MEASURE).unwrap();

for i in 0..n {
a[i] = c64::new(1.0, 0.0);
}
plan.c2c(&mut a, &mut b).unwrap();
plan.c2c(&mut b, &mut a).unwrap();

plan_ab.c2c(&mut a, &mut b).unwrap();
plan_ba.c2c(&mut b, &mut a).unwrap();
for v in a.iter() {
let ans = c64::new(n as f64, 0.0);
let dif = (v - ans).norm();
Expand Down
4 changes: 3 additions & 1 deletion fftw/tests/r2r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ fn r2r2r_identity() {
let factor = 2. * n as f64;

// Vector of ones.
a = vec![1.0f64; n];
for a_i in a.iter_mut() {
*a_i = 1.0;
}

// Forward pass.
fwd.r2r(&mut a, &mut b).unwrap();
Expand Down

0 comments on commit 8dc079d

Please sign in to comment.