"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include "libbb.h" |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 5 | #include "unarchive.h" /* for external decl of check_header_gzip */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 6 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 7 | void check_header_gzip(int src_fd) |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 8 | { |
| 9 | union { |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 10 | unsigned char raw[8]; |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 11 | struct { |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 12 | unsigned char method; |
| 13 | unsigned char flags; |
| 14 | unsigned int mtime; |
| 15 | unsigned char xtra_flags; |
| 16 | unsigned char os_flags; |
| 17 | } formated; |
| 18 | } header; |
| 19 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 20 | bb_xread_all(src_fd, header.raw, 8); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 21 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 22 | /* Check the compression method */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 23 | if (header.formated.method != 8) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 24 | bb_error_msg_and_die("Unknown compression method %d", |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 25 | header.formated.method); |
| 26 | } |
| 27 | |
| 28 | if (header.formated.flags & 0x04) { |
| 29 | /* bit 2 set: extra field present */ |
| 30 | unsigned char extra_short; |
| 31 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 32 | extra_short = bb_xread_char(src_fd) + (bb_xread_char(src_fd) << 8); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 33 | while (extra_short > 0) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 34 | /* Ignore extra field */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 35 | bb_xread_char(src_fd); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 36 | extra_short--; |
| 37 | } |
| 38 | } |
| 39 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 40 | /* Discard original name if any */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 41 | if (header.formated.flags & 0x08) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 42 | /* bit 3 set: original file name present */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 43 | while(bb_xread_char(src_fd) != 0); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 46 | /* Discard file comment if any */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 47 | if (header.formated.flags & 0x10) { |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 48 | /* bit 4 set: file comment present */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 49 | while(bb_xread_char(src_fd) != 0); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Glenn L McGrath | 9c60b29 | 2002-11-03 10:57:25 +0000 | [diff] [blame] | 52 | /* Read the header checksum */ |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 53 | if (header.formated.flags & 0x02) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 54 | bb_xread_char(src_fd); |
| 55 | bb_xread_char(src_fd); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return; |
| 59 | } |