cnd / rpms / gzip

Forked from rpms/gzip 3 years ago
Clone

Blame SOURCES/gzip-1.3.13-cve-2006-4337.patch

fb7e20
--- gzip-1.3.9/unlzh.c.4337	2007-01-15 16:31:53.000000000 +0100
fb7e20
+++ gzip-1.3.9/unlzh.c	2007-01-15 16:38:08.000000000 +0100
fb7e20
@@ -146,8 +146,8 @@
fb7e20
     start[1] = 0;
fb7e20
     for (i = 1; i <= 16; i++)
fb7e20
         start[i + 1] = start[i] + (count[i] << (16 - i));
fb7e20
-    if ((start[17] & 0xffff) != 0)
fb7e20
-      gzip_error ("Bad table\n");
fb7e20
+   if ((start[17] & 0xffff) != 0 || tablebits > 16) /* 16 for weight below */
fb7e20
+      gzip_error ("Bad table (case b)\n"); 
fb7e20
 
fb7e20
     jutbits = 16 - tablebits;
fb7e20
     for (i = 1; i <= (unsigned)tablebits; i++) {
fb7e20
@@ -161,15 +162,15 @@
fb7e20
 
fb7e20
     i = start[tablebits + 1] >> jutbits;
fb7e20
     if (i != 0) {
fb7e20
-        k = 1 << tablebits;
fb7e20
-        while (i != k) table[i++] = 0;
fb7e20
+        k = MIN(1 << tablebits, DIST_BUFSIZE);
fb7e20
+        while (i < k) table[i++] = 0;
fb7e20
     }
fb7e20
 
fb7e20
     avail = nchar;
fb7e20
     mask = (unsigned) 1 << (15 - tablebits);
fb7e20
     for (ch = 0; ch < (unsigned)nchar; ch++) {
fb7e20
         if ((len = bitlen[ch]) == 0) continue;
fb7e20
-        nextcode = start[len] + weight[len];
fb7e20
+        nextcode = MIN(start[len] + weight[len], DIST_BUFSIZE);
fb7e20
         if (len <= (unsigned)tablebits) {
fb7e20
             if ((unsigned) 1 << tablebits < nextcode)
fb7e20
               gzip_error ("Bad table\n");
fb7e20
@@ -212,7 +213,7 @@
fb7e20
         for (i = 0; i < 256; i++) pt_table[i] = c;
fb7e20
     } else {
fb7e20
         i = 0;
fb7e20
-        while (i < n) {
fb7e20
+        while (i < MIN(n,NPT)) {
fb7e20
             c = bitbuf >> (BITBUFSIZ - 3);
fb7e20
             if (c == 7) {
fb7e20
                 mask = (unsigned) 1 << (BITBUFSIZ - 1 - 3);
fb7e20
@@ -224,7 +225,7 @@
fb7e20
             pt_len[i++] = c;
fb7e20
             if (i == i_special) {
fb7e20
                 c = getbits(2);
fb7e20
-                while (--c >= 0) pt_len[i++] = 0;
fb7e20
+                while (--c >= 0 && i < NPT) pt_len[i++] = 0; 
fb7e20
             }
fb7e20
         }
fb7e20
         while (i < nn) pt_len[i++] = 0;
fb7e20
@@ -244,7 +245,7 @@
fb7e20
         for (i = 0; i < 4096; i++) c_table[i] = c;
fb7e20
     } else {
fb7e20
         i = 0;
fb7e20
-        while (i < n) {
fb7e20
+        while (i < MIN(n,NC)) { 
fb7e20
             c = pt_table[bitbuf >> (BITBUFSIZ - 8)];
fb7e20
             if (c >= NT) {
fb7e20
                 mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
fb7e20
@@ -259,7 +260,7 @@
fb7e20
                 if      (c == 0) c = 1;
fb7e20
                 else if (c == 1) c = getbits(4) + 3;
fb7e20
                 else             c = getbits(CBIT) + 20;
fb7e20
-                while (--c >= 0) c_len[i++] = 0;
fb7e20
+                while (--c >= 0 && i < NC) c_len[i++] = 0; 
fb7e20
             } else c_len[i++] = c - 2;
fb7e20
         }
fb7e20
         while (i < NC) c_len[i++] = 0;
fb7e20
@@ -352,7 +353,7 @@
fb7e20
     while (--j >= 0) {
fb7e20
         buffer[r] = buffer[i];
fb7e20
         i = (i + 1) & (DICSIZ - 1);
fb7e20
-        if (++r == count) return r;
fb7e20
+        if (++r >= count) return r;
fb7e20
     }
fb7e20
     for ( ; ; ) {
fb7e20
         c = decode_c();
fb7e20
@@ -362,14 +363,14 @@
fb7e20
         }
fb7e20
         if (c <= UCHAR_MAX) {
fb7e20
             buffer[r] = c;
fb7e20
-            if (++r == count) return r;
fb7e20
+            if (++r >= count) return r;
fb7e20
         } else {
fb7e20
             j = c - (UCHAR_MAX + 1 - THRESHOLD);
fb7e20
             i = (r - decode_p() - 1) & (DICSIZ - 1);
fb7e20
             while (--j >= 0) {
fb7e20
                 buffer[r] = buffer[i];
fb7e20
                 i = (i + 1) & (DICSIZ - 1);
fb7e20
-                if (++r == count) return r;
fb7e20
+                if (++r >= count) return r;
fb7e20
             }
fb7e20
         }
fb7e20
     }
fb7e20
--- gzip-1.3.9/gzip.h.4337	2007-01-15 16:31:53.000000000 +0100
fb7e20
+++ gzip-1.3.9/gzip.h	2007-01-15 16:38:52.000000000 +0100
fb7e20
@@ -224,6 +224,8 @@
fb7e20
 #define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
fb7e20
 #define try_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
fb7e20
 
fb7e20
+#define MIN(a,b) ((a) <= (b) ? (a) : (b)) 
fb7e20
+
fb7e20
 /* put_byte is used for the compressed output, put_ubyte for the
fb7e20
  * uncompressed output. However unlzw() uses window for its
fb7e20
  * suffix table instead of its output buffer, so it does not use put_ubyte
fb7e20
--- gzip-1.3.9/unpack.c.4337	2007-01-15 16:31:53.000000000 +0100
fb7e20
+++ gzip-1.3.9/unpack.c	2007-01-15 16:39:12.000000000 +0100
fb7e20
@@ -21,9 +21,6 @@
fb7e20
 #include "tailor.h"
fb7e20
 #include "gzip.h"
fb7e20
 
fb7e20
-#define MIN(a,b) ((a) <= (b) ? (a) : (b))
fb7e20
-/* The arguments must not have side effects. */
fb7e20
-
fb7e20
 #define MAX_BITLEN 25
fb7e20
 /* Maximum length of Huffman codes. (Minor modifications to the code
fb7e20
  * would be needed to support 32 bits codes, but pack never generates
fb7e20