1
0
Fork 0

Merging upstream version 1.24~pre1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-21 11:32:21 +01:00
parent 3d0e2f8943
commit 3b655f02bb
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
37 changed files with 1495 additions and 1214 deletions

View file

@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
Copyright (C) 2009-2022 Antonio Diaz Diaz.
Copyright (C) 2009-2023 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
@ -45,8 +45,8 @@ bool decompress_member( const int infd, const Pretty_print & pp,
rdec.read_data( header.data, Lzip_header::size );
if( rdec.finished() ) // End Of File
{ pp( "File ends unexpectedly at member header." ); return false; }
if( !header.verify_magic() ) { pp( bad_magic_msg ); return false; }
if( !header.verify_version() )
if( !header.check_magic() ) { pp( bad_magic_msg ); return false; }
if( !header.check_version() )
{ pp( bad_version( header.version() ) ); return false; }
const unsigned dictionary_size = header.dictionary_size();
if( !isvalid_ds( dictionary_size ) ) { pp( bad_dict_msg ); return false; }
@ -113,36 +113,36 @@ const char * format_num( unsigned long long num,
}
bool safe_seek( const int fd, const long long pos )
bool safe_seek( const int fd, const long long pos,
const char * const filename )
{
if( lseek( fd, pos, SEEK_SET ) == pos ) return true;
show_error( "Seek error", errno ); return false;
show_file_error( filename, "Seek error", errno );
return false;
}
int range_decompress( const std::string & input_filename,
const std::string & default_output_filename,
Block range, const bool force, const bool ignore_errors,
const bool ignore_trailing, const bool loose_trailing,
const bool to_stdout )
const Cl_options & cl_opts, Block range,
const bool force, const bool to_stdout )
{
const char * const filename = input_filename.c_str();
struct stat in_stats;
const int infd =
open_instream( input_filename.c_str(), &in_stats, false, true );
const int infd = open_instream( filename, &in_stats, false, true );
if( infd < 0 ) return 1;
const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing,
ignore_errors, ignore_errors );
const Lzip_index lzip_index( infd, cl_opts, cl_opts.ignore_errors,
cl_opts.ignore_errors );
if( lzip_index.retval() != 0 )
{ show_file_error( input_filename.c_str(), lzip_index.error().c_str() );
{ show_file_error( filename, lzip_index.error().c_str() );
return lzip_index.retval(); }
const long long udata_size = lzip_index.udata_size();
if( range.end() > udata_size )
range.size( std::max( 0LL, udata_size - range.pos() ) );
if( range.size() <= 0 )
{ if( udata_size > 0 )
show_file_error( input_filename.c_str(), "Nothing to do." );
{ if( udata_size > 0 ) show_file_error( filename, "Nothing to do." );
return 0; }
if( to_stdout || default_output_filename.empty() ) outfd = STDOUT_FILENO;
@ -171,13 +171,15 @@ int range_decompress( const std::string & input_filename,
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 = lzip_index.mblock( i ).pos();
if( !safe_seek( infd, mpos ) ) cleanup_and_fail( 1 );
if( !safe_seek( infd, mpos, filename ) ) cleanup_and_fail( 1 );
if( !decompress_member( infd, pp, mpos, outskip, outend ) )
{ if( !ignore_errors ) cleanup_and_fail( 2 ); else error = true; }
{ if( cl_opts.ignore_errors ) error = true; else cleanup_and_fail( 2 ); }
pp.reset();
}
}
close( infd );
if( close( infd ) != 0 )
{ show_file_error( filename, "Error closing input file", errno );
cleanup_and_fail( 1 ); }
if( close_outstream( &in_stats ) != 0 ) cleanup_and_fail( 1 );
if( verbosity >= 2 && !error )
std::fputs( "Byte range decompressed successfully.\n", stderr );