eXeC64/imv

imv segfaults when trying to open raw cr2 if freeimage is compiled with tiff support

alexcepoi opened this issue · 5 comments

Gentoo Linux
imv 4.1.0-r1
freeimage 3.18.0-r2 [tiff]

Trying to open a canon raw CR2 file.
If freeimage is not compiled with tiff support, file gets opened by imv as expected. However when freeimage is compiled with tiff support, I get this segfault:

kernel: imv[679121]: segfault at 1 ip 00007fd6146d3e80 sp 00007fd5867fb2e8 error 4 in libtiff.so.5.6.0[7fd6146cc000+46000]

Starting program: /usr/bin/imv Pictures/Stock/IMG_1975.CR2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff3959640 (LWP 679693)]
[New Thread 0x7fffee3a4640 (LWP 679694)]
[New Thread 0x7fffeda56640 (LWP 679695)]
[New Thread 0x7fffed255640 (LWP 679696)]
[New Thread 0x7fffeca54640 (LWP 679697)]
[New Thread 0x7fffdffff640 (LWP 679698)]
[New Thread 0x7fffdf7fe640 (LWP 679699)]
[New Thread 0x7fffdeffd640 (LWP 679700)]
[New Thread 0x7fffde7fc640 (LWP 679701)]
[New Thread 0x7fffddffb640 (LWP 679702)]
[New Thread 0x7fffdd7fa640 (LWP 679703)]
[New Thread 0x7fffdcff9640 (LWP 679704)]
[New Thread 0x7fffbbfff640 (LWP 679705)]
[New Thread 0x7fffbb7fe640 (LWP 679706)]
[New Thread 0x7fffbaffd640 (LWP 679707)]
[New Thread 0x7fffba7fc640 (LWP 679708)]
[New Thread 0x7fffb9ffb640 (LWP 679709)]
[New Thread 0x7fffb97fa640 (LWP 679710)]
[New Thread 0x7fffb8ff9640 (LWP 679711)]
[New Thread 0x7fff9bfff640 (LWP 679712)]
[New Thread 0x7fff9b7fe640 (LWP 679713)]
[New Thread 0x7fff9affd640 (LWP 679714)]
[New Thread 0x7fff9a7fc640 (LWP 679715)]
[New Thread 0x7fff99ffb640 (LWP 679716)]
[New Thread 0x7fff997fa640 (LWP 679717)]
[New Thread 0x7fff98ff9640 (LWP 679718)]
[New Thread 0x7fff7bfff640 (LWP 679719)]
[New Thread 0x7fff7b7fe640 (LWP 679720)]
[New Thread 0x7fff7affd640 (LWP 679721)]
[New Thread 0x7fff7a7fc640 (LWP 679722)]
[New Thread 0x7fff79ffb640 (LWP 679723)]
[New Thread 0x7fff797fa640 (LWP 679724)]
[New Thread 0x7fff78ff9640 (LWP 679725)]
[New Thread 0x7ffff7fc7d80 (LWP 679726)]
[New Thread 0x7fff5bfff640 (LWP 679727)]

Thread 36 "imv" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff5bfff640 (LWP 679727)]
0x00007ffff5a2fe80 in TIFFFieldTag () from /usr/lib64/libtiff.so.5
(gdb) bt
#0  0x00007ffff5a2fe80 in TIFFFieldTag () at /usr/lib64/libtiff.so.5
#1  0x00007ffff5b1f0d2 in tiff_read_exif_tags(tiff*, TagLib::MDMODEL, FIBITMAP*) () at /usr/lib64/libfreeimage.so.3
#2  0x00007ffff5af69c7 in  () at /usr/lib64/libfreeimage.so.3
#3  0x00007ffff5ad69ec in FreeImage_LoadFromHandle () at /usr/lib64/libfreeimage.so.3
#4  0x00007ffff5ad6a99 in FreeImage_Load () at /usr/lib64/libfreeimage.so.3
#5  0x0000555555562f3d in  ()
#6  0x000055555556230f in  ()
#7  0x0000555555562349 in  ()
#8  0x00007ffff7f15fbe in start_thread () at /lib64/libpthread.so.0
#9  0x00007ffff4be76af in clone () at /lib64/libc.so.6

Can reproduce reliably.
IMG_1975.zip

Interestingly TIFFOpen on the libtiff backend returns NULL only when linked against freeimage with tiff support, then continues to try freeimage and finally segfaults.

Interestingly TIFFOpen on the libtiff backend returns NULL only when linked against freeimage with tiff support, then continues to try freeimage and finally segfaults.

I figured out what's going on, this is gentoo's fault. The unbundling patch used by gentoo for freeimage seem to give visibility to a bogus TIFFOpen defined by freeimage:

TIFF*
TIFFOpen(const char* name, const char* mode) {
        return 0;
}

Which surely enough would make the libtiff backend here fail if called.

Not imv's problem.

chewi commented

Ech, that patch was provided by a user and this isn't the first problem we've had with it. When I asked them to correct it last time, they never replied so I ended up having to fix it myself. I guess I'll be doing that again then.

Thanks for doing the investigation