gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / unzip-zipbomb-part3.patch
1 From 6d351831be705cc26d897db44f878a978f4138fc Mon Sep 17 00:00:00 2001
2 From: Mark Adler <madler@alumni.caltech.edu>
3 Date: Thu, 25 Jul 2019 20:43:17 -0700
4 Subject: [PATCH] Do not raise a zip bomb alert for a misplaced central
5 directory.
6
7 There is a zip-like file in the Firefox distribution, omni.ja,
8 which is a zip container with the central directory placed at the
9 start of the file instead of after the local entries as required
10 by the zip standard. This commit marks the actual location of the
11 central directory, as well as the end of central directory records,
12 as disallowed locations. This now permits such containers to not
13 raise a zip bomb alert, where in fact there are no overlaps.
14 ---
15 extract.c | 25 +++++++++++++++++++------
16 process.c | 6 ++++++
17 unzpriv.h | 10 ++++++++++
18 3 files changed, 35 insertions(+), 6 deletions(-)
19
20 diff --git a/extract.c b/extract.c
21 index 0973a33..1b73cb0 100644
22 --- a/extract.c
23 +++ b/extract.c
24 @@ -493,8 +493,11 @@ int extract_or_test_files(__G) /* return PK-type error code */
25 }
26 #endif /* !SFX || SFX_EXDIR */
27
28 - /* One more: initialize cover structure for bomb detection. Start with a
29 - span that covers the central directory though the end of the file. */
30 + /* One more: initialize cover structure for bomb detection. Start with
31 + spans that cover any extra bytes at the start, the central directory,
32 + the end of central directory record (including the Zip64 end of central
33 + directory locator, if present), and the Zip64 end of central directory
34 + record, if present. */
35 if (G.cover == NULL) {
36 G.cover = malloc(sizeof(cover_t));
37 if (G.cover == NULL) {
38 @@ -506,15 +509,25 @@ int extract_or_test_files(__G) /* return PK-type error code */
39 ((cover_t *)G.cover)->max = 0;
40 }
41 ((cover_t *)G.cover)->num = 0;
42 - if ((G.extra_bytes != 0 &&
43 - cover_add((cover_t *)G.cover, 0, G.extra_bytes) != 0) ||
44 - cover_add((cover_t *)G.cover,
45 + if (cover_add((cover_t *)G.cover,
46 G.extra_bytes + G.ecrec.offset_start_central_directory,
47 - G.ziplen) != 0) {
48 + G.extra_bytes + G.ecrec.offset_start_central_directory +
49 + G.ecrec.size_central_directory) != 0) {
50 Info(slide, 0x401, ((char *)slide,
51 LoadFarString(NotEnoughMemCover)));
52 return PK_MEM;
53 }
54 + if ((G.extra_bytes != 0 &&
55 + cover_add((cover_t *)G.cover, 0, G.extra_bytes) != 0) ||
56 + (G.ecrec.have_ecr64 &&
57 + cover_add((cover_t *)G.cover, G.ecrec.ec64_start,
58 + G.ecrec.ec64_end) != 0) ||
59 + cover_add((cover_t *)G.cover, G.ecrec.ec_start,
60 + G.ecrec.ec_end) != 0) {
61 + Info(slide, 0x401, ((char *)slide,
62 + LoadFarString(OverlappedComponents)));
63 + return PK_BOMB;
64 + }
65
66 /*---------------------------------------------------------------------------
67 The basic idea of this function is as follows. Since the central di-
68 diff --git a/process.c b/process.c
69 index d2e4dc3..d75d405 100644
70 --- a/process.c
71 +++ b/process.c
72 @@ -1408,6 +1408,10 @@ static int find_ecrec64(__G__ searchlen) /* return PK-class error */
73
74 /* Now, we are (almost) sure that we have a Zip64 archive. */
75 G.ecrec.have_ecr64 = 1;
76 + G.ecrec.ec_start -= ECLOC64_SIZE+4;
77 + G.ecrec.ec64_start = ecrec64_start_offset;
78 + G.ecrec.ec64_end = ecrec64_start_offset +
79 + 12 + makeint64(&byterec[ECREC64_LENGTH]);
80
81 /* Update the "end-of-central-dir offset" for later checks. */
82 G.real_ecrec_offset = ecrec64_start_offset;
83 @@ -1542,6 +1546,8 @@ static int find_ecrec(__G__ searchlen) /* return PK-class error */
84 makelong(&byterec[OFFSET_START_CENTRAL_DIRECTORY]);
85 G.ecrec.zipfile_comment_length =
86 makeword(&byterec[ZIPFILE_COMMENT_LENGTH]);
87 + G.ecrec.ec_start = G.real_ecrec_offset;
88 + G.ecrec.ec_end = G.ecrec.ec_start + 22 + G.ecrec.zipfile_comment_length;
89
90 /* Now, we have to read the archive comment, BEFORE the file pointer
91 is moved away backwards to seek for a Zip64 ECLOC64 structure.
92 diff --git a/unzpriv.h b/unzpriv.h
93 index dc9eff5..297b3c7 100644
94 --- a/unzpriv.h
95 +++ b/unzpriv.h
96 @@ -2185,6 +2185,16 @@ typedef struct VMStimbuf {
97 int have_ecr64; /* valid Zip64 ecdir-record exists */
98 int is_zip64_archive; /* Zip64 ecdir-record is mandatory */
99 ush zipfile_comment_length;
100 + zusz_t ec_start, ec_end; /* offsets of start and end of the
101 + end of central directory record,
102 + including if present the Zip64
103 + end of central directory locator,
104 + which immediately precedes the
105 + end of central directory record */
106 + zusz_t ec64_start, ec64_end; /* if have_ecr64 is true, then these
107 + are the offsets of the start and
108 + end of the Zip64 end of central
109 + directory record */
110 } ecdir_rec;
111
112