summaryrefslogtreecommitdiffstats
path: root/decoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.cc')
-rw-r--r--decoder.cc68
1 files changed, 30 insertions, 38 deletions
diff --git a/decoder.cc b/decoder.cc
index 4cd2819..16aa016 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2022 Antonio Diaz Diaz.
+ Copyright (C) 2008-2024 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
@@ -98,24 +98,21 @@ void LZ_decoder::flush_data()
}
-bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
+int LZ_decoder::check_trailer( const Pretty_print & pp,
+ const bool ignore_empty ) const
{
Lzip_trailer trailer;
- int size = rdec.read_data( trailer.data, Lzip_trailer::size );
- const unsigned long long data_size = data_position();
- const unsigned long long member_size = rdec.member_position();
+ int size = rdec.read_data( trailer.data, trailer.size );
bool error = false;
- if( size < Lzip_trailer::size )
+ if( size < trailer.size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Trailer truncated at trailer position %d;"
- " some checks may fail.\n", size );
- }
- while( size < Lzip_trailer::size ) trailer.data[size++] = 0;
+ { pp();
+ std::fprintf( stderr, "Trailer truncated at trailer position %d;"
+ " some checks may fail.\n", size ); }
+ while( size < trailer.size ) trailer.data[size++] = 0;
}
const unsigned td_crc = trailer.data_crc();
@@ -123,35 +120,32 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
- td_crc, crc() );
- }
+ { pp();
+ std::fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
+ td_crc, crc() ); }
}
+ const unsigned long long data_size = data_position();
const unsigned long long td_size = trailer.data_size();
if( td_size != data_size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- td_size, td_size, data_size, data_size );
- }
+ { pp();
+ std::fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ td_size, td_size, data_size, data_size ); }
}
+ const unsigned long long member_size = rdec.member_position();
const unsigned long long tm_size = trailer.member_size();
if( tm_size != member_size )
{
error = true;
if( verbosity >= 0 )
- {
- pp();
- std::fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- tm_size, tm_size, member_size, member_size );
- }
+ { pp();
+ std::fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
+ tm_size, tm_size, member_size, member_size ); }
}
- if( error ) return false;
+ if( error ) return 3;
+ if( !ignore_empty && data_size == 0 ) return 5;
if( verbosity >= 2 )
{
if( verbosity >= 4 ) show_header( dictionary_size );
@@ -166,13 +160,15 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
if( verbosity >= 3 )
std::fprintf( stderr, "%9llu out, %8llu in. ", data_size, member_size );
}
- return true;
+ return 0;
}
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
- 3 = trailer error, 4 = unknown marker found. */
-int LZ_decoder::decode_member( const Pretty_print & pp )
+ 3 = trailer error, 4 = unknown marker found,
+ 5 = empty member found, 6 = marked member found. */
+int LZ_decoder::decode_member( const Cl_options & cl_opts,
+ const Pretty_print & pp )
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -192,7 +188,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
unsigned rep3 = 0;
State state;
- rdec.load();
+ if( !rdec.load( cl_opts.ignore_marking ) ) return 6;
while( !rdec.finished() )
{
const int pos_state = data_position() & pos_state_mask;
@@ -256,13 +252,9 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
rdec.normalize();
flush_data();
if( len == min_match_len ) // End Of Stream marker
- {
- if( verify_trailer( pp ) ) return 0; else return 3;
- }
+ return check_trailer( pp, cl_opts.ignore_empty );
if( len == min_match_len + 1 ) // Sync Flush marker
- {
- rdec.load(); continue;
- }
+ { rdec.load(); continue; }
if( verbosity >= 0 )
{
pp();