From 00184d655a72ed5a71aa80449250255fb8ac2caa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 23 Jan 2024 06:36:41 +0100 Subject: Merging upstream version 1.14~rc1. Signed-off-by: Daniel Baumann --- decoder.c | 62 +++++++++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'decoder.c') diff --git a/decoder.c b/decoder.c index b52b35f..ab6a259 100644 --- a/decoder.c +++ b/decoder.c @@ -1,5 +1,5 @@ /* Lunzip - Decompressor for the lzip format - 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 @@ -111,24 +111,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; } @@ -137,35 +134,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 ); @@ -180,13 +174,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; @@ -222,7 +218,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; @@ -287,13 +283,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 ); -- cgit v1.2.3