Hello

Splitting an lzip file using 'lziprecover -s' is currently
broken. This is because File_index::File_index() moves the file
offset of the input file. In do_split_file() the read buffer is
filled before File_index::File_index() is called and subsequent
reads continue at the wrong position. The attached patch fixes
this by moving the call to File_index::File_index() before the
call to seek_read().

cheers,
Hampa
diff -Nur -p 01_split-1/split.cc 01_split-2/split.cc
--- 01_split-1/split.cc	2017-03-12 19:34:30.000000000 +0100
+++ 01_split-2/split.cc	2018-01-22 21:46:17.255636116 +0100
@@ -99,6 +99,13 @@ int do_split_file( const std::string & i
   const int infd = open_instream( input_filename.c_str(), &in_stats, true, true );
   if( infd < 0 ) return 1;
   Pretty_print pp( input_filename, verbosity );
+
+  const File_index file_index( infd, true, true );
+  if( file_index.retval() != 0 ) pp( file_index.error().c_str() );
+  const long max_members = file_index.retval() ? 999999 : file_index.members();
+  int max_digits = 1;
+  for( long i = max_members; i >= 10; i /= 10 ) ++max_digits;
+
   int size = seek_read( infd, buffer, buffer_size + hsize, 0 ) - hsize;
   bool at_stream_end = ( size < buffer_size );
   if( size != buffer_size && errno )
@@ -107,11 +114,6 @@ int do_split_file( const std::string & i
     { pp( "Input file is too short." ); return 2; }
   if( !verify_header( *(File_header *)buffer, pp ) ) return 2;
 
-  const File_index file_index( infd, true, true );
-  if( file_index.retval() != 0 ) pp( file_index.error().c_str() );
-  const long max_members = file_index.retval() ? 999999 : file_index.members();
-  int max_digits = 1;
-  for( long i = max_members; i >= 10; i /= 10 ) ++max_digits;
 
   first_filename( input_filename, default_output_filename, max_digits );
   if( !open_outstream( force, false, false, false ) )
_______________________________________________
Lzip-bug mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lzip-bug

Reply via email to