[Insight-users] strncpy problem in itkAnalyzeImageIO.cxx

Luis Ibanez luis.ibanez at kitware.com
Mon Jun 21 12:28:44 EDT 2004


Jill, Hans,

The changes of memcpy/stncpy in itkAnalyzeImageIO
have been reverted.

Should we have a SPMImageIO class in order to solve
this deviation of format ?

This eventual new class could probably derive from
AnalyzeImageIO...



     Luis


--------------------
Hans Johnson wrote:

> Jill,
> 
> The header Meta-Data information is not handled implicitly by ITK, you
> must explicitly handle that with your own code.  There is a mechanism to
> attach Meta-Data to any ITK object, but the application programmer must
> judiciously propogate that information through the pipelines to make
> sure that it is preserved.  This may seem like a hassle, but it is
> actually a well thought out design decision. 
> 
> This method is not very safe.  The std::string temp is not gaunteed to
> have 10 elements in it, and this will cause a segmentation fault on
> non-spm image types.  The "10" in the strncpy(dest,sorce,10) specifies
> the following behavior: "copy source characters into dest until either a
> '\0' is reached or 10 characters have been copied".  
> 
> For spm formatted images the originator field is not treated as a
> character array (if temp=[0 128 0 128 0 64 0 0 0 0], that is 23
> characters in it).  To use the SPM format you must create an 8-bit
> unsigned array with 10 elements, and memcpy that into the originator
> feild.  This would require a new metadata tag to be created and keyed
> off of.
> 
> The SPM file format is a particularly nasty deviation from the Analyze
> 7.5 file format, and causes many people lots of headaches.  If you are
> needing SPM, then you are probably doing functional imaging, and a cross
> application functional imaging file format is being created. The
> University of Iowa contributers hope to have an implementation of the
> NIfTY file format early this fall http://nifti.nimh.nih.gov/.  
> 
> Good Luck,
> Hans J. Johnson
> hans-johnson at uiowa.edu
> 
> 
>  
> 
> On Thu, 2004-06-17 at 17:19, Jill Goldschneider 327 wrote:
> 
>>Hi,
>>
>>I have been having some problems writing Analyze (SPM extension I
>>believe) formatted images where origin information is stored in
>>the data_history's char originator[10] field.  (I believe this
>>field was originally intended to hold a character string.)
>>If I use the ImageReadWrite example with Dimension = 3, e.g.
>>  ImageReadWrite image.hdr tmp.hdr
>>tmp.hdr loses all of the information in the originator field,
>>(and other fields as well).
>>
>>What I've found, is that on a sun solaris8 system, strncpy is
>>actually NOT copying all 10 requested characters:
>>
>>    // try using [ 0 128 0 128 0 64 0 0 0 0 ] in tmp.c_str()
>>
>>    strncpy(this->m_hdr.hist.originator,temp.c_str(),10);//Note this is necessary because the array is not necessarily null terminated.
>>
>>    // look at contents of m_hdr.hist and temp.c_str,
>>    // m_hdr.hist.originator is all 0!
>>
>>If I change this statement, and all other strncpy statements
>>in the itkAnalyzeImageIO.cxx file, to use memcpy
>>
>>    memcpy(this->m_hdr.hist.originator,temp.c_str(),10);//Note this is necessary because the array is not necessarily null terminated.
>>
>>then everything works much better.
>>
>>Would someone please consider making this change?
>>
>>Thanks,
>>
>>Jill
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 





More information about the Insight-users mailing list