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