]> Creatis software - gdcm.git/commitdiff
* src/gdcmDocument.cxx : bug fix when opening the file. All read is followed
authorregrain <regrain>
Mon, 6 Dec 2004 12:54:40 +0000 (12:54 +0000)
committerregrain <regrain>
Mon, 6 Dec 2004 12:54:40 +0000 (12:54 +0000)
     by an eof to prevent all bad read of the file... and in this case, the
     file isn't readable.
   -- BeNours

ChangeLog
src/gdcmDocument.cxx

index 85b2c664543c33704cbb36d9c1c332e41dedc6b4..5e1419d5efb30fe96e331b543d65c43d6dc621fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-06 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * 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 <Benoit.Regrain@creatis.insa-lyon.fr>
    * Example/Volume2Dicom.cxx : comment unused variables
    * Test/PrintDicomDir.cxx : comment unused variables
index 2a91d1c2134570f346508425820150313c0256ed..60c002f2e7ac9b132a52394da37328779bbd517f 100644 (file)
@@ -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;