summaryrefslogtreecommitdiffstats
path: root/lzip_index.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-02-21 16:10:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-02-21 16:10:20 +0000
commit534d48ffedd7b2050ebccb10ab43d92b8a6248bd (patch)
tree494dcd1ec9526b2c7eaaa34cf9fafa04016e8e5b /lzip_index.c
parentReleasing debian version 1.12-3. (diff)
downloadlunzip-534d48ffedd7b2050ebccb10ab43d92b8a6248bd.tar.xz
lunzip-534d48ffedd7b2050ebccb10ab43d92b8a6248bd.zip
Merging upstream version 1.13.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lzip_index.c')
-rw-r--r--lzip_index.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/lzip_index.c b/lzip_index.c
index ca4df8d..559fd7a 100644
--- a/lzip_index.c
+++ b/lzip_index.c
@@ -1,5 +1,5 @@
/* Lunzip - Decompressor for the lzip format
- Copyright (C) 2010-2021 Antonio Diaz Diaz.
+ Copyright (C) 2010-2022 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
@@ -133,44 +133,38 @@ static bool Li_skip_trailing_data( struct Lzip_index * const li, const int fd,
const bool ignore_trailing,
const bool loose_trailing )
{
+ if( *pos < min_member_size ) return false;
enum { block_size = 16384,
buffer_size = block_size + Lt_size - 1 + Lh_size };
uint8_t buffer[buffer_size];
int bsize = *pos % block_size; /* total bytes in buffer */
- int search_size, rd_size;
- unsigned long long ipos;
- int i;
- if( *pos < min_member_size ) return false;
if( bsize <= buffer_size - block_size ) bsize += block_size;
- search_size = bsize; /* bytes to search for trailer */
- rd_size = bsize; /* bytes to read from file */
- ipos = *pos - rd_size; /* aligned to block_size */
+ int search_size = bsize; /* bytes to search for trailer */
+ int rd_size = bsize; /* bytes to read from file */
+ unsigned long long ipos = *pos - rd_size; /* aligned to block_size */
while( true )
{
- const uint8_t max_msb = ( ipos + search_size ) >> 56;
if( seek_read( fd, buffer, rd_size, ipos ) != rd_size )
- { Li_set_errno_error( li, "Error seeking member trailer: " );
- return false; }
+ { Li_set_errno_error( li, "Error seeking member trailer: " ); return false; }
+ const uint8_t max_msb = ( ipos + search_size ) >> 56;
+ int i;
for( i = search_size; i >= Lt_size; --i )
if( buffer[i-1] <= max_msb ) /* most significant byte of member_size */
{
- Lzip_header header;
- const Lzip_header * header2;
const Lzip_trailer * const trailer =
(const Lzip_trailer *)( buffer + i - Lt_size );
const unsigned long long member_size = Lt_get_member_size( *trailer );
- unsigned dictionary_size;
- bool full_h2;
if( member_size == 0 ) /* skip trailing zeros */
{ while( i > Lt_size && buffer[i-9] == 0 ) --i; continue; }
if( member_size > ipos + i || !Lt_verify_consistency( *trailer ) )
continue;
+ Lzip_header header;
if( !Li_read_header( li, fd, header, ipos + i - member_size ) )
return false;
if( !Lh_verify( header ) ) continue;
- header2 = (const Lzip_header *)( buffer + i );
- full_h2 = bsize - i >= Lh_size;
+ const Lzip_header * header2 = (const Lzip_header *)( buffer + i );
+ const bool full_h2 = bsize - i >= Lh_size;
if( Lh_verify_prefix( *header2, bsize - i ) ) /* last member */
{
if( !full_h2 ) add_error( li, "Last member in input file is truncated." );
@@ -183,7 +177,7 @@ static bool Li_skip_trailing_data( struct Lzip_index * const li, const int fd,
if( !ignore_trailing )
{ add_error( li, trailing_msg ); li->retval = 2; return false; }
*pos = ipos + i - member_size;
- dictionary_size = Lh_get_dictionary_size( header );
+ const unsigned dictionary_size = Lh_get_dictionary_size( header );
if( li->dictionary_size < dictionary_size )
li->dictionary_size = dictionary_size;
return push_back_member( li, 0, Lt_get_data_size( *trailer ), *pos,
@@ -204,9 +198,6 @@ static bool Li_skip_trailing_data( struct Lzip_index * const li, const int fd,
bool Li_init( struct Lzip_index * const li, const int infd,
const bool ignore_trailing, const bool loose_trailing )
{
- Lzip_header header;
- unsigned long long pos;
- long i;
li->member_vector = 0;
li->error = 0;
li->insize = lseek( infd, 0, SEEK_END );
@@ -223,18 +214,17 @@ bool Li_init( struct Lzip_index * const li, const int infd,
{ add_error( li, "Input file is too long (2^63 bytes or more)." );
li->retval = 2; return false; }
+ Lzip_header header;
if( !Li_read_header( li, infd, header, 0 ) ) return false;
if( Li_check_header_error( li, header ) ) return false;
- pos = li->insize; /* always points to a header or to EOF */
+ unsigned long long pos = li->insize; /* always points to a header or to EOF */
while( pos >= min_member_size )
{
Lzip_trailer trailer;
- unsigned long long member_size;
- unsigned dictionary_size;
if( seek_read( infd, trailer, Lt_size, pos - Lt_size ) != Lt_size )
{ Li_set_errno_error( li, "Error reading member trailer: " ); break; }
- member_size = Lt_get_member_size( trailer );
+ const unsigned long long member_size = Lt_get_member_size( trailer );
if( member_size > pos || !Lt_verify_consistency( trailer ) )
{ /* bad trailer */
if( li->members <= 0 )
@@ -253,7 +243,7 @@ bool Li_init( struct Lzip_index * const li, const int infd,
break;
}
pos -= member_size;
- dictionary_size = Lh_get_dictionary_size( header );
+ const unsigned dictionary_size = Lh_get_dictionary_size( header );
if( li->dictionary_size < dictionary_size )
li->dictionary_size = dictionary_size;
if( !push_back_member( li, 0, Lt_get_data_size( trailer ), pos,
@@ -268,6 +258,7 @@ bool Li_init( struct Lzip_index * const li, const int infd,
return false;
}
Li_reverse_member_vector( li );
+ long i;
for( i = 0; ; ++i )
{
const long long end = block_end( li->member_vector[i].dblock );