Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp Tue Mar 17 16:36:14 2020 +0100 +++ b/Core/DicomFormat/DicomMap.cpp Tue Mar 17 19:19:48 2020 +0100 @@ -745,9 +745,8 @@ } - bool DicomMap::ParseDicomMetaInformation(DicomMap& result, - const char* dicom, - size_t size) + bool DicomMap::IsDicomFile(const char* dicom, + size_t size) { /** * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html @@ -756,11 +755,19 @@ * account to determine whether the file is or is not a DICOM file. **/ - if (size < 132 || - dicom[128] != 'D' || - dicom[129] != 'I' || - dicom[130] != 'C' || - dicom[131] != 'M') + return (size >= 132 && + dicom[128] == 'D' && + dicom[129] == 'I' && + dicom[130] == 'C' && + dicom[131] == 'M'); + } + + + bool DicomMap::ParseDicomMetaInformation(DicomMap& result, + const char* dicom, + size_t size) + { + if (!IsDicomFile(dicom, size)) { return false; }