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

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