[Insight-users] Read image header info functions doesn't work? Memory access violation?

Julien Jomier jjomier at cs.unc.edu
Fri Dec 3 14:33:08 EST 2004


Hi Juan,

This has been fixed 3 months ago in the cvs repository (not in ITK 1.8). 
Your option is to update your current version of ITK using cvs or to 
just get the new files from the cvsweb and copy them in your current 
Insight. 
(http://www.itk.org/cgi-bin/viewcvs.cgi/Utilities/DICOMParser/?root=Insight)

Hope this helps,

Julien

Jun Tan wrote:
> Hi, Luis and everybody:
> I'm not able to get header information correctly by calling functions
> such as "GetPatientName" of "DICOMImageIO2". Each time the program
> caused some access violation problem.
> 
> When I traced into file "DICOMAppHelper.h", I found this:
>   void GetPatientName(char* name)
>     {
> a:    strcpy(name, m_PatientName);
>     }
> 
> When I traced further into file "DICOMAppHelper.cxx", I found the
> following function definition:
> void DICOMAppHelper::PatientNameCallback(DICOMParser *,
>                                    doublebyte,
>                                    doublebyte,
>                                    DICOMParser::VRTypes,
>                                    unsigned char* val,
>                                    quadbyte len)
> {
>   if (val)
>     {
> b:    strncpy(m_PatientName, (const char*)val, len < 512 ? len : 511);
>     }
>   else
>     {
>     m_PatientName[0] = '\0';
>     }
> }
> 
> In "b:", only "len" characters are copied and there is no NULL('\0')
> character appended to the end of m_PatientName. This will make "a:"
> illegally overwrite some memory area.
> The reason is that m_PatientName is unfortunately not initialized as
> "\0\0\0\0\0\0\0\0\0\0....." but as "\-51\-51\-51\-51\-51......", it
> does not contain a '\0' and the "strcpy" in "a:" will search and copy
> characters until it hits a '\0' somewhere(no one knows where it is) in
> the memory.
> 
> I'm just wondering if this is a bug or I am using something
> incorrectly? I'm using VC++6 under Windows XP. I don't know whether
> other C++ compilers have this problem or not. However, maybe manual
> initialization for m_PatientName, m_....., or just appending a NULL
> character is a good idea. Thank you.
> 
> Best regards,
> _______________________________________________
> 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