Lines 900-906
Link Here
|
900 |
* Warning: this function moves the current file pointer */ |
900 |
* Warning: this function moves the current file pointer */ |
901 |
int get_compression_type (int fd) |
901 |
int get_compression_type (int fd) |
902 |
{ |
902 |
{ |
903 |
unsigned char magic[4]; |
903 |
unsigned char magic[16]; |
904 |
|
904 |
|
905 |
/* Read the magic signature */ |
905 |
/* Read the magic signature */ |
906 |
if (mc_read (fd, (char *) magic, 4) != 4) |
906 |
if (mc_read (fd, (char *) magic, 4) != 4) |
Lines 944-949
Link Here
|
944 |
return COMPRESSION_BZIP2; |
944 |
return COMPRESSION_BZIP2; |
945 |
} |
945 |
} |
946 |
} |
946 |
} |
|
|
947 |
|
948 |
/* LZMA files; both LZMA_Alone and LZMA utils formats. The LZMA_Alone |
949 |
* format is used by the LZMA_Alone tool from LZMA SDK. The LZMA utils |
950 |
* format is the default format of LZMA utils 4.32.1 and later. */ |
951 |
if (magic[0] < 0xE1 || (magic[0] == 0xFF && magic[1] == 'L' && |
952 |
magic[2] == 'Z' && magic[3] == 'M')) { |
953 |
if (mc_read (fd, (char *) magic + 4, 9) == 9) { |
954 |
/* LZMA utils format */ |
955 |
if (magic[0] == 0xFF && magic[4] == 'A' && magic[5] == 0x00) |
956 |
return COMPRESSION_LZMA; |
957 |
/* The LZMA_Alone format has no magic bytes, thus we |
958 |
* need to play a wizard. This can give false positives, |
959 |
* thus the detection below should be removed when |
960 |
* the newer LZMA utils format has got popular. */ |
961 |
if (magic[0] < 0xE1 && magic[4] < 0x20 && |
962 |
((magic[10] == 0x00 && magic[11] == 0x00 && |
963 |
magic[12] == 0x00) || |
964 |
(magic[5] == 0xFF && magic[6] == 0xFF && |
965 |
magic[7] == 0xFF && magic[8] == 0xFF && |
966 |
magic[9] == 0xFF && magic[10] == 0xFF && |
967 |
magic[11] == 0xFF && magic[12] == 0xFF))) |
968 |
return COMPRESSION_LZMA; |
969 |
} |
970 |
} |
971 |
|
947 |
return 0; |
972 |
return 0; |
948 |
} |
973 |
} |
949 |
|
974 |
|
Lines 954-959
Link Here
|
954 |
case COMPRESSION_GZIP: return "#ugz"; |
979 |
case COMPRESSION_GZIP: return "#ugz"; |
955 |
case COMPRESSION_BZIP: return "#ubz"; |
980 |
case COMPRESSION_BZIP: return "#ubz"; |
956 |
case COMPRESSION_BZIP2: return "#ubz2"; |
981 |
case COMPRESSION_BZIP2: return "#ubz2"; |
|
|
982 |
case COMPRESSION_LZMA: return "#ulzma"; |
957 |
} |
983 |
} |
958 |
/* Should never reach this place */ |
984 |
/* Should never reach this place */ |
959 |
fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); |
985 |
fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); |