summaryrefslogtreecommitdiffstats
path: root/file_index.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 15:39:51 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 15:39:51 +0000
commit25ff7222c94a48b16ce76f161b6e2ae6efc54c5a (patch)
treeb527f4775318d44b7011176d65e05253dba4fcab /file_index.cc
parentAdding upstream version 1.2. (diff)
downloadplzip-25ff7222c94a48b16ce76f161b6e2ae6efc54c5a.tar.xz
plzip-25ff7222c94a48b16ce76f161b6e2ae6efc54c5a.zip
Adding upstream version 1.3~pre1.upstream/1.3_pre1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'file_index.cc')
-rw-r--r--file_index.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/file_index.cc b/file_index.cc
index 1a46277..b5c7638 100644
--- a/file_index.cc
+++ b/file_index.cc
@@ -50,7 +50,7 @@ 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_ = 2;
+ retval_ = member_vector.empty() ? 1 : 2; // maybe trailing garbage
}
@@ -74,9 +74,10 @@ File_index::File_index( const int infd )
retval_ = 2; return; }
if( !header.verify_version() )
{ set_num_error( "Version ", header.version(),
- " member format not supported." ); return; }
+ " member format not supported." ); retval_ = 2; return; }
long long pos = isize; // always points to a header or to EOF
+ const long long max_garbage = 1024;
while( pos >= min_member_size )
{
File_trailer trailer;
@@ -86,8 +87,8 @@ File_index::File_index( const int infd )
const long long member_size = trailer.member_size();
if( member_size < min_member_size || member_size > pos )
{
- if( member_vector.empty() ) // maybe trailing garbage
- { --pos; continue; }
+ if( member_vector.empty() && isize - pos < max_garbage )
+ { --pos; continue; } // maybe trailing garbage
set_num_error( "Member size in trailer is corrupt at pos ", pos - 8 );
break;
}
@@ -96,11 +97,12 @@ File_index::File_index( const int infd )
{ set_errno_error( "Error reading member header: " ); break; }
if( !header.verify_magic() || !header.verify_version() )
{
- if( member_vector.empty() ) // maybe trailing garbage
- { --pos; continue; }
+ if( member_vector.empty() && isize - pos < max_garbage )
+ { --pos; continue; } // maybe trailing garbage
set_num_error( "Bad header at pos ", pos - member_size );
break;
}
+ const unsigned dictionary_size = header.dictionary_size();
if( member_vector.empty() && isize - pos > File_header::size &&
seek_read( infd, header.data, File_header::size, pos ) == File_header::size &&
header.verify_magic() && header.verify_version() )
@@ -110,7 +112,7 @@ File_index::File_index( const int infd )
}
pos -= member_size;
member_vector.push_back( Member( 0, trailer.data_size(),
- pos, member_size ) );
+ pos, member_size, dictionary_size ) );
}
if( pos != 0 || member_vector.empty() )
{