diff options
Diffstat (limited to 'zutils.cc')
-rw-r--r-- | zutils.cc | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -244,7 +244,7 @@ bool set_data_feeder( const std::string & filename, int * const infdp, } -// Return format_index, or -1 if uncompressed. +// Return format_index, or -1 if uncompressed or shorter than magic_buf_size. // int test_format( const int infd, uint8_t magic_data[], int * const magic_sizep ) @@ -269,22 +269,24 @@ int test_format( const int infd, uint8_t magic_data[], { 0x28, 0xB5, 0x2F, 0xFD }; // 0xFD2FB528 LE *magic_sizep = readblock( infd, magic_data, magic_buf_size ); - if( *magic_sizep == magic_buf_size ) // test formats in search order - { - if( std::memcmp( magic_data, lzip_magic, lzip_magic_size ) == 0 && - isvalid_ds( magic_data[lzip_magic_size] ) ) - return fmt_lz; - if( std::memcmp( magic_data, bzip2_magic, bzip2_magic_size ) == 0 && - magic_data[3] >= '1' && magic_data[3] <= '9' && - std::memcmp( magic_data + 4, "1AY&SY", 6 ) == 0 ) - return fmt_bz2; - if( std::memcmp( magic_data, gzip_magic, gzip_magic_size ) == 0 || - std::memcmp( magic_data, compress_magic, compress_magic_size ) == 0 ) - return fmt_gz; - if( std::memcmp( magic_data, zstd_magic, zstd_magic_size ) == 0 ) - return fmt_zst; - if( std::memcmp( magic_data, xz_magic, xz_magic_size ) == 0 ) - return fmt_xz; - } + if( *magic_sizep < magic_buf_size ) + { if( errno ) return -1; // read error + for( int i = *magic_sizep; i < magic_buf_size; ++i ) magic_data[i] = 0; } + // test formats in search order + if( std::memcmp( magic_data, lzip_magic, lzip_magic_size ) == 0 && + isvalid_ds( magic_data[lzip_magic_size] ) ) + return fmt_lz; + if( std::memcmp( magic_data, bzip2_magic, bzip2_magic_size ) == 0 && + magic_data[3] >= '1' && magic_data[3] <= '9' && + ( std::memcmp( magic_data + 4, "1AY&SY", 6 ) == 0 || + std::memcmp( magic_data + 4, "\x17rE8P\x90", 6 ) == 0 ) ) + return fmt_bz2; + if( std::memcmp( magic_data, gzip_magic, gzip_magic_size ) == 0 || + std::memcmp( magic_data, compress_magic, compress_magic_size ) == 0 ) + return fmt_gz; + if( std::memcmp( magic_data, zstd_magic, zstd_magic_size ) == 0 ) + return fmt_zst; + if( std::memcmp( magic_data, xz_magic, xz_magic_size ) == 0 ) + return fmt_xz; return -1; } |