From e70de17d8fbbb35b020373e0bd2a1b53e9deeaf9 Mon Sep 17 00:00:00 2001 From: regrain Date: Mon, 6 Dec 2004 12:54:40 +0000 Subject: [PATCH] * src/gdcmDocument.cxx : bug fix when opening the file. All read is followed by an eof to prevent all bad read of the file... and in this case, the file isn't readable. -- BeNours --- ChangeLog | 5 +++++ src/gdcmDocument.cxx | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85b2c664..5e1419d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-12-06 Benoit Regrain + * src/gdcmDocument.cxx : bug fix when opening the file. All read is followed + by an eof to prevent all bad read of the file... and in this case, the + file isn't readable. + 2004-12-06 Benoit Regrain * Example/Volume2Dicom.cxx : comment unused variables * Test/PrintDicomDir.cxx : comment unused variables diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 2a91d1c2..60c002f2 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/12/06 11:37:38 $ - Version: $Revision: 1.147 $ + Date: $Date: 2004/12/06 12:54:40 $ + Version: $Revision: 1.148 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -442,7 +442,12 @@ std::ifstream* Document::OpenFile() } uint16_t zero; - Fp->read((char*)&zero, (size_t)2 ); + Fp->read((char*)&zero, (size_t)2); + if( Fp->eof() ) + { + CloseFile(); + return 0; + } //ACR -- or DICOM with no Preamble; may start with a Shadow Group -- if( @@ -458,6 +463,11 @@ std::ifstream* Document::OpenFile() Fp->seekg(126L, std::ios::cur); char dicm[4]; Fp->read(dicm, (size_t)4); + if( Fp->eof() ) + { + CloseFile(); + return 0; + } if( memcmp(dicm, "DICM", 4) == 0 ) { return Fp; @@ -1899,8 +1909,6 @@ void Document::FindDocEntryVR( DocEntry *entry ) // within an explicit VR file. Hence we make sure the present tag // is in explicit VR and try to fix things if it happens not to be // the case. - vr[0] = 0x00; - vr[1] = 0x00; Fp->read (vr, (size_t)2); vr[2] = 0; -- 2.48.1