Skip to content

Commit 5c14b0e

Browse files
[AUTO-CHERRYPICK] Fix CVE-2022-0529 and CVE-2022-0530 for unzip: 2.0 - branch main (#11212)
Co-authored-by: KavyaSree2610 <92566732+KavyaSree2610@users.noreply.github.com>
1 parent 5f65efc commit 5c14b0e

6 files changed

Lines changed: 194 additions & 7 deletions

File tree

SPECS/unzip/CVE-2022-0529.patch

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
From 246a2f17066dff57d4a5253de258374a7e99154a Mon Sep 17 00:00:00 2001
2+
From: kavyasree <kkaitepalli@microsoft.com>
3+
Date: Mon, 25 Nov 2024 10:50:21 +0530
4+
Subject: [PATCH] Fix CVE-2022-0529 and CVE-2022-0530
5+
Reference: https://git.launchpad.net/ubuntu/+source/unzip/commit/?h=applied/ubuntu/devel&id=d5d5037f4ca1b40578015085b77ae322d1406f56
6+
---
7+
fileio.c | 34 +++++++++++++++++++++++++---------
8+
process.c | 55 +++++++++++++++++++++++++++++++++++++++++++------------
9+
2 files changed, 68 insertions(+), 21 deletions(-)
10+
11+
diff --git a/fileio.c b/fileio.c
12+
index eb2a115..285f7fe 100644
13+
--- a/fileio.c
14+
+++ b/fileio.c
15+
@@ -171,8 +171,10 @@ static ZCONST char Far ReadError[] = "error: zipfile read error\n";
16+
static ZCONST char Far FilenameTooLongTrunc[] =
17+
"warning: filename too long--truncating.\n";
18+
#ifdef UNICODE_SUPPORT
19+
+ static ZCONST char Far UFilenameCorrupt[] =
20+
+ "error: Unicode filename corrupt.\n";
21+
static ZCONST char Far UFilenameTooLongTrunc[] =
22+
- "warning: Converted unicode filename too long--truncating.\n";
23+
+ "warning: Converted Unicode filename too long--truncating.\n";
24+
#endif
25+
static ZCONST char Far ExtraFieldTooLong[] =
26+
"warning: extra field too long (%d). Ignoring...\n";
27+
@@ -2355,16 +2357,30 @@ int do_string(__G__ length, option) /* return PK-type error code */
28+
/* convert UTF-8 to local character set */
29+
fn = utf8_to_local_string(G.unipath_filename,
30+
G.unicode_escape_all);
31+
- /* make sure filename is short enough */
32+
- if (strlen(fn) >= FILNAMSIZ) {
33+
- fn[FILNAMSIZ - 1] = '\0';
34+
+
35+
+ /* 2022-07-22 SMS, et al. CVE-2022-0530
36+
+ * Detect conversion failure, emit message.
37+
+ * Continue with unconverted name.
38+
+ */
39+
+ if (fn == NULL)
40+
+ {
41+
Info(slide, 0x401, ((char *)slide,
42+
- LoadFarString(UFilenameTooLongTrunc)));
43+
- error = PK_WARN;
44+
+ LoadFarString(UFilenameCorrupt)));
45+
+ error = PK_ERR;
46+
+ }
47+
+ else
48+
+ {
49+
+ /* make sure filename is short enough */
50+
+ if (strlen(fn) >= FILNAMSIZ) {
51+
+ fn[FILNAMSIZ - 1] = '\0';
52+
+ Info(slide, 0x401, ((char *)slide,
53+
+ LoadFarString(UFilenameTooLongTrunc)));
54+
+ error = PK_WARN;
55+
+ }
56+
+ /* replace filename with converted UTF-8 */
57+
+ strcpy(G.filename, fn);
58+
+ free(fn);
59+
}
60+
- /* replace filename with converted UTF-8 */
61+
- strcpy(G.filename, fn);
62+
- free(fn);
63+
}
64+
# endif /* UNICODE_WCHAR */
65+
if (G.unipath_filename != G.filename_full)
66+
diff --git a/process.c b/process.c
67+
index 4e06a35..09d54f7 100644
68+
--- a/process.c
69+
+++ b/process.c
70+
@@ -222,6 +222,8 @@ static ZCONST char Far ZipfileCommTrunc1[] =
71+
"\nwarning: Unicode Path version > 1\n";
72+
static ZCONST char Far UnicodeMismatchError[] =
73+
"\nwarning: Unicode Path checksum invalid\n";
74+
+ static ZCONST char Far UFilenameTooLongTrunc[] =
75+
+ "warning: filename too long (P1) -- truncating.\n";
76+
#endif
77+
78+
79+
@@ -1902,7 +1904,7 @@ int getZip64Data(__G__ ef_buf, ef_len)
80+
Sets both local header and central header fields. Not terribly clever,
81+
but it means that this procedure is only called in one place.
82+
83+
- 2014-12-05 SMS.
84+
+ 2014-12-05 SMS. (oCERT.org report.) CVE-2014-8141.
85+
Added checks to ensure that enough data are available before calling
86+
makeint64() or makelong(). Replaced various sizeof() values with
87+
simple ("4" or "8") constants. (The Zip64 structures do not depend
88+
@@ -1937,8 +1939,7 @@ int getZip64Data(__G__ ef_buf, ef_len)
89+
90+
if (eb_id == EF_PKSZ64)
91+
{
92+
- int offset = EB_HEADSIZE;
93+
-
94+
+ unsigned offset = EB_HEADSIZE;
95+
if ((G.crec.ucsize == Z64FLGL) || (G.lrec.ucsize == Z64FLGL))
96+
{
97+
if (offset+ 8 > ef_len)
98+
@@ -2036,7 +2037,7 @@ int getUnicodeData(__G__ ef_buf, ef_len)
99+
}
100+
if (eb_id == EF_UNIPATH) {
101+
102+
- int offset = EB_HEADSIZE;
103+
+ unsigned offset = EB_HEADSIZE;
104+
ush ULen = eb_len - 5;
105+
ulg chksum = CRCVAL_INITIAL;
106+
107+
@@ -2492,16 +2493,17 @@ char *wide_to_local_string(wide_string, escape_all)
108+
int state_dependent;
109+
int wsize = 0;
110+
int max_bytes = MB_CUR_MAX;
111+
- char buf[9];
112+
+ char buf[ MB_CUR_MAX+ 1]; /* ("+1" not really needed?) */
113+
char *buffer = NULL;
114+
char *local_string = NULL;
115+
+ size_t buffer_size; /* CVE-2022-0529 */
116+
117+
for (wsize = 0; wide_string[wsize]; wsize++) ;
118+
119+
if (max_bytes < MAX_ESCAPE_BYTES)
120+
max_bytes = MAX_ESCAPE_BYTES;
121+
-
122+
- if ((buffer = (char *)malloc(wsize * max_bytes + 1)) == NULL) {
123+
+ buffer_size = wsize * max_bytes + 1; /* Reused below. */
124+
+ if ((buffer = (char *)malloc( buffer_size)) == NULL) {
125+
return NULL;
126+
}
127+
128+
@@ -2539,8 +2541,28 @@ char *wide_to_local_string(wide_string, escape_all)
129+
} else {
130+
/* no MB for this wide */
131+
/* use escape for wide character */
132+
- char *escape_string = wide_to_escape_string(wide_string[i]);
133+
- strcat(buffer, escape_string);
134+
+ size_t buffer_len;
135+
+ size_t escape_string_len;
136+
+ char *escape_string;
137+
+ int err_msg = 0;
138+
+
139+
+ escape_string = wide_to_escape_string(wide_string[i]);
140+
+ buffer_len = strlen( buffer);
141+
+ escape_string_len = strlen( escape_string);
142+
+
143+
+ /* Append escape string, as space allows. */
144+
+ /* 2022-07-18 SMS, et al. CVE-2022-0529 */
145+
+ if (escape_string_len > buffer_size- buffer_len- 1)
146+
+ {
147+
+ escape_string_len = buffer_size- buffer_len- 1;
148+
+ if (err_msg == 0)
149+
+ {
150+
+ err_msg = 1;
151+
+ Info(slide, 0x401, ((char *)slide,
152+
+ LoadFarString( UFilenameTooLongTrunc)));
153+
+ }
154+
+ }
155+
+ strncat( buffer, escape_string, escape_string_len);
156+
free(escape_string);
157+
}
158+
}
159+
@@ -2592,9 +2614,18 @@ char *utf8_to_local_string(utf8_string, escape_all)
160+
ZCONST char *utf8_string;
161+
int escape_all;
162+
{
163+
- zwchar *wide = utf8_to_wide_string(utf8_string);
164+
- char *loc = wide_to_local_string(wide, escape_all);
165+
- free(wide);
166+
+ zwchar *wide;
167+
+ char *loc = NULL;
168+
+
169+
+ wide = utf8_to_wide_string( utf8_string);
170+
+
171+
+ /* 2022-07-25 SMS, et al. CVE-2022-0530 */
172+
+ if (wide != NULL)
173+
+ {
174+
+ loc = wide_to_local_string( wide, escape_all);
175+
+ free( wide);
176+
+ }
177+
+
178+
return loc;
179+
}
180+
181+
--
182+
2.34.1
183+

SPECS/unzip/unzip.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: Unzip-6.0
22
Name: unzip
33
Version: 6.0
4-
Release: 20%{?dist}
4+
Release: 21%{?dist}
55
License: BSD
66
Vendor: Microsoft Corporation
77
Distribution: Mariner
@@ -23,6 +23,7 @@ Patch11: unzip-zipbomb-part3.patch
2323
Patch12: unzip-zipbomb-manpage.patch
2424
Patch13: CVE-2015-7697.patch
2525
Patch14: CVE-2018-1000035.patch
26+
Patch15: CVE-2022-0529.patch
2627

2728
%description
2829
The UnZip package contains ZIP extraction utilities. These are useful
@@ -57,6 +58,9 @@ ln -sf unzip %{buildroot}%{_bindir}/zipinfo
5758
%{_bindir}/*
5859

5960
%changelog
61+
* Mon Nov 25 2024 Kavya Sree Kaitepalli <kkaitepalli@microsoft.com> - 6.0.21
62+
- Fix CVE-2022-0529 and CVE-2022-0530
63+
6064
* Thu Oct 06 2022 Olivia Crain <oliviacrain@microsoft.com> - 6.0-20
6165
- Compile with large file support, zip64 support
6266
- Remove i*86 configuration- Mariner doesn't build for those architectures

toolkit/resources/manifests/package/pkggen_core_aarch64.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ ca-certificates-tools-2.0.0-18.cm2.noarch.rpm
236236
ca-certificates-base-2.0.0-18.cm2.noarch.rpm
237237
ca-certificates-2.0.0-18.cm2.noarch.rpm
238238
dwz-0.14-2.cm2.aarch64.rpm
239-
unzip-6.0-20.cm2.aarch64.rpm
239+
unzip-6.0-21.cm2.aarch64.rpm
240240
python3-3.9.19-7.cm2.aarch64.rpm
241241
python3-devel-3.9.19-7.cm2.aarch64.rpm
242242
python3-libs-3.9.19-7.cm2.aarch64.rpm

toolkit/resources/manifests/package/pkggen_core_x86_64.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ ca-certificates-tools-2.0.0-18.cm2.noarch.rpm
236236
ca-certificates-base-2.0.0-18.cm2.noarch.rpm
237237
ca-certificates-2.0.0-18.cm2.noarch.rpm
238238
dwz-0.14-2.cm2.x86_64.rpm
239-
unzip-6.0-20.cm2.x86_64.rpm
239+
unzip-6.0-21.cm2.x86_64.rpm
240240
python3-3.9.19-7.cm2.x86_64.rpm
241241
python3-devel-3.9.19-7.cm2.x86_64.rpm
242242
python3-libs-3.9.19-7.cm2.x86_64.rpm

toolkit/resources/manifests/package/toolchain_aarch64.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ tdnf-plugin-repogpgcheck-3.5.2-4.cm2.aarch64.rpm
570570
tdnf-python-3.5.2-4.cm2.aarch64.rpm
571571
texinfo-6.8-1.cm2.aarch64.rpm
572572
texinfo-debuginfo-6.8-1.cm2.aarch64.rpm
573-
unzip-6.0-20.cm2.aarch64.rpm
574-
unzip-debuginfo-6.0-20.cm2.aarch64.rpm
573+
unzip-6.0-21.cm2.aarch64.rpm
574+
unzip-debuginfo-6.0-21.cm2.aarch64.rpm
575575
util-linux-2.37.4-9.cm2.aarch64.rpm
576576
util-linux-debuginfo-2.37.4-9.cm2.aarch64.rpm
577577
util-linux-devel-2.37.4-9.cm2.aarch64.rpm

toolkit/resources/manifests/package/toolchain_x86_64.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ tdnf-plugin-repogpgcheck-3.5.2-4.cm2.x86_64.rpm
576576
tdnf-python-3.5.2-4.cm2.x86_64.rpm
577577
texinfo-6.8-1.cm2.x86_64.rpm
578578
texinfo-debuginfo-6.8-1.cm2.x86_64.rpm
579-
unzip-6.0-20.cm2.x86_64.rpm
580-
unzip-debuginfo-6.0-20.cm2.x86_64.rpm
579+
unzip-6.0-21.cm2.x86_64.rpm
580+
unzip-debuginfo-6.0-21.cm2.x86_64.rpm
581581
util-linux-2.37.4-9.cm2.x86_64.rpm
582582
util-linux-debuginfo-2.37.4-9.cm2.x86_64.rpm
583583
util-linux-devel-2.37.4-9.cm2.x86_64.rpm

0 commit comments

Comments
 (0)