summaryrefslogtreecommitdiffstats
path: root/in_place.c
diff options
context:
space:
mode:
Diffstat (limited to 'in_place.c')
-rw-r--r--in_place.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/in_place.c b/in_place.c
index 1f2fe22..11b9cbc 100644
--- a/in_place.c
+++ b/in_place.c
@@ -1,5 +1,5 @@
/* Xlunzip - Test tool for the lzip_decompress linux module
- Copyright (C) 2016-2021 Antonio Diaz Diaz.
+ Copyright (C) 2016-2024 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,8 @@
#include "lzip.h"
-/* Returns the number of bytes really read.
- If (returned value < size) and (errno == 0), means EOF was reached.
+/* Return the number of bytes really read.
+ If (value returned < size) and (errno == 0), means EOF was reached.
*/
static long readblock( const int fd, uint8_t * const buf, const long size )
{
@@ -49,9 +49,9 @@ static long readblock( const int fd, uint8_t * const buf, const long size )
}
-/* Returns the address of a malloc'd buffer containing the file data and
+/* Return the address of a malloc'd buffer containing the file data and
the buffer and file sizes in '*buffer_sizep' and '*file_sizep'.
- In case of error, returns 0 and does not modify '*size'.
+ In case of error, return 0 and do not modify '*sizep'.
*/
static uint8_t * read_file( const int infd, long * const buffer_sizep,
long * const file_sizep, const char * const filename )
@@ -64,8 +64,8 @@ static uint8_t * read_file( const int infd, long * const buffer_sizep,
while( file_size >= buffer_size && !errno )
{
if( buffer_size >= LONG_MAX )
- { show_file_error( filename, "File is too large.", 0 ); free( buffer );
- return 0; }
+ { show_file_error( filename, "Input file is too large.", 0 );
+ free( buffer ); return 0; }
buffer_size = ( buffer_size <= LONG_MAX / 2 ) ? 2 * buffer_size : LONG_MAX;
uint8_t * const tmp = (uint8_t *)realloc( buffer, buffer_size );
if( !tmp )
@@ -97,9 +97,9 @@ static const char * set_file_sizes( struct File_sizes * const file_sizes,
if( file_size <= Lh_size ) return "File ends unexpectedly at member header.";
if( file_size < min_member_size ) return "Input file is too short.";
const Lzip_header * header = (const Lzip_header *)buffer;
- if( !Lh_verify_magic( *header ) )
+ if( !Lh_check_magic( *header ) )
return "Bad magic number (file not in lzip format).";
- if( !Lh_verify_version( *header ) )
+ if( !Lh_check_version( *header ) )
return "Version of lzip member format not supported.";
file_sizes->csize = file_sizes->dsize = file_sizes->tsize = 0;
@@ -122,7 +122,7 @@ static const char * set_file_sizes( struct File_sizes * const file_sizes,
return "Member size in trailer is corrupt.";
}
header = (const Lzip_header *)( buffer + pos - member_size );
- if( !Lh_verify_magic( *header ) || !Lh_verify_version( *header ) )
+ if( !Lh_check_magic( *header ) || !Lh_check_version( *header ) )
{
if( file_sizes->csize == 0 ) { --pos; continue; } /* maybe trailing data */
return "Bad member header inside file.";
@@ -132,7 +132,7 @@ static const char * set_file_sizes( struct File_sizes * const file_sizes,
file_sizes->tsize = file_size - pos;
header = (const Lzip_header *)( buffer + pos );
if( file_size - pos > Lh_size &&
- Lh_verify_magic( *header ) && Lh_verify_version( *header ) )
+ Lh_check_magic( *header ) && Lh_check_version( *header ) )
return "Last member in input file is truncated or corrupt.";
}
pos -= member_size;
@@ -155,7 +155,7 @@ static void error(char *x) { show_file_error( global_name, x, 0 ); }
/*
* Load the compressed file at the end of the buffer used to hold the
- * decompressed data. Verify that the in-place decompression does not
+ * decompressed data. Check that the in-place decompression does not
* overwrite the compressed data. The buffer must be large enough to contain
* after the decompressed data extra space for a marker, a trailer, the
* maximum possible data expansion, and (if multimember) N-1 empty members.
@@ -180,7 +180,7 @@ int decompress_in_place( const int infd, struct Pretty_print * const pp,
const long csize = file_sizes.csize;
const long dsize = file_sizes.dsize;
/* const long extra_bytes = ( dsize >> 8 ) + 65536; wrong linux formula */
- const long extra_bytes = ( csize >> 6 ) + file_sizes.members * 36;
+ const long extra_bytes = ( csize >> 6 ) + file_sizes.members * min_member_size;
const long long target_buffer_size = max( dsize, csize ) + extra_bytes;
if( target_buffer_size > LONG_MAX )
{ show_file_error( pp->name, "Buffer is larger than LONG_MAX.", 0 );