1 /* vi: set sw=4 ts=4: */
3 * busybox gunzip trailing header handler
4 * Copyright Glenn McGrath 2002
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <sys/types.h>
31 #include "unarchive.h"
33 extern unsigned int gunzip_crc;
34 extern unsigned int gunzip_bytes_out;
35 extern unsigned char *gunzip_in_buffer;
36 extern unsigned char gunzip_in_buffer_count;
38 extern void check_trailer_gzip(int src_fd)
41 unsigned int stored_crc = 0;
44 /* top up the input buffer with the rest of the trailer */
45 xread_all(src_fd, &gunzip_in_buffer[gunzip_in_buffer_count], 8 - gunzip_in_buffer_count);
46 for (count = 0; count != 4; count++) {
47 stored_crc |= (gunzip_in_buffer[count] << (count * 8));
50 /* Validate decompression - crc */
51 if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
52 error_msg_and_die("invalid compressed data--crc error");
55 /* Validate decompression - size */
56 if (gunzip_bytes_out !=
57 (gunzip_in_buffer[4] | (gunzip_in_buffer[5] << 8) |
58 (gunzip_in_buffer[6] << 16) | (gunzip_in_buffer[7] << 24))) {
59 error_msg_and_die("invalid compressed data--length error");