1
0
Fork 0

Merging upstream version 1.13~rc1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-23 19:27:49 +01:00
parent 8a20f7e45f
commit fab8025fd0
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
12 changed files with 289 additions and 250 deletions

34
lzip.h
View file

@ -1,5 +1,5 @@
/* Pdlzip - LZMA lossless data compressor
Copyright (C) 2010-2022 Antonio Diaz Diaz.
Copyright (C) 2010-2023 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@ -78,8 +78,8 @@ static inline void CRC32_update_buf( uint32_t * const crc,
static inline bool isvalid_ds( const unsigned dictionary_size )
{ return ( dictionary_size >= min_dictionary_size &&
dictionary_size <= max_dictionary_size ); }
{ return dictionary_size >= min_dictionary_size &&
dictionary_size <= max_dictionary_size; }
static inline int real_bits( unsigned value )
@ -92,43 +92,43 @@ static inline int real_bits( unsigned value )
static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
enum { Lh_size = 6 };
typedef uint8_t Lzip_header[Lh_size]; /* 0-3 magic bytes */
/* 4 version */
/* 5 coded dictionary size */
enum { Lh_size = 6 };
static inline void Lh_set_magic( Lzip_header data )
{ memcpy( data, lzip_magic, 4 ); data[4] = 1; }
static inline bool Lh_verify_magic( const Lzip_header data )
{ return ( memcmp( data, lzip_magic, 4 ) == 0 ); }
static inline bool Lh_check_magic( const Lzip_header data )
{ return memcmp( data, lzip_magic, 4 ) == 0; }
/* detect (truncated) header */
static inline bool Lh_verify_prefix( const Lzip_header data, const int sz )
static inline bool Lh_check_prefix( const Lzip_header data, const int sz )
{
int i; for( i = 0; i < sz && i < 4; ++i )
if( data[i] != lzip_magic[i] ) return false;
return ( sz > 0 );
return sz > 0;
}
/* detect corrupt header */
static inline bool Lh_verify_corrupt( const Lzip_header data )
static inline bool Lh_check_corrupt( const Lzip_header data )
{
int matches = 0;
int i; for( i = 0; i < 4; ++i )
if( data[i] == lzip_magic[i] ) ++matches;
return ( matches > 1 && matches < 4 );
return matches > 1 && matches < 4;
}
static inline uint8_t Lh_version( const Lzip_header data )
{ return data[4]; }
static inline bool Lh_verify_version( const Lzip_header data )
{ return ( data[4] == 1 ); }
static inline bool Lh_check_version( const Lzip_header data )
{ return data[4] == 1; }
static inline unsigned Lh_get_dictionary_size( const Lzip_header data )
{
unsigned sz = ( 1 << ( data[5] & 0x1F ) );
unsigned sz = 1 << ( data[5] & 0x1F );
if( sz > min_dictionary_size )
sz -= ( sz / 16 ) * ( ( data[5] >> 5 ) & 7 );
return sz;
@ -145,17 +145,17 @@ static inline bool Lh_set_dictionary_size( Lzip_header data, const unsigned sz )
unsigned i;
for( i = 7; i >= 1; --i )
if( base_size - ( i * fraction ) >= sz )
{ data[5] |= ( i << 5 ); break; }
{ data[5] |= i << 5; break; }
}
return true;
}
typedef uint8_t Lzip_trailer[20];
enum { Lt_size = 20 };
typedef uint8_t Lzip_trailer[Lt_size];
/* 0-3 CRC32 of the uncompressed data */
/* 4-11 size of the uncompressed data */
/* 12-19 member size including header and trailer */
enum { Lt_size = 20 };
static inline unsigned Lt_get_data_crc( const Lzip_trailer data )
{