summaryrefslogtreecommitdiffstats
path: root/lzip_index.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-12-04 03:34:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-12-04 03:34:45 +0000
commitb1aab60d515050a32bc5764d0106aa01c10a4c0d (patch)
treef8704120bc97b8080b0d88a478dbaf665cb5145a /lzip_index.cc
parentReleasing debian version 1.24.1-2. (diff)
downloadlzip-b1aab60d515050a32bc5764d0106aa01c10a4c0d.tar.xz
lzip-b1aab60d515050a32bc5764d0106aa01c10a4c0d.zip
Merging upstream version 1.25~rc1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzip_index.cc')
-rw-r--r--lzip_index.cc35
1 files changed, 12 insertions, 23 deletions
diff --git a/lzip_index.cc b/lzip_index.cc
index 6c1caf2..d9cfd0c 100644
--- a/lzip_index.cc
+++ b/lzip_index.cc
@@ -70,13 +70,10 @@ void Lzip_index::set_num_error( const char * const msg, unsigned long long num )
bool Lzip_index::read_header( const int fd, Lzip_header & header,
- const long long pos, const bool ignore_marking )
+ const long long pos )
{
if( seek_read( fd, header.data, header.size, pos ) != header.size )
{ set_errno_error( "Error reading member header: " ); return false; }
- uint8_t byte;
- if( !ignore_marking && readblock( fd, &byte, 1 ) == 1 && byte != 0 )
- { error_ = marking_msg; retval_ = 2; return false; }
return true;
}
@@ -110,8 +107,7 @@ bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
{ while( i > trailer.size && buffer[i-9] == 0 ) --i; continue; }
if( member_size > ipos + i || !trailer.check_consistency() ) continue;
Lzip_header header;
- if( !read_header( fd, header, ipos + i - member_size,
- cl_opts.ignore_marking ) ) return false;
+ if( !read_header( fd, header, ipos + i - member_size ) ) return false;
if( !header.check() ) continue;
const Lzip_header & header2 = *(const Lzip_header *)( buffer + i );
const bool full_h2 = bsize - i >= header.size;
@@ -126,15 +122,12 @@ bool Lzip_index::skip_trailing_data( const int fd, unsigned long long & pos,
{ error_ = corrupt_mm_msg; retval_ = 2; return false; }
if( !cl_opts.ignore_trailing )
{ error_ = trailing_msg; retval_ = 2; return false; }
- const unsigned long long data_size = trailer.data_size();
- if( !cl_opts.ignore_empty && data_size == 0 )
- { error_ = empty_msg; retval_ = 2; return false; }
pos = ipos + i - member_size; // good member
const unsigned dictionary_size = header.dictionary_size();
if( dictionary_size_ < dictionary_size )
dictionary_size_ = dictionary_size;
- member_vector.push_back( Member( 0, data_size, pos, member_size,
- dictionary_size ) );
+ member_vector.push_back( Member( 0, trailer.data_size(), pos,
+ member_size, dictionary_size ) );
return true;
}
if( ipos == 0 )
@@ -154,16 +147,16 @@ Lzip_index::Lzip_index( const int infd, const Cl_options & cl_opts )
{
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 ) ) ) return;
if( insize < min_member_size )
- { error_ = "Input file is too short."; retval_ = 2; return; }
+ { error_ = "Input file is truncated."; 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, cl_opts.ignore_marking ) ||
- !check_header( header ) ) return;
-
unsigned long long pos = insize; // always points to a header or to EOF
while( pos >= min_member_size )
{
@@ -178,23 +171,19 @@ Lzip_index::Lzip_index( const int infd, const Cl_options & cl_opts )
{ if( skip_trailing_data( infd, pos, cl_opts ) ) continue; return; }
set_num_error( "Bad trailer at pos ", pos - trailer.size ); break;
}
- if( !read_header( infd, header, pos - member_size, cl_opts.ignore_marking ) )
- break;
+ if( !read_header( infd, header, pos - member_size ) ) break;
if( !header.check() ) // bad header
{
if( member_vector.empty() )
{ if( skip_trailing_data( infd, pos, cl_opts ) ) continue; return; }
set_num_error( "Bad header at pos ", pos - member_size ); break;
}
- const unsigned long long data_size = trailer.data_size();
- if( !cl_opts.ignore_empty && data_size == 0 )
- { error_ = empty_msg; retval_ = 2; break; }
pos -= member_size; // good member
const unsigned dictionary_size = header.dictionary_size();
if( dictionary_size_ < dictionary_size )
dictionary_size_ = dictionary_size;
- member_vector.push_back( Member( 0, data_size, pos, member_size,
- dictionary_size ) );
+ member_vector.push_back( Member( 0, trailer.data_size(), pos,
+ member_size, dictionary_size ) );
}
if( pos != 0 || member_vector.empty() || retval_ != 0 )
{