Blame SOURCES/unzip-6.0-heap-overflow-infloop.patch

1ed299
From bdd4a0cecd745cb4825e4508b5bdf2579731086a Mon Sep 17 00:00:00 2001
1ed299
From: Petr Stodulka <pstodulk@redhat.com>
1ed299
Date: Mon, 14 Sep 2015 18:23:17 +0200
1ed299
Subject: [PATCH 1/3] upstream fix for heap overflow
1ed299
1ed299
https://bugzilla.redhat.com/attachment.cgi?id=1073002
1ed299
---
1ed299
 crypt.c | 12 +++++++++++-
1ed299
 1 file changed, 11 insertions(+), 1 deletion(-)
1ed299
1ed299
diff --git a/crypt.c b/crypt.c
1ed299
index 784e411..a8975f2 100644
1ed299
--- a/crypt.c
1ed299
+++ b/crypt.c
1ed299
@@ -465,7 +465,17 @@ int decrypt(__G__ passwrd)
1ed299
     GLOBAL(pInfo->encrypted) = FALSE;
1ed299
     defer_leftover_input(__G);
1ed299
     for (n = 0; n < RAND_HEAD_LEN; n++) {
1ed299
-        b = NEXTBYTE;
1ed299
+        /* 2012-11-23 SMS.  (OUSPG report.)
1ed299
+         * Quit early if compressed size < HEAD_LEN.  The resulting
1ed299
+         * error message ("unable to get password") could be improved,
1ed299
+         * but it's better than trying to read nonexistent data, and
1ed299
+         * then continuing with a negative G.csize.  (See
1ed299
+         * fileio.c:readbyte()).
1ed299
+         */
1ed299
+        if ((b = NEXTBYTE) == (ush)EOF)
1ed299
+        {
1ed299
+            return PK_ERR;
1ed299
+        }
1ed299
         h[n] = (uch)b;
1ed299
         Trace((stdout, " (%02x)", h[n]));
1ed299
     }
1ed299
-- 
1ed299
2.4.6
1ed299
1ed299
1ed299
From 4b48844661ff9569f2ecf582a387d46a5775b5d8 Mon Sep 17 00:00:00 2001
1ed299
From: Kamil Dudka <kdudka@redhat.com>
1ed299
Date: Mon, 14 Sep 2015 18:24:56 +0200
1ed299
Subject: [PATCH 2/3] fix infinite loop when extracting empty bzip2 data
1ed299
1ed299
Bug: https://sourceforge.net/p/infozip/patches/23/
1ed299
---
1ed299
 extract.c | 6 ++++++
1ed299
 1 file changed, 6 insertions(+)
1ed299
1ed299
diff --git a/extract.c b/extract.c
1ed299
index 7134bfe..29db027 100644
1ed299
--- a/extract.c
1ed299
+++ b/extract.c
1ed299
@@ -2733,6 +2733,12 @@ __GDEF
1ed299
     int repeated_buf_err;
1ed299
     bz_stream bstrm;
1ed299
 
1ed299
+    if (G.incnt <= 0 && G.csize <= 0L) {
1ed299
+        /* avoid an infinite loop */
1ed299
+        Trace((stderr, "UZbunzip2() got empty input\n"));
1ed299
+        return 2;
1ed299
+    }
1ed299
+
1ed299
 #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
1ed299
     if (G.redirect_slide)
1ed299
         wsize = G.redirect_size, redirSlide = G.redirect_buffer;
1ed299
-- 
1ed299
2.4.6
1ed299
1ed299
1ed299
From bd150334fb4084f5555a6be26b015a0671cb5b74 Mon Sep 17 00:00:00 2001
1ed299
From: Kamil Dudka <kdudka@redhat.com>
1ed299
Date: Tue, 22 Sep 2015 18:52:23 +0200
1ed299
Subject: [PATCH 3/3] extract: prevent unsigned overflow on invalid input
1ed299
1ed299
Suggested-by: Stefan Cornelius
1ed299
---
1ed299
 extract.c | 11 ++++++++++-
1ed299
 1 file changed, 10 insertions(+), 1 deletion(-)
1ed299
1ed299
diff --git a/extract.c b/extract.c
1ed299
index 29db027..b9ae667 100644
1ed299
--- a/extract.c
1ed299
+++ b/extract.c
1ed299
@@ -1257,8 +1257,17 @@ static int extract_or_test_entrylist(__G__ numchunk,
1ed299
         if (G.lrec.compression_method == STORED) {
1ed299
             zusz_t csiz_decrypted = G.lrec.csize;
1ed299
 
1ed299
-            if (G.pInfo->encrypted)
1ed299
+            if (G.pInfo->encrypted) {
1ed299
+                if (csiz_decrypted < 12) {
1ed299
+                    /* handle the error now to prevent unsigned overflow */
1ed299
+                    Info(slide, 0x401, ((char *)slide,
1ed299
+                      LoadFarStringSmall(ErrUnzipNoFile),
1ed299
+                      LoadFarString(InvalidComprData),
1ed299
+                      LoadFarStringSmall2(Inflate)));
1ed299
+                    return PK_ERR;
1ed299
+                }
1ed299
                 csiz_decrypted -= 12;
1ed299
+            }
1ed299
             if (G.lrec.ucsize != csiz_decrypted) {
1ed299
                 Info(slide, 0x401, ((char *)slide,
1ed299
                   LoadFarStringSmall2(WrnStorUCSizCSizDiff),
1ed299
-- 
1ed299
2.5.2
1ed299