Bug 210259 - Scan crashed on multi-layer TIFFs
Summary: Scan crashed on multi-layer TIFFs
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-DImg-TIFF (show other bugs)
Version: 1.0.0
Platform: Microsoft Windows Microsoft Windows
: NOR crash
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-12 01:02 UTC by francois
Modified: 2017-08-01 20:23 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 1.2.0


Attachments
Relevant output from Massif (31.69 KB, text/x-vhdl)
2009-10-17 14:03 UTC, Marcel Wiesweg
Details
TIFF Image that makes digikam 1.2.0 crash (412.46 KB, image/tiff)
2010-03-04 04:51 UTC, frith.foottit
Details

Note You need to log in before you can comment on or make changes to this bug.
Description francois 2009-10-12 01:02:43 UTC
Version:           1.0.0 beta 5 (using KDE 4.3.2)
Compiler:          Windows pre-compiled executables Windows pre-compiled executables
OS:                MS Windows
Installed from:    MS Windows

TIFF is 236MB with three layers. Layers above base layer are in Multiply & Screen mode; both have layer masks. Crash occurs during startup scan, or if aborted, during later scan. Established that it was a particular image at fault by renaming it, moving it, etc. DigiKam options are all set to default.

Metadata exactly the same as all the other single-layered TIFFs produced with a Nikon LS-5000 (which were no trouble for digiKam).
Comment 1 caulier.gilles 2009-10-12 06:38:00 UTC
Can you give us a backtrace to see where is the problem ?

Can you try under linux to see if problem exist too ?

Can you provide a tiff file to test ?

Gilles Caulier
Comment 2 Marcel Wiesweg 2009-10-12 15:42:30 UTC
Can we assume that this happens due to the size of this image (doesn't happen with smaller tiffs?)
Backtrace would be the most interesting piece of information here.
Comment 3 francois 2009-10-12 23:57:58 UTC
Thanks for the interest. Being a noob you'll have to be a bit patient ;)

First I tested the size hypothesis, which appears valid. Using only "normal" mode for the layers, no mask (but some transparency), digiKam reads a 215MB file, but chokes on 236MB. Currently uploading files to file sharing site, but that's going to take a bit of time...

Looking into producing a backtrace under Windows XP.
Comment 4 francois 2009-10-13 01:38:18 UTC
Here are the file:
http://dl.free.fr/qZ7HT26Rk

Can't say the backtrace research has been particularly fruitful :(
Comment 5 Marcel Wiesweg 2009-10-17 14:02:08 UTC
Andreas, we have a memory allocation problem with exiv2 here.
I will attach output from massif (heap profiler). When scanning the image in question, libexiv2 will allocate a total of 1209MB of memory (in seven parts of around 172MB each)

Note: from the link posted by Francois above, you can download a ZIP file containing two sample TIFFs.
Comment 6 Marcel Wiesweg 2009-10-17 14:03:39 UTC
Created attachment 37634 [details]
Relevant output from Massif

(read with automatic line breaking disabled)
Comment 7 Marcel Wiesweg 2009-10-17 14:04:45 UTC
Is this related to bug #183171?
Comment 8 Andreas Huggel 2009-10-17 14:40:38 UTC
Marcel,

Exiv2 uses more memory than necessary when writing to TIFFs, that's a known issue. See here: http://dev.exiv2.org/issues/show/617

However, a normal "intrusive" write operation should not allocate more than about 2x the size of the image. Try simple commands like those in the issue to verify. (I can't download such a large file right now, slow internet connections seem to follow me around...)

Additional memory allocated is likely from suboptimal use of the library.

Andreas
Comment 9 Marcel Wiesweg 2009-10-17 16:39:48 UTC
So with a 236MB image, 2*image size is already about 500MB ;-)

So this is indeed an incarnation of bug 183171 (when reading, to store the read data, we do something supposed to be done only when writing).

Francois: Bug 183171 will be fixed soon, but it requires API changes in libkexiv2, so the fix will be in KDE4.4 only.
Comment 10 Andreas Huggel 2009-10-17 23:35:48 UTC
> So with a 236MB image, 2*image size is already about 500MB ;-)

That's why there is http://dev.exiv2.org/issues/show/617 

In the unstable branch in SVN it is partly fixed, the image is only loaded once, eventually it will not be necessary to load the image anymore at all. But that also requires API changes.

Andreas
Comment 11 Andreas Huggel 2009-11-07 18:02:26 UTC
The Exiv2 part is now complete and the results are quite drastic. See http://dev.exiv2.org/issues/show/617

This is still in the unstable branch in the Exiv2 SVN for the moment, but will go into the trunk and then become 0.19 (hopefully) soon. I'd be grateful if someone took the trouble to compile digiKam/libkexiv2 against exiv2-unstable and could report if there are issues with the API changes.

Andreas
Comment 12 caulier.gilles 2009-12-25 20:09:49 UTC
digiKam 1.0.0 is out since few days...

http://www.digikam.org/drupal/node/491

Please try with this version coming with more than 400 bug-fixes.

Thanks in advance

Gilles Caulier
Comment 13 caulier.gilles 2010-01-25 21:49:43 UTC
digiKam 1.1. release will be done in few days. Please check if this entry still valid.

Thanks in advance

Gilles Caulier
Comment 14 francois 2010-01-30 23:18:09 UTC
Thanks a lot Gilles, Marel and Andreas. Tried 1.0.0 but it crashes every time at startup so cannot test how well it scans large files. Hopefully I'll have more luck with 1.1.
Comment 15 frith.foottit 2010-03-03 04:51:15 UTC
Not 100% sure this is the same bug, but I did have a crash on scanning that was fixed by removing the .TIFFs from my photos folder. The largest one was very close to exactly 200MB.

Using linux version 1.2.0 on Ubuntu (downloaded from SVN and compiled on 2nd March 2010), not sure what the library versions are - I just used apt-get build-dep digikam.

Happy to provide any more info if needed, but I can't quite work out how to get the debug info properly - I have installed various '-dbg' packages, but the crash reporter still says that the crash information is not useful.
Comment 16 Andreas Huggel 2010-03-03 05:21:44 UTC
What version of exiv2 are you using? Run the following command to check (assuming you have the exiv2 utility installed, not only the library)

$ exiv2 -V

If it's 0.19, can you post the output of this:

$ ls -la *.TIFF
$ time exiv2 *.TIFF >/dev/null

If it's < 0.19, pls upgrade to 0.19 and re-compile digikam + libkexiv2 against that

Thanks,
Andreas
Comment 17 frith.foottit 2010-03-03 10:52:57 UTC
Okay, so now I'm stuck.

I ran 'exiv2 -V', and it said that I have version 0.18 (can't remember if there was a minor number) installed.

So I checked the latest version of exiv2 out of svn (using the instructions on the website), compiled that via cmake, make, sudo make install. Then I re-compiled digikam, via cmake, make, sudo make install.

Now if I hit Help->Component information, it says:
(abridged)

digiKam version 1.2.0 (rev.: 1098216)
LibExiv2: 0.18.2

I can't understand why the new version of libexiv2 isn't overwriting the old version. Any thoughts? I also notice that the command line program 'exiv2' doesn't get installed - I have to manually run it from the compiled src directory. Perhaps the install is just silently failing?

I suspect that fixing this would fix the problem, but the solution might end up being that I have to wait for the next release of Ubuntu - I notice that version .19 of exiv2 is in the list of packages for Lucid.

Then again, maybe its time to try a different distro...
Comment 18 Andreas Huggel 2010-03-03 13:30:32 UTC
> So I checked the latest version of exiv2 out of svn (using the instructions on
> the website), compiled that via cmake, make, sudo make install. 

Good. The current trunk is better than 0.19. But instead of cmake, do

$ make config; ./configure; make; sudo make install

(cmake is highly experimental - see README-cmake)

> Then I
> re-compiled digikam, via cmake, make, sudo make install.
> Now if I hit Help->Component information, it says:
> (abridged)
> 
> digiKam version 1.2.0 (rev.: 1098216)
> LibExiv2: 0.18.2
> 
> I can't understand why the new version of libexiv2 isn't overwriting the old
> version. Any thoughts? 

Did you re-compile libkexiv2? - note the 'k' If not, that's probably the issue. 

> I also notice that the command line program 'exiv2'
> doesn't get installed - I have to manually run it from the compiled src
> directory. Perhaps the install is just silently failing?

Compile & install exiv2 as suggested above and it will get installed. But this won't fix your other problem.
Comment 19 frith.foottit 2010-03-04 03:35:57 UTC
Okay, so I got exiv2 -V to show version 19.1

Then I tried to download and recompile the svn versions of both kdegraphics and digikam. The compile seemed to work, but now digikam won't even start up. It crashes on the 'loading kipi-plugins' part of the splash screen. I used the automatic bug tracker to add it as a separate bug - https://bugs.kde.org/show_bug.cgi?id=229344

Here is the output of those commands:

frith@sally:~/trouble_images/test$ ls -la
total 162468
drwxr-xr-x 2 frith frith      4096 2010-03-04 13:29 .
drwxr-xr-x 3 frith frith      4096 2010-03-04 13:27 ..
-rw-r--r-- 1 frith frith 164909860 2010-03-04 13:28 CardinalNewman_dinner.tif
-rwxr-xr-x 1 frith frith     75934 2009-06-17 14:02 import_010518.tif
-rwxr-xr-x 1 frith frith     76568 2009-06-17 14:02 import_010519.tif
-rwxr-xr-x 1 frith frith    171370 2009-06-17 14:04 import_011102.tif
-rwxr-xr-x 1 frith frith    440064 2009-06-16 12:12 pic_008434.tif
-rwxr-xr-x 1 frith frith    422358 2009-06-16 12:12 pic_009022.tif
-rwxr-xr-x 1 frith frith     18900 2009-06-16 21:53 pic_009335.tif
-rwxr-xr-x 1 frith frith    223594 2009-06-16 12:12 pic_009816.tif
frith@sally:~/trouble_images/test$ time exiv2 *.tif > /dev/null 
exiv2: tiffvisitor.cpp:1188: virtual void Exiv2::Internal::TiffReader::visitDirectory(Exiv2::Internal::TiffDirectory*): Assertion `tc.get()' failed.
Aborted

real	0m0.013s
user	0m0.004s
sys	0m0.008s
frith@sally:~/trouble_images/test$ 

What is interesting is that the exiv2 command works fine on any of the images individually, but something seems to happen when doing the whole lot.
Comment 20 Andreas Huggel 2010-03-04 04:31:38 UTC
The failed assertion is an exiv2 bug. And it's very weird if that happens only when the utility operates on all of the images, but not an individual one.

Can you run exiv2 -pa *.tif and post the output here? If possible with the last image processed before the crash (unless it's the big one...)

Thanks,
Andreas
Comment 21 frith.foottit 2010-03-04 04:51:53 UTC
Created attachment 41308 [details]
TIFF Image that makes digikam 1.2.0 crash

This is an image that seems to trigger a bug in exiv2.
Comment 22 Andreas Huggel 2010-03-04 14:47:19 UTC
Thanks for the image.

I've created an Exiv2 bug for this: http://dev.exiv2.org/issues/show/684
and checked-in a quickfix with r2034. This change is binary compatible, all you need to do is re-compile and re-install Exiv2, digiKam & Co don't need to be re-built.

The quickfix removes the assertion failure but Exiv2 still only handles the first for sub-IFDs. Further sub-IFDs are not decoded and, more important, if you write to the sample TIFF image using this revision of Exiv2, it may remove sub-IFDs beyond the first four.

Next I'll work on a better solution, but that will not be binary compatible anymore.

Andreas
Comment 23 Andreas Huggel 2010-03-04 15:47:55 UTC
> Next I'll work on a better solution, but that will not be binary compatible
anymore.

Checked-in Exiv2 r2035 with extended sub-IFD support. Make sure you re-compile digiKam & Co if you use this.

-ahu.
Comment 24 frith.foottit 2010-03-10 01:18:48 UTC
Fixed.

I updated from the SVN the digikam/kdegraphics/exiv2 libraries and now it compiles, installs, loads and correctly displays all the TIF files in my collection.

Thanks for all your help and efforts, this is a great piece of software.

-Frith.