Skip to content

Commit e273465

Browse files
mashedcodejjhbw
authored andcommitted
Fix out of bounds access
1 parent 55f4135 commit e273465

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/feat/surf_mlp_featmap.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,25 @@ impl SurfMlpFeatureMap {
145145
math::vector_add(dy, dy, dy, len);
146146

147147
let step = self.width as usize;
148+
let grad_y_stop = self.grad_y.len() - step;
148149

149150
#[cfg(feature = "rayon")]
150-
let it = self.img_buf
151+
let it = self
152+
.img_buf
151153
.par_chunks(step)
152-
.zip(self.grad_y[step..]
153-
.par_chunks_mut(step));
154+
.zip(self.grad_y[step..grad_y_stop].par_chunks_mut(step));
154155

155156
#[cfg(not(feature = "rayon"))]
156-
let it = self.img_buf
157+
let it = self
158+
.img_buf
157159
.chunks(step)
158-
.zip(self.grad_y[step..]
159-
.chunks_mut(step));
160-
161-
it
162-
.for_each(|(inputs, outputs)| {
163-
let src = inputs.as_ptr();
164-
let dest = outputs.as_mut_ptr();
165-
math::vector_sub(src.offset((step << 1) as isize), src, dest, len);
166-
});
160+
.zip(self.grad_y[step..grad_y_stop].chunks_mut(step));
161+
162+
it.for_each(|(inputs, outputs)| {
163+
let src = inputs.as_ptr();
164+
let dest = outputs.as_mut_ptr();
165+
math::vector_sub(src.offset((step << 1) as isize), src, dest, len);
166+
});
167167

168168
let offset = ((self.height - 1) * self.width) as isize;
169169
dy = dy.offset(offset);

0 commit comments

Comments
 (0)