Skip to content

Commit 8dc079d

Browse files
authored
Merge pull request #84 from LingMan/master
Fix unsoundness: Validate input to C2CPlan::c2c and R2RPlan::r2r
2 parents 9c8354a + 93f96dc commit 8dc079d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

fftw/src/plan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ macro_rules! impl_c2c {
202202
})
203203
}
204204
fn c2c(&mut self, in_: &mut [Self::Complex], out: &mut [Self::Complex]) -> Result<()> {
205+
self.check(in_, out)?;
205206
unsafe { $exec(self.plan, in_.as_mut_ptr(), out.as_mut_ptr()) };
206207
Ok(())
207208
}
@@ -315,6 +316,7 @@ macro_rules! impl_r2r {
315316
})
316317
}
317318
fn r2r(&mut self, in_: &mut [Self::Real], out: &mut [Self::Real]) -> Result<()> {
319+
self.check(in_, out)?;
318320
unsafe { $exec(self.plan, in_.as_mut_ptr(), out.as_mut_ptr()) };
319321
Ok(())
320322
}

fftw/tests/c2c.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ fn c2c2c_identity() {
88
let n = 32;
99
let mut a = vec![c64::zero(); n];
1010
let mut b = vec![c64::zero(); n];
11-
let mut plan: C2CPlan64 =
11+
12+
let mut plan_ab: C2CPlan64 =
1213
C2CPlan::new(&[n], &mut a, &mut b, Sign::Forward, Flag::MEASURE).unwrap();
14+
let mut plan_ba: C2CPlan64 =
15+
C2CPlan::new(&[n], &mut b, &mut a, Sign::Forward, Flag::MEASURE).unwrap();
16+
1317
for i in 0..n {
1418
a[i] = c64::new(1.0, 0.0);
1519
}
16-
plan.c2c(&mut a, &mut b).unwrap();
17-
plan.c2c(&mut b, &mut a).unwrap();
20+
21+
plan_ab.c2c(&mut a, &mut b).unwrap();
22+
plan_ba.c2c(&mut b, &mut a).unwrap();
1823
for v in a.iter() {
1924
let ans = c64::new(n as f64, 0.0);
2025
let dif = (v - ans).norm();

fftw/tests/r2r.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ fn r2r2r_identity() {
2525
let factor = 2. * n as f64;
2626

2727
// Vector of ones.
28-
a = vec![1.0f64; n];
28+
for a_i in a.iter_mut() {
29+
*a_i = 1.0;
30+
}
2931

3032
// Forward pass.
3133
fwd.r2r(&mut a, &mut b).unwrap();

0 commit comments

Comments
 (0)