Skip to content

Commit

Permalink
Fix reading ZIP files where no compression is used in the zip file.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Dec 9, 2024
1 parent 2b2df72 commit 3310bb4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/ZipArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,25 @@ size_t read_file_from_zip( std::istream &instrm,

inflateEnd( &strm );
return total_uncompressed;
}else if( header->compression_type == UNCOMPRESSED )
}else if( (header->compression_type == UNCOMPRESSED)
&& (header->compressed_size == header->uncompressed_size) )
{
const size_t nread = std::min( buffer_size - 4,
header->uncompressed_size - total_read );
instrm.read( (char*)(out+4), nread );
return static_cast<size_t>( instrm.gcount() );
size_t num_written = 0;
size_t num_bytes = header->compressed_size;
while( num_bytes > 0 )
{
const size_t nread = std::min( buffer_size, static_cast<const unsigned int>(num_bytes) );
instrm.read( (char *)in, nread );
std::streamsize bytes_read = instrm.gcount(); // Get the number of bytes actually read
output.write( (const char *)in, bytes_read );
num_bytes -= std::min( bytes_read, static_cast<std::streamsize>(num_bytes) );
num_written += bytes_read;

if( bytes_read < static_cast<std::streamsize>(nread) )
break;
}//while( num_bytes > 0 )

return num_written;
}else
{
throw runtime_error( "ZipArchive: unrecognized compression" );
Expand Down

0 comments on commit 3310bb4

Please sign in to comment.