summaryrefslogtreecommitdiff
path: root/memdisk/unzip.c
diff options
context:
space:
mode:
authorhpa <hpa>2003-11-18 19:20:20 +0000
committerhpa <hpa>2003-11-18 19:20:20 +0000
commit319cfdb6a04d0936385cf8876e373f42d6298be2 (patch)
tree631c570739dd8e744df5c8f4c9d8c5215698e54d /memdisk/unzip.c
parent7aabe805b949c456fde27dee0c020e66c23d7777 (diff)
downloadsyslinux-319cfdb6a04d0936385cf8876e373f42d6298be2.tar.gz
Add debugging code for input buffer underrunsyslinux-2.07-pre6
Diffstat (limited to 'memdisk/unzip.c')
-rw-r--r--memdisk/unzip.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/memdisk/unzip.c b/memdisk/unzip.c
index 94f56e43..a3a7f124 100644
--- a/memdisk/unzip.c
+++ b/memdisk/unzip.c
@@ -28,15 +28,18 @@ typedef uint8_t uch;
typedef uint16_t ush;
typedef uint32_t ulg;
-#define WSIZE 0x8000 /* Window size must be at least 32k, */
+#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
-static uch *inbuf; /* input buffer */
-static uch window[WSIZE]; /* Sliding window buffer */
+static uch *inbuf; /* input pointer */
+static uch window[WSIZE]; /* sliding output window buffer */
-static unsigned insize; /* valid bytes in inbuf */
-static unsigned inptr; /* index of next byte to be processed in inbuf */
-static unsigned outcnt; /* bytes in output buffer */
+static unsigned insize; /* total input bytes read */
+static unsigned inbytes; /* valid bytes in inbuf */
+static unsigned outcnt; /* bytes in output buffer */
+
+/* This is here to try to debug strange errors seen on some machines. */
+static ulg in_crc; /* crc of input bytes as read */
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
@@ -47,8 +50,6 @@ static unsigned outcnt; /* bytes in output buffer */
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
#define RESERVED 0xC0 /* bit 6,7: reserved */
-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
-
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
@@ -71,7 +72,23 @@ static void flush_window(void);
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
-
+
+extern ulg crc_32_tab[256];
+
+/* Get byte from input buffer */
+static inline uch get_byte(void)
+{
+ if ( inbytes ) {
+ uch b = *inbuf++;
+ inbytes--;
+ in_crc = crc_32_tab[(in_crc ^ b) & 0xff] ^ (in_crc >> 8);
+
+ return b;
+ } else {
+ return fill_inbuf(); /* Input buffer underrun */
+ }
+}
+
static ulg bytes_out = 0; /* Number of bytes output */
static uch *output_data; /* Output data pointer */
static ulg output_size; /* Number of output bytes expected */
@@ -123,8 +140,9 @@ static int fill_inbuf(void)
{
/* This should never happen. We have already pointed the algorithm
to all the data we have. */
- error("ran out of input data");
- return 0;
+ printf("failed\nDecompression error: ran out of input data, cksum = %lu %u\n",
+ in_crc^0xffffffffUL, insize);
+ die();
}
/* ===========================================================================
@@ -144,7 +162,7 @@ static void flush_window(void)
out = output_data;
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
- c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
+ c = crc_32_tab[(c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
output_data = out;
@@ -155,7 +173,6 @@ static void flush_window(void)
static void error(char *x)
{
printf("failed\nDecompression error: %s\n", x);
- puts(x);
die();
}
@@ -176,8 +193,9 @@ void *unzip(void *indata, unsigned long zbytes, void *target)
free_mem_end_ptr = free_mem_ptr + 0x10000;
/* Set up input buffer */
+ in_crc = 0xffffffffUL;
inbuf = indata;
- insize = zbytes;
+ insize = inbytes = zbytes;
/* Set up output buffer */
outcnt = 0;