diff options
| -rw-r--r-- | archival/libunarchive/Makefile.in | 1 | ||||
| -rw-r--r-- | archival/libunarchive/decompress_unzip.c | 53 | ||||
| -rw-r--r-- | archival/libunarchive/unzip.c | 53 |
3 files changed, 80 insertions, 27 deletions
diff --git a/archival/libunarchive/Makefile.in b/archival/libunarchive/Makefile.in index b59048612..fc277d1c4 100644 --- a/archival/libunarchive/Makefile.in +++ b/archival/libunarchive/Makefile.in | |||
| @@ -55,7 +55,6 @@ LIBUNARCHIVE-y:= \ | |||
| 55 | archive_copy_file.o \ | 55 | archive_copy_file.o \ |
| 56 | \ | 56 | \ |
| 57 | check_header_gzip.o \ | 57 | check_header_gzip.o \ |
| 58 | check_trailer_gzip.o \ | ||
| 59 | data_align.o \ | 58 | data_align.o \ |
| 60 | decompress_bunzip2.o \ | 59 | decompress_bunzip2.o \ |
| 61 | find_list_entry.o \ | 60 | find_list_entry.o \ |
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 1b2d587d6..8da9b5cb9 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
| @@ -83,29 +83,31 @@ typedef struct huft_s { | |||
| 83 | } huft_t; | 83 | } huft_t; |
| 84 | 84 | ||
| 85 | static int gunzip_src_fd; | 85 | static int gunzip_src_fd; |
| 86 | unsigned int gunzip_bytes_out; /* number of output bytes */ | 86 | static unsigned int gunzip_bytes_out; /* number of output bytes */ |
| 87 | static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ | 87 | static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ |
| 88 | 88 | ||
| 89 | /* This is used to sanify any unused bits from the bitbuffer | ||
| 90 | * so they arent skipped when reading trailers (trailing headers) */ | ||
| 91 | //unsigned char gunzip_in_buffer_count; | ||
| 92 | //unsigned char *gunzip_in_buffer; | ||
| 93 | |||
| 94 | /* gunzip_window size--must be a power of two, and | 89 | /* gunzip_window size--must be a power of two, and |
| 95 | * at least 32K for zip's deflate method */ | 90 | * at least 32K for zip's deflate method */ |
| 96 | static const int gunzip_wsize = 0x8000; | 91 | static const int gunzip_wsize = 0x8000; |
| 97 | |||
| 98 | static unsigned char *gunzip_window; | 92 | static unsigned char *gunzip_window; |
| 93 | |||
| 99 | static unsigned int *gunzip_crc_table; | 94 | static unsigned int *gunzip_crc_table; |
| 100 | unsigned int gunzip_crc; | 95 | static unsigned int gunzip_crc; |
| 101 | 96 | ||
| 102 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ | 97 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ |
| 103 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ | 98 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ |
| 104 | #define N_MAX 288 /* maximum number of codes in any set */ | 99 | #define N_MAX 288 /* maximum number of codes in any set */ |
| 105 | 100 | ||
| 101 | /* bitbuffer */ | ||
| 106 | static unsigned int gunzip_bb; /* bit buffer */ | 102 | static unsigned int gunzip_bb; /* bit buffer */ |
| 107 | static unsigned char gunzip_bk; /* bits in bit buffer */ | 103 | static unsigned char gunzip_bk; /* bits in bit buffer */ |
| 108 | 104 | ||
| 105 | /* These control the size of the bytebuffer */ | ||
| 106 | #define BYTEBUFFER_MAX 0x8000 | ||
| 107 | static unsigned char *bytebuffer = NULL; | ||
| 108 | static unsigned int bytebuffer_offset = 0; | ||
| 109 | static unsigned int bytebuffer_size = 0; | ||
| 110 | |||
| 109 | static const unsigned short mask_bits[] = { | 111 | static const unsigned short mask_bits[] = { |
| 110 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, | 112 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, |
| 111 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 113 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
| @@ -142,11 +144,6 @@ static const unsigned char border[] = { | |||
| 142 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 | 144 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
| 143 | }; | 145 | }; |
| 144 | 146 | ||
| 145 | #define BYTEBUFFER_MAX 0x8000 | ||
| 146 | unsigned char *bytebuffer = NULL; | ||
| 147 | unsigned int bytebuffer_offset = 0; | ||
| 148 | unsigned int bytebuffer_size = 0; | ||
| 149 | |||
| 150 | static void fill_bytebuffer(void) | 147 | static void fill_bytebuffer(void) |
| 151 | { | 148 | { |
| 152 | if (bytebuffer_offset >= bytebuffer_size) { | 149 | if (bytebuffer_offset >= bytebuffer_size) { |
| @@ -1011,3 +1008,33 @@ extern int inflate(int in, int out) | |||
| 1011 | GZ_gzReadClose(); | 1008 | GZ_gzReadClose(); |
| 1012 | return 0; | 1009 | return 0; |
| 1013 | } | 1010 | } |
| 1011 | |||
| 1012 | extern void check_trailer_gzip(int src_fd) | ||
| 1013 | { | ||
| 1014 | unsigned int stored_crc = 0; | ||
| 1015 | unsigned char count; | ||
| 1016 | |||
| 1017 | /* top up the input buffer with the rest of the trailer */ | ||
| 1018 | count = bytebuffer_size - bytebuffer_offset; | ||
| 1019 | if (count < 8) { | ||
| 1020 | xread_all(src_fd, &bytebuffer[bytebuffer_size], 8 - count); | ||
| 1021 | bytebuffer_size += 8 - count; | ||
| 1022 | } | ||
| 1023 | for (count = 0; count != 4; count++) { | ||
| 1024 | stored_crc |= (bytebuffer[bytebuffer_offset] << (count * 8)); | ||
| 1025 | bytebuffer_offset++; | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | /* Validate decompression - crc */ | ||
| 1029 | if (stored_crc != (gunzip_crc ^ 0xffffffffL)) { | ||
| 1030 | error_msg_and_die("crc error"); | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | /* Validate decompression - size */ | ||
| 1034 | if (gunzip_bytes_out != | ||
| 1035 | (bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) | | ||
| 1036 | (bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))) { | ||
| 1037 | error_msg_and_die("Incorrect length, but crc is correct"); | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | } | ||
diff --git a/archival/libunarchive/unzip.c b/archival/libunarchive/unzip.c index 1b2d587d6..8da9b5cb9 100644 --- a/archival/libunarchive/unzip.c +++ b/archival/libunarchive/unzip.c | |||
| @@ -83,29 +83,31 @@ typedef struct huft_s { | |||
| 83 | } huft_t; | 83 | } huft_t; |
| 84 | 84 | ||
| 85 | static int gunzip_src_fd; | 85 | static int gunzip_src_fd; |
| 86 | unsigned int gunzip_bytes_out; /* number of output bytes */ | 86 | static unsigned int gunzip_bytes_out; /* number of output bytes */ |
| 87 | static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ | 87 | static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ |
| 88 | 88 | ||
| 89 | /* This is used to sanify any unused bits from the bitbuffer | ||
| 90 | * so they arent skipped when reading trailers (trailing headers) */ | ||
| 91 | //unsigned char gunzip_in_buffer_count; | ||
| 92 | //unsigned char *gunzip_in_buffer; | ||
| 93 | |||
| 94 | /* gunzip_window size--must be a power of two, and | 89 | /* gunzip_window size--must be a power of two, and |
| 95 | * at least 32K for zip's deflate method */ | 90 | * at least 32K for zip's deflate method */ |
| 96 | static const int gunzip_wsize = 0x8000; | 91 | static const int gunzip_wsize = 0x8000; |
| 97 | |||
| 98 | static unsigned char *gunzip_window; | 92 | static unsigned char *gunzip_window; |
| 93 | |||
| 99 | static unsigned int *gunzip_crc_table; | 94 | static unsigned int *gunzip_crc_table; |
| 100 | unsigned int gunzip_crc; | 95 | static unsigned int gunzip_crc; |
| 101 | 96 | ||
| 102 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ | 97 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ |
| 103 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ | 98 | #define BMAX 16 /* maximum bit length of any code (16 for explode) */ |
| 104 | #define N_MAX 288 /* maximum number of codes in any set */ | 99 | #define N_MAX 288 /* maximum number of codes in any set */ |
| 105 | 100 | ||
| 101 | /* bitbuffer */ | ||
| 106 | static unsigned int gunzip_bb; /* bit buffer */ | 102 | static unsigned int gunzip_bb; /* bit buffer */ |
| 107 | static unsigned char gunzip_bk; /* bits in bit buffer */ | 103 | static unsigned char gunzip_bk; /* bits in bit buffer */ |
| 108 | 104 | ||
| 105 | /* These control the size of the bytebuffer */ | ||
| 106 | #define BYTEBUFFER_MAX 0x8000 | ||
| 107 | static unsigned char *bytebuffer = NULL; | ||
| 108 | static unsigned int bytebuffer_offset = 0; | ||
| 109 | static unsigned int bytebuffer_size = 0; | ||
| 110 | |||
| 109 | static const unsigned short mask_bits[] = { | 111 | static const unsigned short mask_bits[] = { |
| 110 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, | 112 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, |
| 111 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 113 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
| @@ -142,11 +144,6 @@ static const unsigned char border[] = { | |||
| 142 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 | 144 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
| 143 | }; | 145 | }; |
| 144 | 146 | ||
| 145 | #define BYTEBUFFER_MAX 0x8000 | ||
| 146 | unsigned char *bytebuffer = NULL; | ||
| 147 | unsigned int bytebuffer_offset = 0; | ||
| 148 | unsigned int bytebuffer_size = 0; | ||
| 149 | |||
| 150 | static void fill_bytebuffer(void) | 147 | static void fill_bytebuffer(void) |
| 151 | { | 148 | { |
| 152 | if (bytebuffer_offset >= bytebuffer_size) { | 149 | if (bytebuffer_offset >= bytebuffer_size) { |
| @@ -1011,3 +1008,33 @@ extern int inflate(int in, int out) | |||
| 1011 | GZ_gzReadClose(); | 1008 | GZ_gzReadClose(); |
| 1012 | return 0; | 1009 | return 0; |
| 1013 | } | 1010 | } |
| 1011 | |||
| 1012 | extern void check_trailer_gzip(int src_fd) | ||
| 1013 | { | ||
| 1014 | unsigned int stored_crc = 0; | ||
| 1015 | unsigned char count; | ||
| 1016 | |||
| 1017 | /* top up the input buffer with the rest of the trailer */ | ||
| 1018 | count = bytebuffer_size - bytebuffer_offset; | ||
| 1019 | if (count < 8) { | ||
| 1020 | xread_all(src_fd, &bytebuffer[bytebuffer_size], 8 - count); | ||
| 1021 | bytebuffer_size += 8 - count; | ||
| 1022 | } | ||
| 1023 | for (count = 0; count != 4; count++) { | ||
| 1024 | stored_crc |= (bytebuffer[bytebuffer_offset] << (count * 8)); | ||
| 1025 | bytebuffer_offset++; | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | /* Validate decompression - crc */ | ||
| 1029 | if (stored_crc != (gunzip_crc ^ 0xffffffffL)) { | ||
| 1030 | error_msg_and_die("crc error"); | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | /* Validate decompression - size */ | ||
| 1034 | if (gunzip_bytes_out != | ||
| 1035 | (bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) | | ||
| 1036 | (bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))) { | ||
| 1037 | error_msg_and_die("Incorrect length, but crc is correct"); | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | } | ||
