comparison Core/DicomFormat/DicomMap.cpp @ 3771:74889e6f6d68

fix memory issues if parsing invalid DICOM file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Mar 2020 19:19:48 +0100
parents 56f2397f027a
children e7003b2203a7
comparison
equal deleted inserted replaced
3769:eb044cc49d51 3771:74889e6f6d68
743 743
744 return true; 744 return true;
745 } 745 }
746 746
747 747
748 bool DicomMap::ParseDicomMetaInformation(DicomMap& result, 748 bool DicomMap::IsDicomFile(const char* dicom,
749 const char* dicom, 749 size_t size)
750 size_t size)
751 { 750 {
752 /** 751 /**
753 * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html 752 * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html
754 * According to Table 7.1-1, besides the "DICM" DICOM prefix, the 753 * According to Table 7.1-1, besides the "DICM" DICOM prefix, the
755 * file preamble (i.e. dicom[0..127]) should not be taken into 754 * file preamble (i.e. dicom[0..127]) should not be taken into
756 * account to determine whether the file is or is not a DICOM file. 755 * account to determine whether the file is or is not a DICOM file.
757 **/ 756 **/
758 757
759 if (size < 132 || 758 return (size >= 132 &&
760 dicom[128] != 'D' || 759 dicom[128] == 'D' &&
761 dicom[129] != 'I' || 760 dicom[129] == 'I' &&
762 dicom[130] != 'C' || 761 dicom[130] == 'C' &&
763 dicom[131] != 'M') 762 dicom[131] == 'M');
763 }
764
765
766 bool DicomMap::ParseDicomMetaInformation(DicomMap& result,
767 const char* dicom,
768 size_t size)
769 {
770 if (!IsDicomFile(dicom, size))
764 { 771 {
765 return false; 772 return false;
766 } 773 }
767 774
768 775