summaryrefslogtreecommitdiffstats
path: root/file_index.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:06:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:06:25 +0000
commitaeab49c877a93051065ab41625d9b13a6017c1d6 (patch)
treecd8f68d5ee0caebf508f6d4f1595d8656f0bff55 /file_index.cc
parentReleasing debian version 1.6-5. (diff)
downloadplzip-aeab49c877a93051065ab41625d9b13a6017c1d6.tar.xz
plzip-aeab49c877a93051065ab41625d9b13a6017c1d6.zip
Merging upstream version 1.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'file_index.cc')
-rw-r--r--file_index.cc37
1 files changed, 20 insertions, 17 deletions
diff --git a/file_index.cc b/file_index.cc
index 581b516..8238054 100644
--- a/file_index.cc
+++ b/file_index.cc
@@ -1,5 +1,5 @@
/* Plzip - Parallel compressor compatible with lzip
- Copyright (C) 2009-2017 Antonio Diaz Diaz.
+ Copyright (C) 2009-2018 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -60,7 +60,8 @@ void File_index::set_num_error( const char * const msg, unsigned long long num )
// If successful, push last member and set pos to member header.
-bool File_index::skip_trailing_data( const int fd, long long & pos )
+bool File_index::skip_trailing_data( const int fd, long long & pos,
+ const bool ignore_trailing, const bool loose_trailing )
{
enum { block_size = 16384,
buffer_size = block_size + File_trailer::size - 1 + File_header::size };
@@ -95,10 +96,13 @@ bool File_index::skip_trailing_data( const int fd, long long & pos )
if( !header.verify_magic() || !header.verify_version() ||
!isvalid_ds( dictionary_size ) ) continue;
if( (*(File_header *)( buffer + i )).verify_prefix( bsize - i ) )
- {
- error_ = "Last member in input file is truncated or corrupt.";
- retval_ = 2; return false;
- }
+ { error_ = "Last member in input file is truncated or corrupt.";
+ retval_ = 2; return false; }
+ if( !loose_trailing && bsize - i >= File_header::size &&
+ (*(File_header *)( buffer + i )).verify_corrupt() )
+ { error_ = corrupt_mm_msg; retval_ = 2; return false; }
+ if( !ignore_trailing )
+ { error_ = trailing_msg; retval_ = 2; return false; }
pos = ipos + i - member_size;
member_vector.push_back( Member( 0, trailer.data_size(), pos,
member_size, dictionary_size ) );
@@ -116,7 +120,8 @@ bool File_index::skip_trailing_data( const int fd, long long & pos )
}
-File_index::File_index( const int infd, const bool ignore_trailing )
+File_index::File_index( const int infd, const bool ignore_trailing,
+ const bool loose_trailing )
: isize( lseek( infd, 0, SEEK_END ) ), retval_( 0 )
{
if( isize < 0 )
@@ -147,11 +152,10 @@ File_index::File_index( const int infd, const bool ignore_trailing )
const unsigned long long member_size = trailer.member_size();
if( member_size < min_member_size || member_size > (unsigned long long)pos )
{
- if( !member_vector.empty() )
- set_num_error( "Member size in trailer is corrupt at pos ", pos - 8 );
- else if( skip_trailing_data( infd, pos ) )
- { if( ignore_trailing ) continue;
- error_ = trailing_msg; retval_ = 2; return; }
+ if( member_vector.empty() )
+ { if( skip_trailing_data( infd, pos, ignore_trailing, loose_trailing ) )
+ continue; else return; }
+ set_num_error( "Member size in trailer is corrupt at pos ", pos - 8 );
break;
}
if( seek_read( infd, header.data, File_header::size,
@@ -161,11 +165,10 @@ File_index::File_index( const int infd, const bool ignore_trailing )
if( !header.verify_magic() || !header.verify_version() ||
!isvalid_ds( dictionary_size ) )
{
- if( !member_vector.empty() )
- set_num_error( "Bad header at pos ", pos - member_size );
- else if( skip_trailing_data( infd, pos ) )
- { if( ignore_trailing ) continue;
- error_ = trailing_msg; retval_ = 2; return; }
+ if( member_vector.empty() )
+ { if( skip_trailing_data( infd, pos, ignore_trailing, loose_trailing ) )
+ continue; else return; }
+ set_num_error( "Bad header at pos ", pos - member_size );
break;
}
pos -= member_size;