summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-01-06 10:08:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-01-06 10:08:51 +0000
commit1bd12f8e72751a6431189a7088f01477a987a212 (patch)
treef3bda4baabb6941e593609529faa13efcad4302c /lzip.h
parentReleasing debian version 1.7-3. (diff)
downloadplzip-1bd12f8e72751a6431189a7088f01477a987a212.tar.xz
plzip-1bd12f8e72751a6431189a7088f01477a987a212.zip
Merging upstream version 1.8.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzip.h')
-rw-r--r--lzip.h47
1 files changed, 31 insertions, 16 deletions
diff --git a/lzip.h b/lzip.h
index 3587a8f..dfbf4f7 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
-/* Plzip - Parallel compressor compatible with lzip
- Copyright (C) 2009-2018 Antonio Diaz Diaz.
+/* Plzip - Massively parallel implementation of lzip
+ 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
@@ -48,7 +48,7 @@ public:
{
const std::string & s = filenames[i];
const unsigned len = ( s == "-" ) ? stdin_name_len : s.size();
- if( len > longest_name ) longest_name = len;
+ if( longest_name < len ) longest_name = len;
}
if( longest_name == 0 ) longest_name = stdin_name_len;
}
@@ -58,7 +58,7 @@ public:
if( filename.size() && filename != "-" ) name_ = filename;
else name_ = stdin_name;
padded_name = " "; padded_name += name_; padded_name += ": ";
- if( name_.size() < longest_name )
+ if( longest_name > name_.size() )
padded_name.append( longest_name - name_.size(), ' ' );
first_post = true;
}
@@ -82,30 +82,30 @@ inline int real_bits( unsigned value )
}
-const uint8_t magic_string[4] = { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP"
+const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP"
-struct File_header
+struct Lzip_header
{
uint8_t data[6]; // 0-3 magic bytes
// 4 version
// 5 coded_dict_size
enum { size = 6 };
- void set_magic() { std::memcpy( data, magic_string, 4 ); data[4] = 1; }
+ void set_magic() { std::memcpy( data, lzip_magic, 4 ); data[4] = 1; }
bool verify_magic() const
- { return ( std::memcmp( data, magic_string, 4 ) == 0 ); }
+ { return ( std::memcmp( data, lzip_magic, 4 ) == 0 ); }
bool verify_prefix( const int sz ) const // detect (truncated) header
{
for( int i = 0; i < sz && i < 4; ++i )
- if( data[i] != magic_string[i] ) return false;
+ if( data[i] != lzip_magic[i] ) return false;
return ( sz > 0 );
}
bool verify_corrupt() const // detect corrupt header
{
int matches = 0;
for( int i = 0; i < 4; ++i )
- if( data[i] == magic_string[i] ) ++matches;
+ if( data[i] == lzip_magic[i] ) ++matches;
return ( matches > 1 && matches < 4 );
}
@@ -137,12 +137,11 @@ struct File_header
};
-struct File_trailer
+struct Lzip_trailer
{
uint8_t data[20]; // 0-3 CRC32 of the uncompressed data
// 4-11 size of the uncompressed data
// 12-19 member size including header and trailer
-
enum { size = 20 };
unsigned data_crc() const
@@ -174,6 +173,20 @@ struct File_trailer
void member_size( unsigned long long sz )
{ for( int i = 12; i <= 19; ++i ) { data[i] = (uint8_t)sz; sz >>= 8; } }
+
+ bool verify_consistency() const // check internal consistency
+ {
+ const unsigned crc = data_crc();
+ const unsigned long long dsize = data_size();
+ if( ( crc == 0 ) != ( dsize == 0 ) ) return false;
+ const unsigned long long msize = member_size();
+ if( msize < min_member_size ) return false;
+ const unsigned long long mlimit = ( 9 * dsize + 7 ) / 8 + min_member_size;
+ if( mlimit > dsize && msize > mlimit ) return false;
+ const unsigned long long dlimit = 7090 * ( msize - 26 ) - 1;
+ if( dlimit > msize && dsize > dlimit ) return false;
+ return true;
+ }
};
@@ -200,18 +213,19 @@ int compress( const unsigned long long cfile_size,
const int infd, const int outfd,
const Pretty_print & pp, const int debug_level );
-// defined in file_index.cc
-class File_index;
+// defined in lzip_index.cc
+class Lzip_index;
// defined in dec_stdout.cc
int dec_stdout( const int num_workers, const int infd, const int outfd,
const Pretty_print & pp, const int debug_level,
- const File_index & file_index );
+ const int out_slots, const Lzip_index & lzip_index );
// defined in dec_stream.cc
int dec_stream( const unsigned long long cfile_size,
const int num_workers, const int infd, const int outfd,
const Pretty_print & pp, const int debug_level,
+ const int in_slots, const int out_slots,
const bool ignore_trailing, const bool loose_trailing );
// defined in decompress.cc
@@ -221,7 +235,8 @@ int decompress_read_error( struct LZ_Decoder * const decoder,
const Pretty_print & pp, const int worker_id );
int decompress( const unsigned long long cfile_size, int num_workers,
const int infd, const int outfd, const Pretty_print & pp,
- const int debug_level, const bool ignore_trailing,
+ const int debug_level, const int in_slots,
+ const int out_slots, const bool ignore_trailing,
const bool loose_trailing, const bool infd_isreg );
// defined in list.cc