From b74ecd2cc2094c9644123e48ac3e2400fd8a3674 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 1 Jun 2016 16:15:38 +0200 Subject: Adding upstream version 1.5. Signed-off-by: Daniel Baumann --- file_index.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'file_index.cc') diff --git a/file_index.cc b/file_index.cc index 7e265a1..0e48833 100644 --- a/file_index.cc +++ b/file_index.cc @@ -1,5 +1,5 @@ /* Plzip - Parallel compressor compatible with lzip - Copyright (C) 2009-2015 Antonio Diaz Diaz. + Copyright (C) 2009-2016 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 @@ -50,11 +50,11 @@ void File_index::set_num_error( const char * const msg1, unsigned long long num, char buf[80]; snprintf( buf, sizeof buf, "%s%llu%s", msg1, num, msg2 ); error_ = buf; - retval_ = member_vector.empty() ? 1 : 2; // maybe trailing garbage + retval_ = member_vector.empty() ? 1 : 2; // maybe trailing data } -File_index::File_index( const int infd ) +File_index::File_index( const int infd, const bool ignore_garbage ) : retval_( 0 ) { const long long isize = lseek( infd, 0, SEEK_END ); @@ -88,7 +88,10 @@ File_index::File_index( const int infd ) if( member_size < min_member_size || member_size > pos ) { if( member_vector.empty() && isize - pos < max_garbage ) - { --pos; continue; } // maybe trailing garbage + { + if( ignore_garbage ) { --pos; continue; } // maybe trailing data + error_ = "Trailing data not allowed."; retval_ = 2; return; + } set_num_error( "Member size in trailer is corrupt at pos ", pos - 8 ); break; } @@ -98,7 +101,10 @@ File_index::File_index( const int infd ) if( !header.verify_magic() || !header.verify_version() ) { if( member_vector.empty() && isize - pos < max_garbage ) - { --pos; continue; } // maybe trailing garbage + { + if( ignore_garbage ) { --pos; continue; } // maybe trailing data + error_ = "Trailing data not allowed."; retval_ = 2; return; + } set_num_error( "Bad header at pos ", pos - member_size ); break; } -- cgit v1.2.3