1
0
Fork 0

Merging upstream version 1.21.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-21 11:29:36 +01:00
parent 4b818dc40b
commit 29d9f35b61
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
42 changed files with 2853 additions and 1586 deletions

View file

@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
Copyright (C) 2009-2018 Antonio Diaz Diaz.
Copyright (C) 2009-2019 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
@ -30,8 +30,7 @@
#include "lzip.h"
#include "decoder.h"
#include "block.h"
#include "file_index.h"
#include "lzip_index.h"
namespace {
@ -42,14 +41,15 @@ int decompress_member( const int infd, const Pretty_print & pp,
const unsigned long long outend )
{
Range_decoder rdec( infd );
File_header header;
rdec.read_data( header.data, File_header::size );
Lzip_header header;
rdec.read_data( header.data, Lzip_header::size );
if( rdec.finished() ) // End Of File
{ pp( "File ends unexpectedly at member header." ); return 2; }
if( !verify_header( header, pp ) ) return 2;
if( !header.verify_magic() ) { pp( bad_magic_msg ); return 2; }
if( !header.verify_version() )
{ pp( bad_version( header.version() ) ); return 2; }
const unsigned dictionary_size = header.dictionary_size();
if( !isvalid_ds( dictionary_size ) )
{ pp( "Invalid dictionary size in member header." ); return 2; }
if( !isvalid_ds( dictionary_size ) ) { pp( bad_dict_msg ); return 2; }
if( verbosity >= 2 ) pp();
@ -117,49 +117,49 @@ int range_decompress( const std::string & input_filename,
const int infd = open_instream( input_filename.c_str(), &in_stats, true, true );
if( infd < 0 ) return 1;
Pretty_print pp( input_filename );
const File_index file_index( infd, ignore_errors, ignore_trailing,
loose_trailing );
if( file_index.retval() != 0 )
{ show_file_error( input_filename.c_str(), file_index.error().c_str() );
return file_index.retval(); }
const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing,
ignore_errors, ignore_errors );
if( lzip_index.retval() != 0 )
{ show_file_error( input_filename.c_str(), lzip_index.error().c_str() );
return lzip_index.retval(); }
if( range.end() > file_index.udata_size() )
range.size( std::max( 0LL, file_index.udata_size() - range.pos() ) );
if( range.end() > lzip_index.udata_size() )
range.size( std::max( 0LL, lzip_index.udata_size() - range.pos() ) );
if( range.size() <= 0 )
{ pp( "Nothing to do." ); return 0; }
if( verbosity >= 1 )
std::fprintf( stderr, "Decompressing range %sB to %sB (%sof %sBytes)\n",
format_num( range.pos() ),
format_num( range.pos() + range.size() ),
format_num( range.size() ),
format_num( file_index.udata_size() ) );
{ show_file_error( input_filename.c_str(), "Nothing to do." ); return 0; }
if( to_stdout || default_output_filename.empty() )
outfd = STDOUT_FILENO;
else
{
output_filename = default_output_filename;
set_signal_handler();
if( !open_outstream( force, false, false, false ) )
{ close( infd ); return 1; }
}
if( verbosity >= 1 )
std::fprintf( stderr, "Decompressing range %sB to %sB (%sof %sBytes)\n",
format_num( range.pos() ),
format_num( range.pos() + range.size() ),
format_num( range.size() ),
format_num( lzip_index.udata_size() ) );
Pretty_print pp( input_filename );
int retval = 0;
for( long i = 0; i < file_index.members(); ++i )
for( long i = 0; i < lzip_index.members(); ++i )
{
const Block & db = file_index.dblock( i );
const Block & db = lzip_index.dblock( i );
if( range.overlaps( db ) )
{
if( verbosity >= 3 && file_index.members() > 1 )
if( verbosity >= 3 && lzip_index.members() > 1 )
std::fprintf( stderr, "Decompressing member %3ld\n", i + 1 );
const long long outskip = std::max( 0LL, range.pos() - db.pos() );
const long long outend = std::min( db.size(), range.end() - db.pos() );
const long long mpos = file_index.mblock( i ).pos();
const long long mpos = lzip_index.mblock( i ).pos();
if( !safe_seek( infd, mpos ) ) { retval = 1; break; }
const int tmp = decompress_member( infd, pp, mpos, outskip, outend );
if( tmp && ( tmp != 2 || !ignore_errors ) )
cleanup_and_fail( tmp );
if( tmp && ( tmp != 2 || !ignore_errors ) ) cleanup_and_fail( tmp );
if( tmp > retval ) retval = tmp;
pp.reset();
}