diff options
Diffstat (limited to 'file_index.cc')
-rw-r--r-- | file_index.cc | 16 |
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() ) { |