1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
--- a/zipios++/zipheadio.h 2000-09-20 10:46:59.000000000 -0700
+++ b/zipios++/zipheadio.h 2019-07-09 08:23:45.122804315 -0700
@@ -9,6 +9,7 @@
#include "zipios++/ziphead.h"
#include "zipios++/zipios_defs.h"
+#include "zipios++/fcollexceptions.h"
namespace zipios {
@@ -79,10 +80,16 @@ inline uint32 readUint32 ( istream &is ) {
static const int buf_len = sizeof ( uint32 ) ;
unsigned char buf [ buf_len ] ;
int rsf = 0 ;
- while ( rsf < buf_len ) {
+ std::streampos original_pos = is.tellg() ;
+ while ( rsf < buf_len && !is.eof() ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
rsf += static_cast< int >( is.gcount () ) ;
}
+ if ( rsf != buf_len ) {
+ is.seekg( original_pos ) ;
+ throw InvalidStateException( "Reached end-of-file while trying to read a"
+ "Uint32; the zip archive may be corrupt." ) ;
+ }
return ztohl ( buf ) ;
}
@@ -95,10 +102,16 @@ inline uint16 readUint16 ( istream &is ) {
static const int buf_len = sizeof ( uint16 ) ;
unsigned char buf [ buf_len ] ;
int rsf = 0 ;
- while ( rsf < buf_len ) {
+ std::streampos original_pos = is.tellg() ;
+ while ( rsf < buf_len && !is.eof() ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
rsf += static_cast< int >( is.gcount () ) ;
}
+ if ( rsf != buf_len ) {
+ is.seekg( original_pos ) ;
+ throw InvalidStateException( "Reached end-of-file while trying to read a"
+ "Uint16; the zip archive may be corrupt." ) ;
+ }
return ztohs ( buf ) ;
}
|