diff options
Diffstat (limited to 'dec_stream.cc')
-rw-r--r-- | dec_stream.cc | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/dec_stream.cc b/dec_stream.cc index e074ee2..5ec1ff7 100644 --- a/dec_stream.cc +++ b/dec_stream.cc @@ -1,6 +1,6 @@ /* Plzip - Parallel compressor compatible with lzip Copyright (C) 2009 Laszlo Ersek. - Copyright (C) 2009-2016 Antonio Diaz Diaz. + Copyright (C) 2009-2017 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 @@ -267,16 +267,13 @@ extern "C" void * dsplitter_s( void * arg ) { pp( "Input file is too short." ); cleanup_and_fail( 2 ); } const File_header & header = *(File_header *)buffer; if( !header.verify_magic() ) - { pp( "Bad magic number (file not in lzip format)." ); cleanup_and_fail( 2 ); } + { pp( bad_magic_msg ); cleanup_and_fail( 2 ); } if( !header.verify_version() ) - { - if( verbosity >= 0 ) - { pp(); - std::fprintf( stderr, "Version %d member format not supported.\n", - header.version() ); } - cleanup_and_fail( 2 ); - } - show_header( header.dictionary_size() ); + { pp( bad_version( header.version() ) ); cleanup_and_fail( 2 ); } + const unsigned dictionary_size = header.dictionary_size(); + if( !isvalid_ds( dictionary_size ) ) + { pp( bad_dict_msg ); cleanup_and_fail( 2 ); } + show_header( dictionary_size ); unsigned long long partial_member_size = 0; while( true ) @@ -293,13 +290,10 @@ extern "C" void * dsplitter_s( void * arg ) { // header found const File_header & header = *(File_header *)(buffer + newpos); if( !header.verify_version() ) - { - if( verbosity >= 0 ) - { pp(); - std::fprintf( stderr, "Version %d member format not supported.\n", - header.version() ); } - cleanup_and_fail( 2 ); - } + { pp( bad_version( header.version() ) ); cleanup_and_fail( 2 ); } + const unsigned dictionary_size = header.dictionary_size(); + if( !isvalid_ds( dictionary_size ) ) + { pp( bad_dict_msg ); cleanup_and_fail( 2 ); } uint8_t * const data = new( std::nothrow ) uint8_t[newpos - pos]; if( !data ) { pp( "Not enough memory." ); cleanup_and_fail(); } std::memcpy( data, buffer + pos, newpos - pos ); @@ -367,7 +361,7 @@ extern "C" void * dworker_s( void * arg ) { pp( "Not enough memory." ); cleanup_and_fail(); } unsigned long long partial_out_size = 0; int new_pos = 0; - bool trailing_garbage_found = false; + bool trailing_data_found = false; while( true ) { @@ -376,7 +370,7 @@ extern "C" void * dworker_s( void * arg ) if( !ipacket->data ) LZ_decompress_finish( decoder ); int written = 0; - while( !trailing_garbage_found ) + while( !trailing_data_found ) { if( LZ_decompress_write_size( decoder ) > 0 && written < ipacket->size ) { @@ -387,7 +381,7 @@ extern "C" void * dworker_s( void * arg ) if( written > ipacket->size ) internal_error( "ipacket size exceeded in worker." ); } - while( !trailing_garbage_found ) // read and pack decompressed data + while( !trailing_data_found ) // read and pack decompressed data { const int rd = LZ_decompress_read( decoder, new_data + new_pos, max_packet_size - new_pos ); @@ -395,9 +389,9 @@ extern "C" void * dworker_s( void * arg ) { if( LZ_decompress_errno( decoder ) == LZ_header_error ) { - trailing_garbage_found = true; + trailing_data_found = true; if( !ignore_trailing ) - { pp( "Trailing data not allowed." ); cleanup_and_fail( 2 ); } + { pp( trailing_msg ); cleanup_and_fail( 2 ); } } else cleanup_and_fail( decompress_read_error( decoder, pp, worker_id ) ); @@ -405,7 +399,7 @@ extern "C" void * dworker_s( void * arg ) else new_pos += rd; if( new_pos > max_packet_size ) internal_error( "opacket size exceeded in worker." ); - if( new_pos == max_packet_size || trailing_garbage_found || + if( new_pos == max_packet_size || trailing_data_found || LZ_decompress_finished( decoder ) == 1 ) { if( !testing && new_pos > 0 ) // make data packet @@ -417,8 +411,7 @@ extern "C" void * dworker_s( void * arg ) } partial_out_size += new_pos; new_pos = 0; - if( trailing_garbage_found || - LZ_decompress_finished( decoder ) == 1 ) + if( trailing_data_found || LZ_decompress_finished( decoder ) == 1 ) { if( !testing ) // end of member token courier.collect_packet( new Packet, worker_id ); @@ -525,7 +518,7 @@ int dec_stream( const int num_workers, const int infd, const int outfd, ( 8.0 * in_size ) / out_size, 100.0 * ( 1.0 - ( (double)in_size / out_size ) ) ); if( verbosity >= 4 ) - std::fprintf( stderr, "decompressed size %9llu, size %9llu. ", + std::fprintf( stderr, "decompressed %9llu, compressed %9llu. ", out_size, in_size ); if( verbosity >= 1 ) std::fputs( (outfd < 0) ? "ok\n" : "done\n", stderr ); |