summaryrefslogtreecommitdiffstats
path: root/lzip_index.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lzip_index.cc15
1 files changed, 7 insertions, 8 deletions
diff --git a/lzip_index.cc b/lzip_index.cc
index 8d1aa0c..ad9157b 100644
--- a/lzip_index.cc
+++ b/lzip_index.cc
@@ -45,9 +45,8 @@ int seek_read( const int fd, uint8_t * const buf, const int size,
bool Lzip_index::check_header( const Lzip_header & header, const bool first )
{
- if( !header.check_magic() )
- { error_ = bad_magic_msg; retval_ = 2; if( first ) bad_magic_ = true;
- return false; }
+ if( header.check_magic() ) { if( first ) good_magic_ = true; }
+ else { error_ = bad_magic_msg; retval_ = 2; return false; }
if( !header.check_version() )
{ error_ = bad_version( header.version() ); retval_ = 2; return false; }
if( !isvalid_ds( header.dictionary_size() ) )
@@ -145,20 +144,20 @@ bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
Lzip_index::Lzip_index( const int infd, const Cl_options & cl_opts )
: insize( lseek( infd, 0, SEEK_END ) ), retval_( 0 ), dictionary_size_( 0 ),
- bad_magic_( false )
+ good_magic_( false )
{
if( insize < 0 )
{ set_errno_error( "Input file is not seekable: " ); return; }
+ Lzip_header header;
+ if( insize >= header.size &&
+ ( !read_header( infd, header, 0 ) ||
+ !check_header( header, true ) ) ) return;
if( insize < min_member_size )
{ error_ = "Input file is too short."; retval_ = 2; return; }
if( insize > INT64_MAX )
{ error_ = "Input file is too long (2^63 bytes or more).";
retval_ = 2; return; }
- Lzip_header header;
- if( !read_header( infd, header, 0 ) ||
- !check_header( header, true ) ) return;
-
unsigned long long pos = insize; // always points to a header or to EOF
while( pos >= min_member_size )
{