We're Hiring!

Writing tif images fails with arithmetic exception

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

Writing tif images fails with arithmetic exception

Postby bmoeller » Mon Jan 29, 2018 2:52 pm

Dear all,
we are developing a Java library for image processing in Fiji/ImageJ and use bioformats for reading and writing images from/to disk. We develop with Maven and get all our dependencies concerning Fiji, ImageJ, Bioformats, etc. from the pom-scijava artifact on org.scijava. Recently we updated to a new pom-scijava version and since then errors occur when we try to save images in tif format. Indeed we figured out that the saving worked until version 17.2.0 of pom-scijava, but starting with 18.0.0 saving images fails. We did not do any changes to related parts of our code. It seems that the change from ome-common-5.3.2.jar to ome-common-5.3.3.jar causes the writing to fail. At least we could fix the issue on some systems by replacing the new ome-common-5.3.3.jar with the old one ome-common-5.3.2.jar.

To demonstrate the issue I have put a small demo program on Github, https://github.com/bimoelle/bioformatsProblem. The demo program "Problem.java" generates a small ImageJ ImagePlus and saves it as file in tif format. As long as we are compiling and running the program with ome-common-5.3.2.jar (and related dependencies) everything is fine (runTest.sh, first half), but when we switch to the new version the program crashes with a division by zero exception (second half in runTest.sh):

Code: Select all
Exception in thread "main" java.lang.ArithmeticException: / by zero
   at loci.formats.tiff.IFD.getTilesPerRow(IFD.java:509)
   at loci.formats.tiff.TiffSaver.writeIFDStrips(TiffSaver.java:879)
   at loci.formats.tiff.TiffSaver.writeImageIFD(TiffSaver.java:451)
   at loci.formats.tiff.TiffSaver.writeImage(TiffSaver.java:401)
   at loci.formats.tiff.TiffSaver.writeImage(TiffSaver.java:277)
   at loci.formats.out.TiffWriter.saveBytes(TiffWriter.java:270)
   at loci.formats.out.TiffWriter.saveBytes(TiffWriter.java:479)
   at loci.formats.FormatWriter.saveBytes(FormatWriter.java:123)
   at Problem.main(Problem.java:295)


We have tried to localize the error and to us it appears as if the RandomAccessInputStream used by the TiffWriter class is involved in producing the error, i.e. seems to return wrong data in some cases. The writer seems to first read a tif file potentially already existing at the target location before writing the new data to file. In version 5.3.3 this seems to end-up in an error if there is no proper tif file (e.g., no file at all, just an empty file or a file not in tif format) located at the target location. Contrary, if there exists such a file the error disappears and saving the image works fine. In version 5.3.2 saving works if there is no file or a proper tif image file. However, in case that the file is corrupt (not a tif file, empty, etc.) the writer in version 5.3.2 also fails.

We are developing on Linux, but could also reproduce the error on Windows machines. We are looking forward to your support and any hint that might help us to overcome this issue and enables us to save tif images again using Bioformats.
Thanks in advance and best regards,

Birgit
bmoeller
 
Posts: 2
Joined: Fri Jan 26, 2018 1:26 pm

Re: Writing tif images fails with arithmetic exception

Postby sbesson » Mon Jan 29, 2018 4:05 pm

Dear Birgit,

thank you very much for your detailed report including all steps required to reproduce the issue.

The 5.3.3 release of ome-common included some changes to improve the TIFF writing on Windows as suggested by our profiling. Unfortunately after cutting the ome-common release and testing the integration in Bio-Formats, we hit similar issue as the one you reported below and flagged by the failures of the TIFF writing unit tests. This version of ome-common was never exposed in a release of Bio-Formats and as the fix ended up being non trivial, we decided to simply revert the changes in the release 5.3.4 of ome-common. See this card for more detailed information.

Unfortunately, the ome-common dependency declared in pom-scijava is managed separately of the high-level Bio-Formats and got bumped independently in https://github.com/scijava/pom-scijava/ ... 2bd22c40a3 causing the failures you reported in the following release. We have opened a PR against pom-scijava to bump this dependency to 5.3.4 and we hope the next release of pom-scijava will resolve the problem.

Our most since apologies for the issue, we hope this did not lead in the creation of corrupted TIFF data in the interim.
Best regards,
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: Writing tif images fails with arithmetic exception

Postby bmoeller » Mon Jan 29, 2018 4:53 pm

Dear Sebastien,
thanks for your quick reply! It's good to hear that we were on the right path and that it was indeed not our own fault ;) And even better to hear that the issue is already fixed in the latest release. Fortunately since we only recently did the update and almost immediately noticed the problem to our knowledge no files were corrupted so far. Since pom-scijava is updated quite regularly I think that there is a good chance that the new version will be integrated soon and will then be available also in Fiji solving the problem for us.

Thanks again and best regards,

Birgit
bmoeller
 
Posts: 2
Joined: Fri Jan 26, 2018 1:26 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest

cron