Segmentation fault in GIFT Gabor feature extraction code

David Squire <[email protected]> Thu, 20 May 2010 17:29:24 +1000
Newsgroups gmane.comp.gnu.gift.general,gmane.comp.gnu.gift.bugs
Message-ID <[email protected]>
Hi All,

I am getting a segmentation fault in gift-extract-features using the 
latest version from CVS. It is occurring in code of which I wrote the 
first version years ago, but that code has been modified a *lot* since I 
last looked at it.

The error is occurring in function gabor_filter in file gabor.c, at 
lines 112-113. Specifically it is target_image[k] on line 113 that is 
causing the seg. fault. This is occuring with k = 1, but even "print 
*target_image" in gdb is causing a problem, so it would see that the 
original calculation of the pointer target_image is the problem. This 
occurs earlier in the function, with the line:

target_image=&image[(width*height-1)-(y*width+x+kernel_size[filter_scale]/2)];

It appears that a lot of this sort of pointer arithmetic has been 
introduced in order to try to avoid redundant calculations inside loops 
- which is fine so long as the calculations are correct. In many cases I 
suspect that the optimizer would have picked such things up anyway, and 
with less risk.

I've added some code to print the values of the pointers, and I observe 
that immediately prior to the crash:

        image = 0x35525010
target_image = 0x35525008

So, we see that it has tried to read from before the start of image[]. 
The seg. fault is thus not surprising.

That "-1" in the calculation above is ringing alarm bells for me. Why is 
it there?

Anyway, I would be very glad if the person who made these changes is 
still reading these lists, and could re-check the calculations that they 
made. That would probably be a lot more efficient than me trying to 
decipher it all.

Any other thoughts also very welcome.

Regards,

David


-- 
Dr David McG. Squire,  Senior Lecturer
Clayton School of Information Technology, Monash University, Australia
CRICOS Provider No. 00008C       http://www.csse.monash.edu.au/~davids/