From e6759ba4e68c66f0927bb89bfb87215eb29016ae Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 20 May 2016 08:54:36 +0200 Subject: Adding upstream version 1.18. Signed-off-by: Daniel Baumann --- mtester.cc | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'mtester.cc') diff --git a/mtester.cc b/mtester.cc index 92de2e0..22fd67d 100644 --- a/mtester.cc +++ b/mtester.cc @@ -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 @@ -56,7 +56,10 @@ void LZ_mtester::flush_data() { const int size = pos - stream_pos; crc32.update_buf( crc_, buffer + stream_pos, size ); - if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; } + if( outfd >= 0 && writeblock( outfd, buffer + stream_pos, size ) != size ) + throw Error( "Write error" ); + if( pos >= dictionary_size ) + { partial_data_pos += pos; pos = 0; pos_wrapped = true; } stream_pos = pos; } } @@ -64,13 +67,12 @@ void LZ_mtester::flush_data() bool LZ_mtester::verify_trailer() { - const File_trailer * trailer = rdec.get_trailer(); + const File_trailer * const trailer = rdec.get_trailer(); if( !trailer ) return false; - return ( rdec.code_is_zero() && - trailer->data_crc() == crc() && + return ( trailer->data_crc() == crc() && trailer->data_size() == data_position() && - trailer->member_size() == (unsigned long)member_position() ); + trailer->member_size() == member_position() ); } @@ -101,7 +103,7 @@ void LZ_mtester::duplicate_buffer() /* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, 3 = trailer error, 4 = unknown marker found, -1 = pos_limit reached. */ -int LZ_mtester::test_member( const long pos_limit ) +int LZ_mtester::test_member( const unsigned long pos_limit ) { if( pos_limit < File_header::size + 5 ) return -1; if( member_position() == File_header::size ) rdec.load(); @@ -181,11 +183,12 @@ int LZ_mtester::test_member( const long pos_limit ) } return 4; } + if( rep0 > max_rep0 ) max_rep0 = rep0; } } 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 ); @@ -304,8 +307,13 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos, if( show_packets ) std::fputs( "trailer error\n", stdout ); return 3; } + if( len == min_match_len + 1 ) // Sync Flush marker + { + rdec.load(); continue; + } return 4; } + if( rep0 > max_rep0 ) max_rep0 = rep0; } } rep3 = rep2; rep2 = rep1; rep1 = rep0_saved; @@ -313,7 +321,7 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos, if( show_packets ) std::printf( "%6llu %6llu match %6u,%3d (%6lld)", mp, dp, rep0 + 1, len, dp - rep0 - 1 ); - if( rep0 >= dictionary_size || rep0 >= data_position() ) + if( rep0 >= dictionary_size || ( rep0 >= pos && !pos_wrapped ) ) { flush_data(); if( show_packets ) std::fputc( '\n', stdout ); return 1; } } @@ -343,19 +351,13 @@ uint8_t * read_member( const int infd, const long long mpos, const LZ_mtester * prepare_master( const uint8_t * const buffer, const long buffer_size, - const long pos_limit ) + const unsigned long pos_limit, + const unsigned dictionary_size ) { - const File_header & header = *(File_header *)buffer; - const unsigned dictionary_size = header.dictionary_size(); - if( header.verify_magic() && header.verify_version() && - dictionary_size >= min_dictionary_size && - dictionary_size <= max_dictionary_size ) - { - LZ_mtester * const master = - new LZ_mtester( buffer, buffer_size, dictionary_size ); - if( master->test_member( pos_limit ) == -1 ) return master; - delete master; - } + LZ_mtester * const master = + new LZ_mtester( buffer, buffer_size, dictionary_size ); + if( master->test_member( pos_limit ) == -1 ) return master; + delete master; return 0; } -- cgit v1.2.3