diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-27 06:46:02 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-27 06:46:02 +0000 |
commit | 2e41d0cb777e6af086b45555551780e02ad13f46 (patch) | |
tree | a53d807aeb25003e5a8ea22461079a10b5238e4d /archival/libunarchive | |
parent | a47a3eada6ada1168205f6684e5c5a5c23d3558b (diff) | |
download | busybox-w32-2e41d0cb777e6af086b45555551780e02ad13f46.tar.gz busybox-w32-2e41d0cb777e6af086b45555551780e02ad13f46.tar.bz2 busybox-w32-2e41d0cb777e6af086b45555551780e02ad13f46.zip |
Fix compress support and prevent a segfault
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/check_header_gzip.c | 11 | ||||
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 1 | ||||
-rw-r--r-- | archival/libunarchive/decompress_uncompress.c | 26 | ||||
-rw-r--r-- | archival/libunarchive/filter_accept_all.c | 6 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 1 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar_gz.c | 9 | ||||
-rw-r--r-- | archival/libunarchive/uncompress.c | 26 |
7 files changed, 35 insertions, 45 deletions
diff --git a/archival/libunarchive/check_header_gzip.c b/archival/libunarchive/check_header_gzip.c index 508d30924..e8bb8d547 100644 --- a/archival/libunarchive/check_header_gzip.c +++ b/archival/libunarchive/check_header_gzip.c | |||
@@ -5,9 +5,8 @@ | |||
5 | extern void check_header_gzip(int src_fd) | 5 | extern void check_header_gzip(int src_fd) |
6 | { | 6 | { |
7 | union { | 7 | union { |
8 | unsigned char raw[10]; | 8 | unsigned char raw[8]; |
9 | struct { | 9 | struct { |
10 | unsigned char magic[2]; | ||
11 | unsigned char method; | 10 | unsigned char method; |
12 | unsigned char flags; | 11 | unsigned char flags; |
13 | unsigned int mtime; | 12 | unsigned int mtime; |
@@ -16,13 +15,7 @@ extern void check_header_gzip(int src_fd) | |||
16 | } formated; | 15 | } formated; |
17 | } header; | 16 | } header; |
18 | 17 | ||
19 | xread_all(src_fd, header.raw, 10); | 18 | xread_all(src_fd, header.raw, 8); |
20 | |||
21 | /* Magic header for gzip files, 1F 8B = \037\213 */ | ||
22 | if ((header.formated.magic[0] != 0x1F) | ||
23 | || (header.formated.magic[1] != 0x8b)) { | ||
24 | error_msg_and_die("Invalid gzip magic"); | ||
25 | } | ||
26 | 19 | ||
27 | /* Check the compression method */ | 20 | /* Check the compression method */ |
28 | if (header.formated.method != 8) { | 21 | if (header.formated.method != 8) { |
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index 20d99aa58..a80f422b7 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -18,7 +18,6 @@ extern void data_extract_all(archive_handle_t *archive_handle) | |||
18 | if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { | 18 | if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { |
19 | char *dir = dirname(strdup(file_header->name)); | 19 | char *dir = dirname(strdup(file_header->name)); |
20 | make_directory (dir, 0777, FILEUTILS_RECUR); | 20 | make_directory (dir, 0777, FILEUTILS_RECUR); |
21 | free(dir); | ||
22 | } | 21 | } |
23 | 22 | ||
24 | /* Create the file */ | 23 | /* Create the file */ |
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index 903e6aa6d..949e27df1 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c | |||
@@ -28,8 +28,9 @@ | |||
28 | * [... History snipped ...] | 28 | * [... History snipped ...] |
29 | * | 29 | * |
30 | */ | 30 | */ |
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | #include <string.h> | |
33 | #include <unistd.h> | ||
33 | 34 | ||
34 | #define IBUFSIZ 2048 /* Defailt input buffer size */ | 35 | #define IBUFSIZ 2048 /* Defailt input buffer size */ |
35 | #define OBUFSIZ 2048 /* Default output buffer size */ | 36 | #define OBUFSIZ 2048 /* Default output buffer size */ |
@@ -95,9 +96,6 @@ unsigned short codetab[HSIZE]; | |||
95 | #define clear_tab_prefixof() memset(codetab, 0, 256); | 96 | #define clear_tab_prefixof() memset(codetab, 0, 256); |
96 | 97 | ||
97 | 98 | ||
98 | extern int uncompress ( FILE *, FILE * ); | ||
99 | |||
100 | |||
101 | /* | 99 | /* |
102 | * Decompress stdin to stdout. This routine adapts to the codes in the | 100 | * Decompress stdin to stdout. This routine adapts to the codes in the |
103 | * file building the "string" table on-the-fly; requiring no table to | 101 | * file building the "string" table on-the-fly; requiring no table to |
@@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * ); | |||
105 | * with those of the compress() routine. See the definitions above. | 103 | * with those of the compress() routine. See the definitions above. |
106 | */ | 104 | */ |
107 | 105 | ||
108 | int uncompress ( FILE * fdin, FILE * fdout ) | 106 | extern int uncompress(int fd_in, int fd_out) |
109 | { | 107 | { |
110 | char_type *stackp; | 108 | char_type *stackp; |
111 | code_int code; | 109 | code_int code; |
@@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout ) | |||
125 | 123 | ||
126 | insize = 0; | 124 | insize = 0; |
127 | 125 | ||
128 | inbuf [0] = fgetc(fdin); | 126 | inbuf [0] = xread_char(fd_in); |
129 | 127 | ||
130 | maxbits = inbuf[0] & BIT_MASK; | 128 | maxbits = inbuf[0] & BIT_MASK; |
131 | block_mode = inbuf[0] & BLOCK_MODE; | 129 | block_mode = inbuf[0] & BLOCK_MODE; |
@@ -173,11 +171,7 @@ resetbuf: ; | |||
173 | 171 | ||
174 | if (insize < (int) sizeof(inbuf)-IBUFSIZ) | 172 | if (insize < (int) sizeof(inbuf)-IBUFSIZ) |
175 | { | 173 | { |
176 | rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin); | 174 | xread_all(fd_in, inbuf+insize, IBUFSIZ); |
177 | |||
178 | if ( !rsize && ferror(fdin)) | ||
179 | return -1; | ||
180 | |||
181 | insize += rsize; | 175 | insize += rsize; |
182 | } | 176 | } |
183 | 177 | ||
@@ -275,8 +269,7 @@ resetbuf: ; | |||
275 | 269 | ||
276 | if (outpos >= OBUFSIZ) | 270 | if (outpos >= OBUFSIZ) |
277 | { | 271 | { |
278 | fwrite(outbuf, 1,outpos,fdout); | 272 | write(fd_out, outbuf, outpos); |
279 | |||
280 | outpos = 0; | 273 | outpos = 0; |
281 | } | 274 | } |
282 | stackp+= i; | 275 | stackp+= i; |
@@ -303,8 +296,9 @@ resetbuf: ; | |||
303 | } | 296 | } |
304 | while (rsize > 0); | 297 | while (rsize > 0); |
305 | 298 | ||
306 | if (outpos > 0) | 299 | if (outpos > 0) { |
307 | fwrite(outbuf, outpos,1, fdout); | 300 | write(fd_out, outbuf, outpos); |
301 | } | ||
308 | 302 | ||
309 | return 0; | 303 | return 0; |
310 | } | 304 | } |
diff --git a/archival/libunarchive/filter_accept_all.c b/archival/libunarchive/filter_accept_all.c index 0471ccef0..2838ea1f2 100644 --- a/archival/libunarchive/filter_accept_all.c +++ b/archival/libunarchive/filter_accept_all.c | |||
@@ -6,5 +6,9 @@ | |||
6 | */ | 6 | */ |
7 | extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key) | 7 | extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key) |
8 | { | 8 | { |
9 | return(EXIT_SUCCESS); | 9 | if (key) { |
10 | return(EXIT_SUCCESS); | ||
11 | } else { | ||
12 | return(EXIT_FAILURE); | ||
13 | } | ||
10 | } | 14 | } |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 2c8fc0aa0..bb0affeb3 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -155,7 +155,6 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
155 | # endif | 155 | # endif |
156 | } | 156 | } |
157 | #endif | 157 | #endif |
158 | |||
159 | if (archive_handle->filter(archive_handle->accept, archive_handle->reject, archive_handle->file_header->name) == EXIT_SUCCESS) { | 158 | if (archive_handle->filter(archive_handle->accept, archive_handle->reject, archive_handle->file_header->name) == EXIT_SUCCESS) { |
160 | archive_handle->action_header(archive_handle->file_header); | 159 | archive_handle->action_header(archive_handle->file_header); |
161 | archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; | 160 | archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; |
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c index c06beac9d..24d19fbfd 100644 --- a/archival/libunarchive/get_header_tar_gz.c +++ b/archival/libunarchive/get_header_tar_gz.c | |||
@@ -27,11 +27,17 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle) | |||
27 | { | 27 | { |
28 | int fd_pipe[2]; | 28 | int fd_pipe[2]; |
29 | int pid; | 29 | int pid; |
30 | unsigned char magic[2]; | ||
31 | |||
32 | xread_all(archive_handle->src_fd, &magic, 2); | ||
33 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { | ||
34 | error_msg_and_die("Invalid gzip magic"); | ||
35 | } | ||
30 | 36 | ||
31 | check_header_gzip(archive_handle->src_fd); | 37 | check_header_gzip(archive_handle->src_fd); |
32 | 38 | ||
33 | if (pipe(fd_pipe) != 0) { | 39 | if (pipe(fd_pipe) != 0) { |
34 | error_msg_and_die("Can't create pipe\n"); | 40 | error_msg_and_die("Can't create pipe"); |
35 | } | 41 | } |
36 | 42 | ||
37 | pid = fork(); | 43 | pid = fork(); |
@@ -54,6 +60,7 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle) | |||
54 | 60 | ||
55 | archive_handle->src_fd = fd_pipe[0]; | 61 | archive_handle->src_fd = fd_pipe[0]; |
56 | 62 | ||
63 | archive_handle->offset = 0; | ||
57 | while (get_header_tar(archive_handle) == EXIT_SUCCESS); | 64 | while (get_header_tar(archive_handle) == EXIT_SUCCESS); |
58 | 65 | ||
59 | if (kill(pid, SIGTERM) == -1) { | 66 | if (kill(pid, SIGTERM) == -1) { |
diff --git a/archival/libunarchive/uncompress.c b/archival/libunarchive/uncompress.c index 903e6aa6d..949e27df1 100644 --- a/archival/libunarchive/uncompress.c +++ b/archival/libunarchive/uncompress.c | |||
@@ -28,8 +28,9 @@ | |||
28 | * [... History snipped ...] | 28 | * [... History snipped ...] |
29 | * | 29 | * |
30 | */ | 30 | */ |
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | #include <string.h> | |
33 | #include <unistd.h> | ||
33 | 34 | ||
34 | #define IBUFSIZ 2048 /* Defailt input buffer size */ | 35 | #define IBUFSIZ 2048 /* Defailt input buffer size */ |
35 | #define OBUFSIZ 2048 /* Default output buffer size */ | 36 | #define OBUFSIZ 2048 /* Default output buffer size */ |
@@ -95,9 +96,6 @@ unsigned short codetab[HSIZE]; | |||
95 | #define clear_tab_prefixof() memset(codetab, 0, 256); | 96 | #define clear_tab_prefixof() memset(codetab, 0, 256); |
96 | 97 | ||
97 | 98 | ||
98 | extern int uncompress ( FILE *, FILE * ); | ||
99 | |||
100 | |||
101 | /* | 99 | /* |
102 | * Decompress stdin to stdout. This routine adapts to the codes in the | 100 | * Decompress stdin to stdout. This routine adapts to the codes in the |
103 | * file building the "string" table on-the-fly; requiring no table to | 101 | * file building the "string" table on-the-fly; requiring no table to |
@@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * ); | |||
105 | * with those of the compress() routine. See the definitions above. | 103 | * with those of the compress() routine. See the definitions above. |
106 | */ | 104 | */ |
107 | 105 | ||
108 | int uncompress ( FILE * fdin, FILE * fdout ) | 106 | extern int uncompress(int fd_in, int fd_out) |
109 | { | 107 | { |
110 | char_type *stackp; | 108 | char_type *stackp; |
111 | code_int code; | 109 | code_int code; |
@@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout ) | |||
125 | 123 | ||
126 | insize = 0; | 124 | insize = 0; |
127 | 125 | ||
128 | inbuf [0] = fgetc(fdin); | 126 | inbuf [0] = xread_char(fd_in); |
129 | 127 | ||
130 | maxbits = inbuf[0] & BIT_MASK; | 128 | maxbits = inbuf[0] & BIT_MASK; |
131 | block_mode = inbuf[0] & BLOCK_MODE; | 129 | block_mode = inbuf[0] & BLOCK_MODE; |
@@ -173,11 +171,7 @@ resetbuf: ; | |||
173 | 171 | ||
174 | if (insize < (int) sizeof(inbuf)-IBUFSIZ) | 172 | if (insize < (int) sizeof(inbuf)-IBUFSIZ) |
175 | { | 173 | { |
176 | rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin); | 174 | xread_all(fd_in, inbuf+insize, IBUFSIZ); |
177 | |||
178 | if ( !rsize && ferror(fdin)) | ||
179 | return -1; | ||
180 | |||
181 | insize += rsize; | 175 | insize += rsize; |
182 | } | 176 | } |
183 | 177 | ||
@@ -275,8 +269,7 @@ resetbuf: ; | |||
275 | 269 | ||
276 | if (outpos >= OBUFSIZ) | 270 | if (outpos >= OBUFSIZ) |
277 | { | 271 | { |
278 | fwrite(outbuf, 1,outpos,fdout); | 272 | write(fd_out, outbuf, outpos); |
279 | |||
280 | outpos = 0; | 273 | outpos = 0; |
281 | } | 274 | } |
282 | stackp+= i; | 275 | stackp+= i; |
@@ -303,8 +296,9 @@ resetbuf: ; | |||
303 | } | 296 | } |
304 | while (rsize > 0); | 297 | while (rsize > 0); |
305 | 298 | ||
306 | if (outpos > 0) | 299 | if (outpos > 0) { |
307 | fwrite(outbuf, outpos,1, fdout); | 300 | write(fd_out, outbuf, outpos); |
301 | } | ||
308 | 302 | ||
309 | return 0; | 303 | return 0; |
310 | } | 304 | } |