Skip to content

Commit

Permalink
BUG: Address buffer overflow with deprecated GDCM1 interface
Browse files Browse the repository at this point in the history
This is a back port of commit 49c4663
to the 4.13 release to address a buffer overflow issue. This change
only addresses the internal usage of the methods with an internal
fixed maximum length which does not change the API of GDCMImageIO.
  • Loading branch information
blowekamp committed Nov 7, 2019
1 parent f64fdf6 commit 5df152b
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1241,127 +1241,159 @@ void GDCMImageIO::GetPatientName(char *name)
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0010|0010", m_PatientName);
strcpy ( name, m_PatientName.c_str() );
const size_t len = 512;
strncpy ( name, m_PatientName.c_str(), len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetPatientID(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0010|0020", m_PatientID);
strcpy ( name, m_PatientID.c_str() );
const size_t len = 512;
strncpy ( name, m_PatientID.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetPatientSex(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0010|0040", m_PatientSex);
strcpy ( name, m_PatientSex.c_str() );
const size_t len = 512;
strncpy ( name, m_PatientSex.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetPatientAge(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0010|1010", m_PatientAge);
strcpy ( name, m_PatientAge.c_str() );
const size_t len = 512;
strncpy ( name, m_PatientAge.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetStudyID(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0020|0010", m_StudyID);
strcpy ( name, m_StudyID.c_str() );
const size_t len = 512;
strncpy ( name, m_StudyID.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetPatientDOB(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0010|0030", m_PatientDOB);
strcpy ( name, m_PatientDOB.c_str() );
const size_t len = 512;
strncpy ( name, m_PatientDOB.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetStudyDescription(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|1030", m_StudyDescription);
strcpy ( name, m_StudyDescription.c_str() );
const size_t len = 512;
strncpy ( name, m_StudyDescription.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetBodyPart(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0018|0015", m_BodyPart);
strcpy ( name, m_BodyPart.c_str() );
const size_t len = 512;
strncpy ( name, m_BodyPart.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetNumberOfSeriesInStudy(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0020|1000", m_NumberOfSeriesInStudy);
strcpy ( name, m_NumberOfSeriesInStudy.c_str() );
const size_t len = 512;
strncpy ( name, m_NumberOfSeriesInStudy.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetNumberOfStudyRelatedSeries(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0020|1206", m_NumberOfStudyRelatedSeries);
strcpy ( name, m_NumberOfStudyRelatedSeries.c_str() );
const size_t len = 512;
strncpy ( name, m_NumberOfStudyRelatedSeries.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetStudyDate(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|0020", m_StudyDate);
strcpy ( name, m_StudyDate.c_str() );
const size_t len = 512;
strncpy ( name, m_StudyDate.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetModality(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|0060", m_Modality);
strcpy ( name, m_Modality.c_str() );
const size_t len = 512;
strncpy ( name, m_Modality.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetManufacturer(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|0070", m_Manufacturer);
strcpy ( name, m_Manufacturer.c_str() );
const size_t len = 512;
strncpy ( name, m_Manufacturer.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetInstitution(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|0080", m_Institution);
strcpy ( name, m_Institution.c_str() );
const size_t len = 512;
strncpy ( name, m_Institution.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetModel(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0008|1090", m_Model);
strcpy ( name, m_Model.c_str() );
const size_t len = 512;
strncpy ( name, m_Model.c_str() , len-1);
name[len-1] = '0';
}

void GDCMImageIO::GetScanOptions(char *name)
{
MetaDataDictionary & dict = this->GetMetaDataDictionary();

ExposeMetaData< std::string >(dict, "0018|0022", m_ScanOptions);
strcpy ( name, m_ScanOptions.c_str() );
const size_t len = 512;
strncpy ( name, m_ScanOptions.c_str() , len-1);
name[len-1] = '0';
}
#endif

Expand Down

0 comments on commit 5df152b

Please sign in to comment.