From 4eb895adce37d5080310984546faf00db136d4ef Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 1 Jun 2016 16:15:42 +0200 Subject: Merging upstream version 1.5. Signed-off-by: Daniel Baumann --- dec_stream.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'dec_stream.cc') diff --git a/dec_stream.cc b/dec_stream.cc index 93fc8de..e074ee2 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-2015 Antonio Diaz Diaz. + Copyright (C) 2009-2016 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 @@ -88,16 +88,16 @@ public: num_workers( workers ), out_slots( oslots ), slot_av( workers ), eof( false ) { - xinit( &imutex ); xinit( &iav_or_eof ); - xinit( &omutex ); xinit( &oav_or_exit ); - for( unsigned i = 0; i < slot_av.size(); ++i ) xinit( &slot_av[i] ); + xinit_mutex( &imutex ); xinit_cond( &iav_or_eof ); + xinit_mutex( &omutex ); xinit_cond( &oav_or_exit ); + for( unsigned i = 0; i < slot_av.size(); ++i ) xinit_cond( &slot_av[i] ); } ~Packet_courier() { - for( unsigned i = 0; i < slot_av.size(); ++i ) xdestroy( &slot_av[i] ); - xdestroy( &oav_or_exit ); xdestroy( &omutex ); - xdestroy( &iav_or_eof ); xdestroy( &imutex ); + for( unsigned i = 0; i < slot_av.size(); ++i ) xdestroy_cond( &slot_av[i] ); + xdestroy_cond( &oav_or_exit ); xdestroy_mutex( &omutex ); + xdestroy_cond( &iav_or_eof ); xdestroy_mutex( &imutex ); } // make a packet with data received from splitter @@ -345,6 +345,7 @@ struct Worker_arg Packet_courier * courier; const Pretty_print * pp; int worker_id; + bool ignore_trailing; bool testing; }; @@ -357,6 +358,7 @@ extern "C" void * dworker_s( void * arg ) Packet_courier & courier = *tmp.courier; const Pretty_print & pp = *tmp.pp; const int worker_id = tmp.worker_id; + const bool ignore_trailing = tmp.ignore_trailing; const bool testing = tmp.testing; uint8_t * new_data = new( std::nothrow ) uint8_t[max_packet_size]; @@ -392,7 +394,11 @@ extern "C" void * dworker_s( void * arg ) if( rd < 0 ) { if( LZ_decompress_errno( decoder ) == LZ_header_error ) + { trailing_garbage_found = true; + if( !ignore_trailing ) + { pp( "Trailing data not allowed." ); cleanup_and_fail( 2 ); } + } else cleanup_and_fail( decompress_read_error( decoder, pp, worker_id ) ); } @@ -461,7 +467,8 @@ void muxer( Packet_courier & courier, const Pretty_print & pp, const int outfd ) // init the courier, then start the splitter and the workers and, // if not testing, call the muxer. int dec_stream( const int num_workers, const int infd, const int outfd, - const Pretty_print & pp, const int debug_level ) + const Pretty_print & pp, const int debug_level, + const bool ignore_trailing ) { const int in_slots_per_worker = 2; const int out_slots = 32; @@ -490,6 +497,7 @@ int dec_stream( const int num_workers, const int infd, const int outfd, worker_args[i].courier = &courier; worker_args[i].pp = &pp; worker_args[i].worker_id = i; + worker_args[i].ignore_trailing = ignore_trailing; worker_args[i].testing = ( outfd < 0 ); errcode = pthread_create( &worker_threads[i], 0, dworker_s, &worker_args[i] ); if( errcode ) -- cgit v1.2.3