Check for null when calling TiffParser.checkHeader()#4429
Check for null when calling TiffParser.checkHeader()#4429melissalinkert wants to merge 1 commit into
Conversation
sbesson
left a comment
There was a problem hiding this comment.
The proposed changes are consistent with other readers like FlowSightReader.java or MinimalTiffReader which check the output of TiffParser.checkHeader and throw a FormatException if the return value is null.
To assess the functional impact on the readers, I constructed a synthetic Metamorph dataset derived from a public sample, replacing individual TIFF files by empty files. When the first TIFF file in the list (test_timelapse_20240816_s1_t1.TIF) is corrupted, using both Bio-Formats 8.5.0 or this PR, the reader initialization would fail on the file with:
loci.formats.FormatException: Invalid TIFF file: /Users/sbesson/Downloads/Bio-Formats_testdata/test_timelapse_20240816_s1_t1.TIF
at loci.formats.in.MinimalTiffReader.initFile(MinimalTiffReader.java:452)
at loci.formats.in.BaseTiffReader.initFile(BaseTiffReader.java:609)
at loci.formats.in.MetamorphReader.initFile(MetamorphReader.java:425)
at loci.formats.FormatReader.setId(FormatReader.java:1480)
at loci.formats.ImageReader.setId(ImageReader.java:864)
at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:692)
at loci.formats.tools.ImageInfo.testRead(ImageInfo.java:1054)
at loci.formats.tools.ImageInfo.main(ImageInfo.java:1165)
When corrupting another file e.g. test_timelapse_20240816_s1_t2.TIF, the latest release of Bio-Formats 8.5.0 initializes the dataset, does not includes test_timelapse_20240816_s1_t2.TIF in the used files list and renders the corresponding plane as empty. With this change, the reader fails at initialization time with:
loci.formats.FormatException: Invalid TIFF file: /Users/sbesson/Downloads/Bio-Formats_testdata/test_timelapse_20240816_s1_t2.TIF
at loci.formats.in.MetamorphReader.initFile(MetamorphReader.java:1175)
at loci.formats.FormatReader.setId(FormatReader.java:1480)
at loci.formats.ImageReader.setId(ImageReader.java:864)
at loci.formats.ReaderWrapper.setId(ReaderWrapper.java:692)
at loci.formats.tools.ImageInfo.testRead(ImageInfo.java:1054)
at loci.formats.tools.ImageInfo.main(ImageInfo.java:1165)
I will look into constructing similar examples for LeicaReader and ZeissLSMReader.
Based on the above, the outstanding question is whether increasing the strictness in terms of file validity is part of the contract/expectation of this PR or whether we want to retain the leniency of the current implementation.
Fixes #4232.
Most calls to
checkHeaderalready check for anullreturn value, or follow a call toisValidHeaderwhich checks fornullitself. In the few remaining cases here, the changes are mostly throwing a more informative exception, or logging an error when that isn't reasonable.checkHeaderreturningnullimplies that the TIFF file is invalid, so throwing an exception of some kind is usually appropriate.This should not be a breaking change, and is not expected to have any impact on tests.