From 7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Wed, 25 Sep 2002 02:47:48 +0000 Subject: New common unarchive code. --- archival/libunarchive/check_trailer_gzip.c | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 archival/libunarchive/check_trailer_gzip.c (limited to 'archival/libunarchive/check_trailer_gzip.c') diff --git a/archival/libunarchive/check_trailer_gzip.c b/archival/libunarchive/check_trailer_gzip.c new file mode 100644 index 000000000..215e8293f --- /dev/null +++ b/archival/libunarchive/check_trailer_gzip.c @@ -0,0 +1,62 @@ +/* vi: set sw=4 ts=4: */ +/* + * busybox gunzip trailing header handler + * Copyright Glenn McGrath 2002 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "busybox.h" +#include "unarchive.h" + +extern unsigned int gunzip_crc; +extern unsigned int gunzip_bytes_out; +extern unsigned char *gunzip_in_buffer; +extern unsigned char gunzip_in_buffer_count; + +extern void check_trailer_gzip(int src_fd) +{ + + unsigned int stored_crc = 0; + unsigned char count; + + /* top up the input buffer with the rest of the trailer */ + xread_all(src_fd, &gunzip_in_buffer[gunzip_in_buffer_count], 8 - gunzip_in_buffer_count); + for (count = 0; count != 4; count++) { + stored_crc |= (gunzip_in_buffer[count] << (count * 8)); + } + + /* Validate decompression - crc */ + if (stored_crc != (gunzip_crc ^ 0xffffffffL)) { + error_msg("invalid compressed data--crc error"); + } + + /* Validate decompression - size */ + if (gunzip_bytes_out != + (gunzip_in_buffer[4] | (gunzip_in_buffer[5] << 8) | + (gunzip_in_buffer[6] << 16) | (gunzip_in_buffer[7] << 24))) { + error_msg("invalid compressed data--length error"); + } + +} -- cgit v1.2.3