blob: 00d1919a79ccbad0915fc6178d319412a6ae1241 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00002/*
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00005#include <stdlib.h>
6#include <unistd.h>
7#include "libbb.h"
Eric Andersen14f5c8d2005-04-16 19:39:00 +00008#include "unarchive.h" /* for external decl of check_header_gzip */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00009
Rob Landleydfba7412006-03-06 20:47:33 +000010void check_header_gzip(int src_fd)
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000011{
12 union {
Glenn L McGrath2e41d0c2002-09-27 06:46:02 +000013 unsigned char raw[8];
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000014 struct {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000015 unsigned char method;
16 unsigned char flags;
17 unsigned int mtime;
18 unsigned char xtra_flags;
19 unsigned char os_flags;
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000020 } formatted;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000021 } header;
22
Rob Landley53437472006-07-16 08:14:35 +000023 xread(src_fd, header.raw, 8);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000024
Glenn L McGrath9c60b292002-11-03 10:57:25 +000025 /* Check the compression method */
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000026 if (header.formatted.method != 8) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000027 bb_error_msg_and_die("Unknown compression method %d",
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000028 header.formatted.method);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000029 }
30
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000031 if (header.formatted.flags & 0x04) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000032 /* bit 2 set: extra field present */
33 unsigned char extra_short;
34
Rob Landley53437472006-07-16 08:14:35 +000035 extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000036 while (extra_short > 0) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000037 /* Ignore extra field */
Rob Landley53437472006-07-16 08:14:35 +000038 xread_char(src_fd);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000039 extra_short--;
40 }
41 }
42
Glenn L McGrath9c60b292002-11-03 10:57:25 +000043 /* Discard original name if any */
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000044 if (header.formatted.flags & 0x08) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000045 /* bit 3 set: original file name present */
Rob Landley53437472006-07-16 08:14:35 +000046 while(xread_char(src_fd) != 0);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000047 }
48
Glenn L McGrath9c60b292002-11-03 10:57:25 +000049 /* Discard file comment if any */
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000050 if (header.formatted.flags & 0x10) {
Glenn L McGrath9c60b292002-11-03 10:57:25 +000051 /* bit 4 set: file comment present */
Rob Landley53437472006-07-16 08:14:35 +000052 while(xread_char(src_fd) != 0);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000053 }
54
Glenn L McGrath9c60b292002-11-03 10:57:25 +000055 /* Read the header checksum */
"Robert P. J. Day"eea56182006-07-20 19:02:24 +000056 if (header.formatted.flags & 0x02) {
Rob Landley53437472006-07-16 08:14:35 +000057 xread_char(src_fd);
58 xread_char(src_fd);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000059 }
60
61 return;
62}