Blame SOURCES/unzip-6.0-cve-2014-8139.patch

5c40ff
diff --git a/extract.c b/extract.c
5c40ff
index 9ef80b3..c741b5f 100644
5c40ff
--- a/extract.c
5c40ff
+++ b/extract.c
5c40ff
@@ -1,5 +1,5 @@
5c40ff
 /*
5c40ff
-  Copyright (c) 1990-2009 Info-ZIP.  All rights reserved.
5c40ff
+  Copyright (c) 1990-2014 Info-ZIP.  All rights reserved.
5c40ff
 
5c40ff
   See the accompanying file LICENSE, version 2009-Jan-02 or later
5c40ff
   (the contents of which are also included in unzip.h) for terms of use.
5c40ff
@@ -298,6 +298,8 @@ char ZCONST Far TruncNTSD[] =
5c40ff
 #ifndef SFX
5c40ff
    static ZCONST char Far InconsistEFlength[] = "bad extra-field entry:\n \
5c40ff
      EF block length (%u bytes) exceeds remaining EF data (%u bytes)\n";
5c40ff
+   static ZCONST char Far TooSmallEBlength[] = "bad extra-field entry:\n \
5c40ff
+     EF block length (%u bytes) invalid (< %d)\n";
5c40ff
    static ZCONST char Far InvalidComprDataEAs[] =
5c40ff
      " invalid compressed data for EAs\n";
5c40ff
 #  if (defined(WIN32) && defined(NTSD_EAS))
5c40ff
@@ -2020,7 +2022,8 @@ static int TestExtraField(__G__ ef, ef_len)
5c40ff
         ebID = makeword(ef);
5c40ff
         ebLen = (unsigned)makeword(ef+EB_LEN);
5c40ff
 
5c40ff
-        if (ebLen > (ef_len - EB_HEADSIZE)) {
5c40ff
+        if (ebLen > (ef_len - EB_HEADSIZE))
5c40ff
+        {
5c40ff
            /* Discovered some extra field inconsistency! */
5c40ff
             if (uO.qflag)
5c40ff
                 Info(slide, 1, ((char *)slide, "%-22s ",
5c40ff
@@ -2155,11 +2158,29 @@ static int TestExtraField(__G__ ef, ef_len)
5c40ff
                 }
5c40ff
                 break;
5c40ff
             case EF_PKVMS:
5c40ff
-                if (makelong(ef+EB_HEADSIZE) !=
5c40ff
-                    crc32(CRCVAL_INITIAL, ef+(EB_HEADSIZE+4),
5c40ff
-                          (extent)(ebLen-4)))
5c40ff
-                    Info(slide, 1, ((char *)slide,
5c40ff
-                      LoadFarString(BadCRC_EAs)));
5c40ff
+                /* 2015-01-30 SMS.  Added sufficient-bytes test/message
5c40ff
+                 * here.  (Removed defective ebLen test above.)
5c40ff
+                 *
5c40ff
+                 * If sufficient bytes (EB_PKVMS_MINLEN) are available,
5c40ff
+                 * then compare the stored CRC value with the calculated
5c40ff
+                 * CRC for the remainder of the data (and complain about
5c40ff
+                 * a mismatch).
5c40ff
+                 */
5c40ff
+                if (ebLen < EB_PKVMS_MINLEN)
5c40ff
+                {
5c40ff
+                    /* Insufficient bytes available. */
5c40ff
+                    Info( slide, 1,
5c40ff
+                     ((char *)slide, LoadFarString( TooSmallEBlength),
5c40ff
+                     ebLen, EB_PKVMS_MINLEN));
5c40ff
+                }
5c40ff
+                else if (makelong(ef+ EB_HEADSIZE) !=
5c40ff
+                 crc32(CRCVAL_INITIAL,
5c40ff
+                 (ef+ EB_HEADSIZE+ EB_PKVMS_MINLEN),
5c40ff
+                 (extent)(ebLen- EB_PKVMS_MINLEN)))
5c40ff
+                {
5c40ff
+                     Info(slide, 1, ((char *)slide,
5c40ff
+                       LoadFarString(BadCRC_EAs)));
5c40ff
+                }
5c40ff
                 break;
5c40ff
             case EF_PKW32:
5c40ff
             case EF_PKUNIX:
5c40ff
diff --git a/unzpriv.h b/unzpriv.h
5c40ff
index 005cee0..5c83a6e 100644
5c40ff
--- a/unzpriv.h
5c40ff
+++ b/unzpriv.h
5c40ff
@@ -1806,6 +1806,8 @@
5c40ff
 #define EB_NTSD_VERSION   4    /* offset of NTSD version byte */
5c40ff
 #define EB_NTSD_MAX_VER   (0)  /* maximum version # we know how to handle */
5c40ff
 
5c40ff
+#define EB_PKVMS_MINLEN   4    /* minimum data length of PKVMS extra block */
5c40ff
+
5c40ff
 #define EB_ASI_CRC32      0    /* offset of ASI Unix field's crc32 checksum */
5c40ff
 #define EB_ASI_MODE       4    /* offset of ASI Unix permission mode field */
5c40ff
 
5c40ff