diff options
Diffstat (limited to 'archival/libunarchive/unzip.c')
-rw-r--r-- | archival/libunarchive/unzip.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/archival/libunarchive/unzip.c b/archival/libunarchive/unzip.c index d8d5b77b1..770e4141d 100644 --- a/archival/libunarchive/unzip.c +++ b/archival/libunarchive/unzip.c | |||
@@ -88,8 +88,8 @@ static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ | |||
88 | 88 | ||
89 | /* This is used to sanify any unused bits from the bitbuffer | 89 | /* This is used to sanify any unused bits from the bitbuffer |
90 | * so they arent skipped when reading trailers (trailing headers) */ | 90 | * so they arent skipped when reading trailers (trailing headers) */ |
91 | unsigned char gunzip_in_buffer_count; | 91 | //unsigned char gunzip_in_buffer_count; |
92 | unsigned char *gunzip_in_buffer; | 92 | //unsigned char *gunzip_in_buffer; |
93 | 93 | ||
94 | /* gunzip_window size--must be a power of two, and | 94 | /* gunzip_window size--must be a power of two, and |
95 | * at least 32K for zip's deflate method */ | 95 | * at least 32K for zip's deflate method */ |
@@ -142,13 +142,30 @@ 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 | 142 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
143 | }; | 143 | }; |
144 | 144 | ||
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() | ||
151 | { | ||
152 | if (bytebuffer_offset >= bytebuffer_size) { | ||
153 | /* Leave the first 4 bytes empty so we can always unwind the bitbuffer | ||
154 | * to the front of the bytebuffer, leave 4 bytes free at end of tail | ||
155 | * so we can easily top up buffer in check_trailer_gzip() */ | ||
156 | bytebuffer_size = 4 + xread(gunzip_src_fd, &bytebuffer[4], BYTEBUFFER_MAX - 8); | ||
157 | bytebuffer_offset = 4; | ||
158 | } | ||
159 | } | ||
160 | |||
145 | static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current, const unsigned int required) | 161 | static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current, const unsigned int required) |
146 | { | 162 | { |
147 | while (*current < required) { | 163 | while (*current < required) { |
148 | bitbuffer |= ((unsigned int) xread_char(gunzip_src_fd)) << *current; | 164 | fill_bytebuffer(); |
165 | bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current; | ||
166 | bytebuffer_offset++; | ||
149 | *current += 8; | 167 | *current += 8; |
150 | } | 168 | } |
151 | |||
152 | return(bitbuffer); | 169 | return(bitbuffer); |
153 | } | 170 | } |
154 | 171 | ||
@@ -857,7 +874,10 @@ static int inflate_get_next_window(void) | |||
857 | int ret; | 874 | int ret; |
858 | 875 | ||
859 | if (needAnotherBlock) { | 876 | if (needAnotherBlock) { |
860 | if(e) { calculate_gunzip_crc(); return 0; } // Last block | 877 | if(e) { |
878 | calculate_gunzip_crc(); | ||
879 | return 0; | ||
880 | } // Last block | ||
861 | method = inflate_block(&e); | 881 | method = inflate_block(&e); |
862 | needAnotherBlock = 0; | 882 | needAnotherBlock = 0; |
863 | } | 883 | } |
@@ -875,6 +895,7 @@ static int inflate_get_next_window(void) | |||
875 | return 1; // More data left | 895 | return 1; // More data left |
876 | } else needAnotherBlock = 1; // End of that block | 896 | } else needAnotherBlock = 1; // End of that block |
877 | } | 897 | } |
898 | /* Doesnt get here */ | ||
878 | } | 899 | } |
879 | 900 | ||
880 | /* | 901 | /* |
@@ -923,7 +944,8 @@ extern void GZ_gzReadOpen(int fd, void *unused, int nUnused) | |||
923 | gunzip_bytes_out = 0; | 944 | gunzip_bytes_out = 0; |
924 | gunzip_src_fd = fd; | 945 | gunzip_src_fd = fd; |
925 | 946 | ||
926 | gunzip_in_buffer = malloc(8); | 947 | /* Input buffer */ |
948 | bytebuffer = xmalloc(BYTEBUFFER_MAX); | ||
927 | 949 | ||
928 | /* initialize gunzip_window, bit buffer */ | 950 | /* initialize gunzip_window, bit buffer */ |
929 | gunzip_bk = 0; | 951 | gunzip_bk = 0; |
@@ -940,12 +962,11 @@ extern void GZ_gzReadClose(void) | |||
940 | free(gunzip_crc_table); | 962 | free(gunzip_crc_table); |
941 | 963 | ||
942 | /* Store unused bytes in a global buffer so calling applets can access it */ | 964 | /* Store unused bytes in a global buffer so calling applets can access it */ |
943 | gunzip_in_buffer_count = 0; | ||
944 | if (gunzip_bk >= 8) { | 965 | if (gunzip_bk >= 8) { |
945 | /* Undo too much lookahead. The next read will be byte aligned | 966 | /* Undo too much lookahead. The next read will be byte aligned |
946 | * so we can discard unused bits in the last meaningful byte. */ | 967 | * so we can discard unused bits in the last meaningful byte. */ |
947 | gunzip_in_buffer[gunzip_in_buffer_count] = gunzip_bb & 0xff; | 968 | bytebuffer_offset--; |
948 | gunzip_in_buffer_count++; | 969 | bytebuffer[bytebuffer_offset] = gunzip_bb & 0xff; |
949 | gunzip_bb >>= 8; | 970 | gunzip_bb >>= 8; |
950 | gunzip_bk -= 8; | 971 | gunzip_bk -= 8; |
951 | } | 972 | } |