wok-stable diff linux/stuff/linux-lzma-2.6.25.5.u @ rev 936

Linux: lzma catch eof
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 20 21:49:23 2008 +0000 (2008-06-20)
parents 9e2bae22918d
children edda77c45d23
line diff
     1.1 --- a/linux/stuff/linux-lzma-2.6.25.5.u	Thu Jun 19 16:54:03 2008 +0000
     1.2 +++ b/linux/stuff/linux-lzma-2.6.25.5.u	Fri Jun 20 21:49:23 2008 +0000
     1.3 @@ -1444,7 +1444,7 @@
     1.4  
     1.5  --- linux-2.6.25.5/lib/decompress_unlzma.c
     1.6  +++ linux-2.6.25.5/lib/decompress_unlzma.c
     1.7 -@@ -0,0 +1,608 @@
     1.8 +@@ -0,0 +1,616 @@
     1.9  +/* Lzma decompressor for Linux kernel. Shamelessly snarfed
    1.10  + * from busybox 1.1.1
    1.11  + *
    1.12 @@ -1571,11 +1571,15 @@
    1.13  +/* Called twice: once at startup and once in rc_normalize() */
    1.14  +static void rc_read(rc_t * rc)
    1.15  +{
    1.16 -+	rc->buffer_size = rc->fill((char*)rc->buffer, LZMA_IOBUF_SIZE);
    1.17 -+	if (rc->buffer_size <= 0)
    1.18 -+		error("unexpected EOF");
    1.19 -+	rc->ptr = rc->buffer;
    1.20 -+	rc->buffer_end = rc->buffer + rc->buffer_size;
    1.21 ++	if (!rc->buffer_size) return;
    1.22 ++	if (rc->fill) {
    1.23 ++		rc->buffer_size = rc->fill((char*)rc->buffer, LZMA_IOBUF_SIZE);
    1.24 ++		rc->ptr = rc->buffer;
    1.25 ++		rc->buffer_end = rc->buffer + rc->buffer_size;
    1.26 ++		if (rc->buffer_size > 0) return;
    1.27 ++	}
    1.28 ++	error("unexpected EOF");
    1.29 ++	rc->buffer_size = 0;
    1.30  +}
    1.31  +
    1.32  +/* Called once */
    1.33 @@ -1797,8 +1801,10 @@
    1.34  +		}
    1.35  +	}
    1.36  +
    1.37 -+	if (header.pos >= (9 * 5 * 5))
    1.38 ++	if (header.pos >= (9 * 5 * 5)) {
    1.39  +		error("bad header");
    1.40 ++		return -1;
    1.41 ++	}
    1.42  +
    1.43  +	mi = header.pos / 9;
    1.44  +	lc = header.pos % 9;
    1.45 @@ -1843,13 +1849,13 @@
    1.46  +				int match_byte;
    1.47  +
    1.48  +				pos = buffer_pos - rep0;
    1.49 -+				if (writebb) {
    1.50 -+					while (pos >= header.dict_size)
    1.51 -+						pos += header.dict_size;
    1.52 -+					if(pos >= bufsize) {
    1.53 -+						goto fail;
    1.54 -+					}
    1.55 ++
    1.56 ++				while (pos >= header.dict_size)
    1.57 ++					pos += header.dict_size;
    1.58 ++				if(pos >= bufsize) {
    1.59 ++					goto fail;
    1.60  +				}
    1.61 ++
    1.62  +				match_byte = buffer[pos];
    1.63  +				do {
    1.64  +					int bit;
    1.65 @@ -1903,15 +1909,16 @@
    1.66  +
    1.67  +						state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
    1.68  +						pos = buffer_pos - rep0;
    1.69 -+						if (writebb) {
    1.70 -+							while (pos >= header.dict_size)
    1.71 -+								pos += header.dict_size;
    1.72 -+							if(pos >= bufsize) {
    1.73 -+								goto fail;
    1.74 -+							}
    1.75 ++
    1.76 ++						while (pos >= header.dict_size)
    1.77 ++							pos += header.dict_size;
    1.78 ++						if(pos >= bufsize) {
    1.79 ++							goto fail;
    1.80  +						}
    1.81 ++
    1.82  +						previous_byte = buffer[pos];
    1.83  +					store_previous_byte:
    1.84 ++						if (!rc.buffer_size) goto eof;
    1.85  +						buffer[buffer_pos++] = previous_byte;
    1.86  +						if (writebb && buffer_pos == header.dict_size) {
    1.87  +							buffer_pos = 0;
    1.88 @@ -2018,15 +2025,16 @@
    1.89  +
    1.90  +			len += LZMA_MATCH_MIN_LEN;
    1.91  +
    1.92 ++			if (!rc.buffer_size) goto eof;
    1.93  +			do {
    1.94  +				pos = buffer_pos - rep0;
    1.95 -+				if (writebb) {
    1.96 -+					while (pos >= header.dict_size)
    1.97 -+						pos += header.dict_size;
    1.98 -+					if(pos >= bufsize) {
    1.99 -+						goto fail;
   1.100 -+					}
   1.101 ++
   1.102 ++				while (pos >= header.dict_size)
   1.103 ++					pos += header.dict_size;
   1.104 ++				if(pos >= bufsize) {
   1.105 ++					goto fail;
   1.106  +				}
   1.107 ++
   1.108  +				previous_byte = buffer[pos];
   1.109  +				buffer[buffer_pos++] = previous_byte;
   1.110  +				if (writebb && buffer_pos == header.dict_size) {
   1.111 @@ -2038,7 +2046,7 @@
   1.112  +			} while (len != 0 && (global_pos + buffer_pos) < header.dst_size);
   1.113  +		}
   1.114  +	}
   1.115 -+
   1.116 ++ eof:
   1.117  +	if (writebb) {
   1.118  +		writebb((char*)buffer, buffer_pos);
   1.119  +		if(posp) {