[Insight-users] AnalyzeImageIO bug: file loading exception for non-hdr files
Gavin Baker
gavinb+xtk@cs.mu.OZ.AU
Thu, 17 Apr 2003 20:29:41 +1000
Hello,
While writing an extension to add another file type to ITK, I
discovered a bug in the AnalyzeImageIO code. (This is in the official
1.2.0 release.) This bug is masked by the fact that in the default
distribution, it is the last registered file extension, and thus does
not normally occur. But any file IO handler registered _after_
AnalyzeImageIO will fail, regardless.
When trying to read another file format, the failure is as follows:
ExceptionObject caught !
itk::ExceptionObject (0x807c5f8)
Location: "Unknown"
File: /home/gavinb/projects/ITK-cvs/ToolkitTIFF/Code/IO/itkAnalyzeImageIO.cxx
Line: 1002
Description: File cannot be read
If I register my own file IO handler _before_ AnalyzeImageIO, it works
fine.
It turns out to be a fairly simple logical error. The CanReadFile()
method takes the filename and tries to find a corresponding .hdr file
by replacing the extension. Thus, in this method we have:
HeaderFileName = "/data/ct/cadaver/tiff_8bit/CT_Temporal_Bone_065.hdr"
FileNameToRead = "/data/ct/cadaver/tiff_8bit/CT_Temporal_Bone_065.tif"
So the code at line 999 will always fail for a non-Analyze file, and
prevent any handler registered after it from attempting to read it.
I would propose the fix to be simply returning false instead of
throwing an exception. Similarly, I think the test following should
also not throw an exception, but simply look for a magic number in the
header and return false. And maybe even a test first for a valid file
extension.
Should I submit a patch, or file a bug report? Does ITK have bugzilla
or something?
Thanks,
:: Gavin
--
Gavin Baker Computer Vision Lab (CVMIL)
http://www.cs.mu.oz.au/~gavinb University of Melbourne