summaryrefslogtreecommitdiffstats
path: root/decoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-02 07:58:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-02 07:58:40 +0000
commit4ababfe2ca0eb0cc924b750f52d884f91e3a232f (patch)
treea2ccb135e231250bdce430c06c25e9642aea900a /decoder.c
parentAdding upstream version 1.13. (diff)
downloadclzip-4ababfe2ca0eb0cc924b750f52d884f91e3a232f.tar.xz
clzip-4ababfe2ca0eb0cc924b750f52d884f91e3a232f.zip
Adding upstream version 1.14~rc1.upstream/1.14_rc1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--decoder.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/decoder.c b/decoder.c
index fb662c5..0217fc6 100644
--- a/decoder.c
+++ b/decoder.c
@@ -1,5 +1,5 @@
/* Clzip - LZMA lossless data compressor
- Copyright (C) 2010-2022 Antonio Diaz Diaz.
+ Copyright (C) 2010-2023 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 LZd_flush_data( struct LZ_decoder * const d )
}
-static bool LZd_verify_trailer( struct LZ_decoder * const d,
- struct Pretty_print * const pp )
+static int LZd_check_trailer( struct LZ_decoder * const d,
+ struct Pretty_print * const pp,
+ const bool ignore_empty )
{
Lzip_trailer trailer;
int size = Rd_read_data( d->rdec, trailer, Lt_size );
- const unsigned long long data_size = LZd_data_position( d );
- const unsigned long long member_size = Rd_member_position( d->rdec );
bool error = false;
if( size < Lt_size )
{
error = true;
if( verbosity >= 0 )
- {
- Pp_show_msg( pp, 0 );
- fprintf( stderr, "Trailer truncated at trailer position %d;"
- " some checks may fail.\n", size );
- }
+ { Pp_show_msg( pp, 0 );
+ fprintf( stderr, "Trailer truncated at trailer position %d;"
+ " some checks may fail.\n", size ); }
while( size < Lt_size ) trailer[size++] = 0;
}
@@ -124,35 +121,32 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d,
{
error = true;
if( verbosity >= 0 )
- {
- Pp_show_msg( pp, 0 );
- fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
- td_crc, LZd_crc( d ) );
- }
+ { Pp_show_msg( pp, 0 );
+ fprintf( stderr, "CRC mismatch; stored %08X, computed %08X\n",
+ td_crc, LZd_crc( d ) ); }
}
+ const unsigned long long data_size = LZd_data_position( d );
const unsigned long long td_size = Lt_get_data_size( trailer );
if( td_size != data_size )
{
error = true;
if( verbosity >= 0 )
- {
- Pp_show_msg( pp, 0 );
- fprintf( stderr, "Data size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- td_size, td_size, data_size, data_size );
- }
+ { Pp_show_msg( pp, 0 );
+ 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 = Rd_member_position( d->rdec );
const unsigned long long tm_size = Lt_get_member_size( trailer );
if( tm_size != member_size )
{
error = true;
if( verbosity >= 0 )
- {
- Pp_show_msg( pp, 0 );
- fprintf( stderr, "Member size mismatch; stored %llu (0x%llX), computed %llu (0x%llX)\n",
- tm_size, tm_size, member_size, member_size );
- }
+ { Pp_show_msg( pp, 0 );
+ 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( d->dictionary_size );
@@ -167,13 +161,15 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d,
if( verbosity >= 3 )
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. */
+ 3 = trailer error, 4 = unknown marker found,
+ 5 = empty member found, 6 = marked member found. */
int LZd_decode_member( struct LZ_decoder * const d,
+ const struct Cl_options * const cl_opts,
struct Pretty_print * const pp )
{
struct Range_decoder * const rdec = d->rdec;
@@ -208,7 +204,7 @@ int LZd_decode_member( struct LZ_decoder * const d,
Lm_init( &match_len_model );
Lm_init( &rep_len_model );
- Rd_load( rdec );
+ if( !Rd_load( rdec, cl_opts->ignore_marking ) ) return 6;
while( !Rd_finished( rdec ) )
{
const int pos_state = LZd_data_position( d ) & pos_state_mask;
@@ -273,13 +269,9 @@ int LZd_decode_member( struct LZ_decoder * const d,
Rd_normalize( rdec );
LZd_flush_data( d );
if( len == min_match_len ) /* End Of Stream marker */
- {
- if( LZd_verify_trailer( d, pp ) ) return 0; else return 3;
- }
+ return LZd_check_trailer( d, pp, cl_opts->ignore_empty );
if( len == min_match_len + 1 ) /* Sync Flush marker */
- {
- Rd_load( rdec ); continue;
- }
+ { Rd_load( rdec, true ); continue; }
if( verbosity >= 0 )
{
Pp_show_msg( pp, 0 );