BIC-MNI / minc-tools

Basic minc-tools from former minc repository
Other
29 stars 25 forks source link

Undefined behaviour in mincresample #111

Closed bbbxyz closed 3 years ago

bbbxyz commented 3 years ago

I discovered an array overflow in resample_volume's trilinear_interpolant() while running mincresample on an input volume with a slice dimension size of one. It attempts to read from index slcind+1 here but volume->offset is created with a size of 1 here. I believe the intended behaviour was to use slcnext (set to 0 when the dimension is of size 1 here ) rather than slcind+1 as an index.

To reproduce it:

make_phantom -xcenter 1.1 -xwidth 1 -xnelements 1 -xstart 1.1 -xstep 0.005 input.mnc
mincresample input.mnc out.mnc

The exact output is undefined and from what I can see depends on your system but running the mincresample call with valgrind should complain about an invalid read.

I'll open a PR if that fix sounds correct to you.

vfonov commented 3 years ago

yes, looks like it is an attempt to account for interslice normalization , that's gone wrong. fix looks reasonable