blob: 215e8293fefad3b75cec3b15fe1069852c4f3ce1 [file] [log] [blame]
Glenn L McGrath7ca04f32002-09-25 02:47:48 +00001/* vi: set sw=4 ts=4: */
2/*
3 * busybox gunzip trailing header handler
4 * Copyright Glenn McGrath 2002
5 *
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.
10 *
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.
15 *
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.
19 */
20
21
22#include <sys/types.h>
23#include <sys/wait.h>
24#include <signal.h>
25#include <stdlib.h>
26#include <string.h>
27#include <unistd.h>
28#include <fcntl.h>
29#include "config.h"
30#include "busybox.h"
31#include "unarchive.h"
32
33extern unsigned int gunzip_crc;
34extern unsigned int gunzip_bytes_out;
35extern unsigned char *gunzip_in_buffer;
36extern unsigned char gunzip_in_buffer_count;
37
38extern void check_trailer_gzip(int src_fd)
39{
40
41 unsigned int stored_crc = 0;
42 unsigned char count;
43
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));
48 }
49
50 /* Validate decompression - crc */
51 if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
52 error_msg("invalid compressed data--crc error");
53 }
54
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("invalid compressed data--length error");
60 }
61
62}