aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/gunzip.c22
-rw-r--r--archival/libunarchive/check_header_gzip.c11
-rw-r--r--archival/libunarchive/data_extract_all.c1
-rw-r--r--archival/libunarchive/decompress_uncompress.c26
-rw-r--r--archival/libunarchive/filter_accept_all.c6
-rw-r--r--archival/libunarchive/get_header_tar.c1
-rw-r--r--archival/libunarchive/get_header_tar_gz.c9
-rw-r--r--archival/libunarchive/uncompress.c26
-rw-r--r--archival/rpm2cpio.c6
-rw-r--r--include/libbb.h1
-rw-r--r--include/unarchive.h2
-rw-r--r--libbb/uncompress.c26
12 files changed, 71 insertions, 66 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 4489204fb..6ec5c69ae 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -163,11 +163,25 @@ extern int gunzip_main(int argc, char **argv)
163 } 163 }
164 164
165 /* do the decompression, and cleanup */ 165 /* do the decompression, and cleanup */
166 check_header_gzip(src_fd); 166 if (xread_char(src_fd) == 0x1f) {
167 if (inflate(src_fd, dst_fd) != 0) { 167 unsigned char magic2;
168 error_msg("Error inflating"); 168
169 magic2 = xread_char(src_fd);
170#ifdef CONFIG_FEATURE_UNCOMPRESS
171 if (magic2 == 0x9d) {
172 return(uncompress(src_fd, dst_fd));
173 } else
174#endif
175 if (magic2 == 0x8b) {
176 check_header_gzip(src_fd);
177 if (inflate(src_fd, dst_fd) != 0) {
178 error_msg("Error inflating");
179 }
180 check_trailer_gzip(src_fd);
181 } else {
182 error_msg_and_die("Invalid magic\n");
183 }
169 } 184 }
170 check_trailer_gzip(src_fd);
171 185
172 if ((status != EXIT_SUCCESS) && (new_path)) { 186 if ((status != EXIT_SUCCESS) && (new_path)) {
173 /* Unzip failed, remove new path instead of old path */ 187 /* Unzip failed, remove new path instead of old path */
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 @@
5extern void check_header_gzip(int src_fd) 5extern 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
98extern 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
108int uncompress ( FILE * fdin, FILE * fdout ) 106extern 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 */
7extern char filter_accept_all(const llist_t *accept_list, const llist_t *reject_list, const char *key) 7extern 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
98extern 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
108int uncompress ( FILE * fdin, FILE * fdout ) 106extern 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/rpm2cpio.c b/archival/rpm2cpio.c
index e1e93988f..9372dc5e1 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -70,6 +70,7 @@ extern int rpm2cpio_main(int argc, char **argv)
70{ 70{
71 struct rpm_lead lead; 71 struct rpm_lead lead;
72 int rpm_fd; 72 int rpm_fd;
73 unsigned char magic[2];
73 74
74 if (argc == 1) { 75 if (argc == 1) {
75 rpm_fd = fileno(stdin); 76 rpm_fd = fileno(stdin);
@@ -88,6 +89,11 @@ extern int rpm2cpio_main(int argc, char **argv)
88 89
89 /* Skip the main header */ 90 /* Skip the main header */
90 skip_header(rpm_fd); 91 skip_header(rpm_fd);
92
93 xread_all(rpm_fd, &magic, 2);
94 if ((magic[0] != 0x1f) || (magic[1] != 0x8b))
95 error_msg_and_die("Invalid gzip magic");
96 }
91 97
92 check_header_gzip(rpm_fd); 98 check_header_gzip(rpm_fd);
93 if (inflate(rpm_fd, fileno(stdout)) != 0) { 99 if (inflate(rpm_fd, fileno(stdout)) != 0) {
diff --git a/include/libbb.h b/include/libbb.h
index 9dbbb47ce..2fec93db1 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -226,6 +226,7 @@ extern long arith (const char *startbuf, int *errcode);
226int read_package_field(const char *package_buffer, char **field_name, char **field_value); 226int read_package_field(const char *package_buffer, char **field_name, char **field_value);
227char *fgets_str(FILE *file, const char *terminating_string); 227char *fgets_str(FILE *file, const char *terminating_string);
228 228
229extern int uncompress(int fd_in, int fd_out);
229extern int inflate(int in, int out); 230extern int inflate(int in, int out);
230 231
231extern struct hostent *xgethostbyname(const char *name); 232extern struct hostent *xgethostbyname(const char *name);
diff --git a/include/unarchive.h b/include/unarchive.h
index e564e9572..023c3e8aa 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -85,7 +85,7 @@ extern char get_header_ar(archive_handle_t *archive_handle);
85extern char get_header_tar(archive_handle_t *archive_handle); 85extern char get_header_tar(archive_handle_t *archive_handle);
86extern char get_header_tar_gz(archive_handle_t *archive_handle); 86extern char get_header_tar_gz(archive_handle_t *archive_handle);
87 87
88//extern void seek_sub_file(int src_fd, unsigned int amount); 88extern void seek_sub_file(int src_fd, unsigned int amount);
89extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to); 89extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to);
90extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item); 90extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item);
91extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize); 91extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize);
diff --git a/libbb/uncompress.c b/libbb/uncompress.c
index 903e6aa6d..949e27df1 100644
--- a/libbb/uncompress.c
+++ b/libbb/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
98extern 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
108int uncompress ( FILE * fdin, FILE * fdout ) 106extern 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}