diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2016-05-20 06:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2016-05-20 06:55:18 +0000 |
commit | 07c2a71a11edd637f0ec9b42b5c5621980c96562 (patch) | |
tree | ffe015da89db655e2f4edbabd6924e41b3971f02 /decoder.cc | |
parent | Adding debian version 1.18~pre2-1. (diff) | |
download | lziprecover-07c2a71a11edd637f0ec9b42b5c5621980c96562.tar.xz lziprecover-07c2a71a11edd637f0ec9b42b5c5621980c96562.zip |
Merging upstream version 1.18.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.cc')
-rw-r--r-- | decoder.cc | 58 |
1 files changed, 30 insertions, 28 deletions
@@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for the lzip format - 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 @@ -73,13 +73,13 @@ long readblock( const int fd, uint8_t * const buf, const long size ) /* Returns the number of bytes really written. If (returned value < size), it is always an error. */ -int writeblock( const int fd, const uint8_t * const buf, const int size ) +long writeblock( const int fd, const uint8_t * const buf, const long size ) { - int sz = 0; + long sz = 0; errno = 0; while( sz < size ) { - const int n = write( fd, buf + sz, size - sz ); + const int n = write( fd, buf + sz, std::min( 1L << 20, size - sz ) ); if( n > 0 ) sz += n; else if( n < 0 && errno != EINTR ) break; errno = 0; @@ -117,7 +117,8 @@ void LZ_decoder::flush_data() if( s > 0 && writeblock( outfd, buffer + stream_pos + i, s ) != s ) throw Error( "Write error" ); } - if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; } + if( pos >= dictionary_size ) + { partial_data_pos += pos; pos = 0; pos_wrapped = true; } stream_pos = pos; } } @@ -126,66 +127,67 @@ void LZ_decoder::flush_data() bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const { File_trailer trailer; - const int trailer_size = File_trailer::size; - const unsigned long long member_size = rdec.member_position() + trailer_size; + int size = rdec.read_data( trailer.data, File_trailer::size ); + const unsigned long long data_size = data_position(); + const unsigned long long member_size = rdec.member_position(); + const int verbosity = pp.verbosity(); bool error = false; - int size = rdec.read_data( trailer.data, trailer_size ); - if( size < trailer_size ) + if( size < File_trailer::size ) { error = true; - if( pp.verbosity() >= 0 ) + if( verbosity >= 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; + while( size < File_trailer::size ) trailer.data[size++] = 0; } - if( !rdec.code_is_zero() ) - { - error = true; - pp( "Range decoder final code is not zero." ); - } if( trailer.data_crc() != crc() ) { error = true; - if( pp.verbosity() >= 0 ) + if( verbosity >= 0 ) { pp(); std::fprintf( stderr, "CRC mismatch; trailer says %08X, data CRC is %08X\n", trailer.data_crc(), crc() ); } } - if( trailer.data_size() != data_position() ) + if( trailer.data_size() != data_size ) { error = true; - if( pp.verbosity() >= 0 ) + if( verbosity >= 0 ) { pp(); std::fprintf( stderr, "Data size mismatch; trailer says %llu, data size is %llu (0x%llX)\n", - trailer.data_size(), data_position(), data_position() ); + trailer.data_size(), data_size, data_size ); } } if( trailer.member_size() != member_size ) { error = true; - if( pp.verbosity() >= 0 ) + if( verbosity >= 0 ) { pp(); std::fprintf( stderr, "Member size mismatch; trailer says %llu, member size is %llu (0x%llX)\n", trailer.member_size(), member_size, member_size ); } } - if( !error && pp.verbosity() >= 2 && data_position() > 0 && member_size > 0 ) + if( !error && verbosity >= 2 && data_size > 0 && member_size > 0 ) std::fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ", - (double)data_position() / member_size, - ( 8.0 * member_size ) / data_position(), - 100.0 * ( 1.0 - ( (double)member_size / data_position() ) ) ); - if( !error && pp.verbosity() >= 4 ) + (double)data_size / member_size, + ( 8.0 * member_size ) / data_size, + 100.0 * ( 1.0 - ( (double)member_size / data_size ) ) ); + if( !error && verbosity >= 4 ) std::fprintf( stderr, "data CRC %08X, data size %9llu, member size %8llu. ", - trailer.data_crc(), trailer.data_size(), trailer.member_size() ); + crc(), data_size, member_size ); + if( rdec.get_code() != 0 && !error && verbosity >= 1 ) + { // corruption in the last 4 bytes of the EOS marker + pp(); + std::fprintf( stderr, "Range decoder final code is %08X\n", rdec.get_code() ); + } return !error; } @@ -301,7 +303,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp ) } rep3 = rep2; rep2 = rep1; rep1 = rep0_saved; state.set_match(); - if( rep0 >= dictionary_size || rep0 >= data_position() ) + if( rep0 >= dictionary_size || ( rep0 >= pos && !pos_wrapped ) ) { flush_data(); return 1; } } copy_block( rep0, len ); |