Gentoo Archives: gentoo-commits

From: Matt Thode <prometheanfire@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-arch/p7zip/files/, app-arch/p7zip/
Date: Wed, 07 Feb 2018 19:41:17
Message-Id: 1518032461.b684427f2fbb85f3f5f895f7794b81d6f83a4bea.prometheanfire@gentoo
1 commit: b684427f2fbb85f3f5f895f7794b81d6f83a4bea
2 Author: Matthew Thode <prometheanfire <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 7 19:40:40 2018 +0000
4 Commit: Matt Thode <prometheanfire <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 7 19:41:01 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b684427f
7
8 app-arch/p7zip: for CVE-2017-17969, CVE-2018-5996
9
10 Bug: https://bugs.gentoo.org/645500
11 Package-Manager: Portage-2.3.19, Repoman-2.3.6
12
13 app-arch/p7zip/files/CVE-2017-17969.patch | 26 ++++
14 app-arch/p7zip/files/CVE-2018-5996.patch | 221 ++++++++++++++++++++++++++++++
15 app-arch/p7zip/p7zip-16.02-r2.ebuild | 163 ++++++++++++++++++++++
16 3 files changed, 410 insertions(+)
17
18 diff --git a/app-arch/p7zip/files/CVE-2017-17969.patch b/app-arch/p7zip/files/CVE-2017-17969.patch
19 new file mode 100644
20 index 00000000000..9a820af7306
21 --- /dev/null
22 +++ b/app-arch/p7zip/files/CVE-2017-17969.patch
23 @@ -0,0 +1,26 @@
24 +From: =?utf-8?q?Antoine_Beaupr=C3=A9?= <anarcat@××××××.org>
25 +Date: Sun, 28 Jan 2018 21:19:50 +0100
26 +Subject: backport of the CVE-2017-17969 fix from 7zip 18.00-beta
27 +
28 +---
29 + CPP/7zip/Compress/ShrinkDecoder.cpp | 7 ++++++-
30 + 1 file changed, 6 insertions(+), 1 deletion(-)
31 +
32 +diff --git a/CPP/7zip/Compress/ShrinkDecoder.cpp b/CPP/7zip/Compress/ShrinkDecoder.cpp
33 +index 80b7e67..4acdce5 100644
34 +--- a/CPP/7zip/Compress/ShrinkDecoder.cpp
35 ++++ b/CPP/7zip/Compress/ShrinkDecoder.cpp
36 +@@ -121,7 +121,12 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *
37 + {
38 + _stack[i++] = _suffixes[cur];
39 + cur = _parents[cur];
40 +- }
41 ++ if (i >= kNumItems)
42 ++ break;
43 ++ }
44 ++
45 ++ if (i >= kNumItems)
46 ++ break;
47 +
48 + _stack[i++] = (Byte)cur;
49 + lastChar2 = (Byte)cur;
50
51 diff --git a/app-arch/p7zip/files/CVE-2018-5996.patch b/app-arch/p7zip/files/CVE-2018-5996.patch
52 new file mode 100644
53 index 00000000000..6733bff9189
54 --- /dev/null
55 +++ b/app-arch/p7zip/files/CVE-2018-5996.patch
56 @@ -0,0 +1,221 @@
57 +From: Robert Luberda <robert@××××××.org>
58 +Date: Sun, 28 Jan 2018 23:47:40 +0100
59 +Subject: CVE-2018-5996
60 +
61 +Hopefully fix Memory Corruptions via RAR PPMd (CVE-2018-5996) by
62 +applying a few changes from 7Zip 18.00-beta.
63 +
64 +Bug-Debian: https://bugs.debian.org/#888314
65 +---
66 + CPP/7zip/Compress/Rar1Decoder.cpp | 13 +++++++++----
67 + CPP/7zip/Compress/Rar1Decoder.h | 1 +
68 + CPP/7zip/Compress/Rar2Decoder.cpp | 10 +++++++++-
69 + CPP/7zip/Compress/Rar2Decoder.h | 1 +
70 + CPP/7zip/Compress/Rar3Decoder.cpp | 23 ++++++++++++++++++++---
71 + CPP/7zip/Compress/Rar3Decoder.h | 2 ++
72 + 6 files changed, 42 insertions(+), 8 deletions(-)
73 +
74 +diff --git a/CPP/7zip/Compress/Rar1Decoder.cpp b/CPP/7zip/Compress/Rar1Decoder.cpp
75 +index 1aaedcc..68030c7 100644
76 +--- a/CPP/7zip/Compress/Rar1Decoder.cpp
77 ++++ b/CPP/7zip/Compress/Rar1Decoder.cpp
78 +@@ -29,7 +29,7 @@ public:
79 + };
80 + */
81 +
82 +-CDecoder::CDecoder(): m_IsSolid(false) { }
83 ++CDecoder::CDecoder(): m_IsSolid(false), _errorMode(false) { }
84 +
85 + void CDecoder::InitStructures()
86 + {
87 +@@ -406,9 +406,14 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *
88 + InitData();
89 + if (!m_IsSolid)
90 + {
91 ++ _errorMode = false;
92 + InitStructures();
93 + InitHuff();
94 + }
95 ++
96 ++ if (_errorMode)
97 ++ return S_FALSE;
98 ++
99 + if (m_UnpackSize > 0)
100 + {
101 + GetFlagsBuf();
102 +@@ -477,9 +482,9 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
103 + const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
104 + {
105 + try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
106 +- catch(const CInBufferException &e) { return e.ErrorCode; }
107 +- catch(const CLzOutWindowException &e) { return e.ErrorCode; }
108 +- catch(...) { return S_FALSE; }
109 ++ catch(const CInBufferException &e) { _errorMode = true; return e.ErrorCode; }
110 ++ catch(const CLzOutWindowException &e) { _errorMode = true; return e.ErrorCode; }
111 ++ catch(...) { _errorMode = true; return S_FALSE; }
112 + }
113 +
114 + STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
115 +diff --git a/CPP/7zip/Compress/Rar1Decoder.h b/CPP/7zip/Compress/Rar1Decoder.h
116 +index 630f089..01b606b 100644
117 +--- a/CPP/7zip/Compress/Rar1Decoder.h
118 ++++ b/CPP/7zip/Compress/Rar1Decoder.h
119 +@@ -39,6 +39,7 @@ public:
120 +
121 + Int64 m_UnpackSize;
122 + bool m_IsSolid;
123 ++ bool _errorMode;
124 +
125 + UInt32 ReadBits(int numBits);
126 + HRESULT CopyBlock(UInt32 distance, UInt32 len);
127 +diff --git a/CPP/7zip/Compress/Rar2Decoder.cpp b/CPP/7zip/Compress/Rar2Decoder.cpp
128 +index b3f2b4b..0580c8d 100644
129 +--- a/CPP/7zip/Compress/Rar2Decoder.cpp
130 ++++ b/CPP/7zip/Compress/Rar2Decoder.cpp
131 +@@ -80,7 +80,8 @@ static const UInt32 kHistorySize = 1 << 20;
132 + static const UInt32 kWindowReservSize = (1 << 22) + 256;
133 +
134 + CDecoder::CDecoder():
135 +- m_IsSolid(false)
136 ++ m_IsSolid(false),
137 ++ m_TablesOK(false)
138 + {
139 + }
140 +
141 +@@ -100,6 +101,8 @@ UInt32 CDecoder::ReadBits(unsigned numBits) { return m_InBitStream.ReadBits(numB
142 +
143 + bool CDecoder::ReadTables(void)
144 + {
145 ++ m_TablesOK = false;
146 ++
147 + Byte levelLevels[kLevelTableSize];
148 + Byte newLevels[kMaxTableSize];
149 + m_AudioMode = (ReadBits(1) == 1);
150 +@@ -170,6 +173,8 @@ bool CDecoder::ReadTables(void)
151 + }
152 +
153 + memcpy(m_LastLevels, newLevels, kMaxTableSize);
154 ++ m_TablesOK = true;
155 ++
156 + return true;
157 + }
158 +
159 +@@ -344,6 +349,9 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *
160 + return S_FALSE;
161 + }
162 +
163 ++ if (!m_TablesOK)
164 ++ return S_FALSE;
165 ++
166 + UInt64 startPos = m_OutWindowStream.GetProcessedSize();
167 + while (pos < unPackSize)
168 + {
169 +diff --git a/CPP/7zip/Compress/Rar2Decoder.h b/CPP/7zip/Compress/Rar2Decoder.h
170 +index 3a0535c..0e9005f 100644
171 +--- a/CPP/7zip/Compress/Rar2Decoder.h
172 ++++ b/CPP/7zip/Compress/Rar2Decoder.h
173 +@@ -139,6 +139,7 @@ class CDecoder :
174 +
175 + UInt64 m_PackSize;
176 + bool m_IsSolid;
177 ++ bool m_TablesOK;
178 +
179 + void InitStructures();
180 + UInt32 ReadBits(unsigned numBits);
181 +diff --git a/CPP/7zip/Compress/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar3Decoder.cpp
182 +index 3bf2513..6cb8a6a 100644
183 +--- a/CPP/7zip/Compress/Rar3Decoder.cpp
184 ++++ b/CPP/7zip/Compress/Rar3Decoder.cpp
185 +@@ -92,7 +92,8 @@ CDecoder::CDecoder():
186 + _writtenFileSize(0),
187 + _vmData(0),
188 + _vmCode(0),
189 +- m_IsSolid(false)
190 ++ m_IsSolid(false),
191 ++ _errorMode(false)
192 + {
193 + Ppmd7_Construct(&_ppmd);
194 + }
195 +@@ -545,6 +546,9 @@ HRESULT CDecoder::ReadTables(bool &keepDecompressing)
196 + return InitPPM();
197 + }
198 +
199 ++ TablesRead = false;
200 ++ TablesOK = false;
201 ++
202 + _lzMode = true;
203 + PrevAlignBits = 0;
204 + PrevAlignCount = 0;
205 +@@ -606,6 +610,9 @@ HRESULT CDecoder::ReadTables(bool &keepDecompressing)
206 + }
207 + }
208 + }
209 ++ if (InputEofError())
210 ++ return S_FALSE;
211 ++
212 + TablesRead = true;
213 +
214 + // original code has check here:
215 +@@ -623,6 +630,9 @@ HRESULT CDecoder::ReadTables(bool &keepDecompressing)
216 + RIF(m_LenDecoder.Build(&newLevels[kMainTableSize + kDistTableSize + kAlignTableSize]));
217 +
218 + memcpy(m_LastLevels, newLevels, kTablesSizesSum);
219 ++
220 ++ TablesOK = true;
221 ++
222 + return S_OK;
223 + }
224 +
225 +@@ -824,7 +834,12 @@ HRESULT CDecoder::CodeReal(ICompressProgressInfo *progress)
226 + PpmEscChar = 2;
227 + PpmError = true;
228 + InitFilters();
229 ++ _errorMode = false;
230 + }
231 ++
232 ++ if (_errorMode)
233 ++ return S_FALSE;
234 ++
235 + if (!m_IsSolid || !TablesRead)
236 + {
237 + bool keepDecompressing;
238 +@@ -838,6 +853,8 @@ HRESULT CDecoder::CodeReal(ICompressProgressInfo *progress)
239 + bool keepDecompressing;
240 + if (_lzMode)
241 + {
242 ++ if (!TablesOK)
243 ++ return S_FALSE;
244 + RINOK(DecodeLZ(keepDecompressing))
245 + }
246 + else
247 +@@ -901,8 +918,8 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
248 + _unpackSize = outSize ? *outSize : (UInt64)(Int64)-1;
249 + return CodeReal(progress);
250 + }
251 +- catch(const CInBufferException &e) { return e.ErrorCode; }
252 +- catch(...) { return S_FALSE; }
253 ++ catch(const CInBufferException &e) { _errorMode = true; return e.ErrorCode; }
254 ++ catch(...) { _errorMode = true; return S_FALSE; }
255 + // CNewException is possible here. But probably CNewException is caused
256 + // by error in data stream.
257 + }
258 +diff --git a/CPP/7zip/Compress/Rar3Decoder.h b/CPP/7zip/Compress/Rar3Decoder.h
259 +index c130cec..2f72d7d 100644
260 +--- a/CPP/7zip/Compress/Rar3Decoder.h
261 ++++ b/CPP/7zip/Compress/Rar3Decoder.h
262 +@@ -192,6 +192,7 @@ class CDecoder:
263 + UInt32 _lastFilter;
264 +
265 + bool m_IsSolid;
266 ++ bool _errorMode;
267 +
268 + bool _lzMode;
269 + bool _unsupportedFilter;
270 +@@ -200,6 +201,7 @@ class CDecoder:
271 + UInt32 PrevAlignCount;
272 +
273 + bool TablesRead;
274 ++ bool TablesOK;
275 +
276 + CPpmd7 _ppmd;
277 + int PpmEscChar;
278
279 diff --git a/app-arch/p7zip/p7zip-16.02-r2.ebuild b/app-arch/p7zip/p7zip-16.02-r2.ebuild
280 new file mode 100644
281 index 00000000000..4bcce404532
282 --- /dev/null
283 +++ b/app-arch/p7zip/p7zip-16.02-r2.ebuild
284 @@ -0,0 +1,163 @@
285 +# Copyright 1999-2018 Gentoo Foundation
286 +# Distributed under the terms of the GNU General Public License v2
287 +
288 +EAPI=6
289 +
290 +WX_GTK_VER="3.0"
291 +
292 +inherit toolchain-funcs wxwidgets
293 +
294 +DESCRIPTION="Port of 7-Zip archiver for Unix"
295 +HOMEPAGE="http://p7zip.sourceforge.net/"
296 +SRC_URI="mirror://sourceforge/${PN}/${PN}_${PV}_src_all.tar.bz2"
297 +
298 +LICENSE="LGPL-2.1 rar? ( unRAR )"
299 +SLOT="0"
300 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sparc ~x86 ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris"
301 +IUSE="abi_x86_x32 doc kde +pch rar static wxwidgets"
302 +
303 +REQUIRED_USE="kde? ( wxwidgets )"
304 +
305 +RDEPEND="wxwidgets? ( x11-libs/wxGTK:${WX_GTK_VER}[X] )"
306 +DEPEND="${RDEPEND}
307 + abi_x86_x32? ( >=dev-lang/yasm-1.2.0-r1 )
308 + amd64? ( dev-lang/yasm )
309 + x86? ( dev-lang/nasm )"
310 +
311 +S=${WORKDIR}/${PN}_${PV}
312 +
313 +DOCS=( ChangeLog README TODO )
314 +
315 +PATCHES=(
316 + "${FILESDIR}"/${P}-darwin.patch
317 + "${FILESDIR}"/CVE-2017-17969.patch
318 + "${FILESDIR}"/CVE-2018-5996.patch
319 +)
320 +
321 +src_prepare() {
322 + default
323 +
324 + if ! use pch; then
325 + sed "s:PRE_COMPILED_HEADER=StdAfx.h.gch:PRE_COMPILED_HEADER=:g" -i makefile.* || die
326 + fi
327 +
328 + sed \
329 + -e 's:-m32 ::g' \
330 + -e 's:-m64 ::g' \
331 + -e 's:-pipe::g' \
332 + -e '/ALLFLAGS/s:-s ::' \
333 + -e "/OPTFLAGS=/s:=.*:=${CXXFLAGS}:" \
334 + -i makefile* || die
335 +
336 + # remove non-free RAR codec
337 + if use rar; then
338 + ewarn "Enabling nonfree RAR decompressor"
339 + else
340 + sed \
341 + -e '/Rar/d' \
342 + -e '/RAR/d' \
343 + -i makefile* CPP/7zip/Bundles/Format7zFree/makefile || die
344 + rm -rf CPP/7zip/Compress/Rar || die
345 + fi
346 +
347 + if use abi_x86_x32; then
348 + sed -i -e "/^ASM=/s:amd64:x32:" makefile* || die
349 + cp -f makefile.linux_amd64_asm makefile.machine || die
350 + elif use amd64; then
351 + cp -f makefile.linux_amd64_asm makefile.machine || die
352 + elif use x86; then
353 + cp -f makefile.linux_x86_asm_gcc_4.X makefile.machine || die
354 + elif [[ ${CHOST} == *-darwin* ]] ; then
355 + # Mac OS X needs this special makefile, because it has a non-GNU
356 + # linker, it doesn't matter so much for bitwidth, for it doesn't
357 + # do anything with it
358 + cp -f makefile.macosx_llvm_64bits makefile.machine
359 + # bundles have extension .bundle but don't die because USE=-rar
360 + # removes the Rar directory
361 + sed -i -e '/strcpy(name/s/\.so/.bundle/' \
362 + CPP/Windows/DLL.cpp || die
363 + sed -i -e '/^PROG=/s/\.so/.bundle/' \
364 + CPP/7zip/Bundles/Format7zFree/makefile.list \
365 + $(use rar && echo CPP/7zip/Compress/Rar/makefile.list) || die
366 + elif use x86-fbsd; then
367 + # FreeBSD needs this special makefile, because it hasn't -ldl
368 + sed -e 's/-lc_r/-pthread/' makefile.freebsd > makefile.machine
369 + fi
370 +
371 + if use static; then
372 + sed -i -e '/^LOCAL_LIBS=/s/LOCAL_LIBS=/&-static /' makefile.machine || die
373 + fi
374 +
375 + if use kde || use wxwidgets; then
376 + need-wxwidgets unicode
377 + einfo "Preparing dependency list"
378 + emake depend
379 + fi
380 +}
381 +
382 +src_compile() {
383 + emake CC=$(tc-getCC) CXX=$(tc-getCXX) all3
384 + if use kde || use wxwidgets; then
385 + emake CC=$(tc-getCC) CXX=$(tc-getCXX) -- 7zG
386 +# emake -- 7zFM
387 + fi
388 +}
389 +
390 +src_test() {
391 + emake test test_7z test_7zr
392 +}
393 +
394 +src_install() {
395 + # this wrappers can not be symlinks, p7zip should be called with full path
396 + make_wrapper 7zr "/usr/$(get_libdir)/${PN}/7zr"
397 + make_wrapper 7za "/usr/$(get_libdir)/${PN}/7za"
398 + make_wrapper 7z "/usr/$(get_libdir)/${PN}/7z"
399 +
400 + if use kde || use wxwidgets; then
401 + make_wrapper 7zG "/usr/$(get_libdir)/${PN}/7zG"
402 +# make_wrapper 7zFM "/usr/$(get_libdir)/${PN}/7zFM"
403 +
404 +# make_desktop_entry 7zFM "${PN} FM" ${PN} "GTK;Utility;Archiving;Compression"
405 +
406 + dobin GUI/p7zipForFilemanager
407 + exeinto /usr/$(get_libdir)/${PN}
408 +# doexe bin/7z{G,FM}
409 + doexe bin/7zG
410 +
411 + insinto /usr/$(get_libdir)/${PN}
412 + doins -r GUI/Lang
413 + doins -r DOC/MANUAL
414 +
415 + insinto /usr/share/icons/hicolor/16x16/apps/
416 + newins GUI/p7zip_16_ok.png p7zip.png
417 +
418 + if use kde; then
419 + rm GUI/kde4/p7zip_compress.desktop || die
420 + insinto /usr/share/kservices5/ServiceMenus
421 + doins GUI/kde4/*.desktop
422 + dodir /usr/share/kde4/services/ServiceMenus # drop these lines after konqueror:4/krusader:4 are gone
423 + for item in "${ED}"usr/share/kservices5/ServiceMenus/*.desktop; do
424 + item="$(basename ${item})"
425 + dosym "/usr/share/kservices5/ServiceMenus/${item}" "/usr/share/kde4/services/ServiceMenus/${item}"
426 + done
427 + fi
428 + fi
429 +
430 + dobin contrib/gzip-like_CLI_wrapper_for_7z/p7zip
431 + doman contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1
432 +
433 + exeinto /usr/$(get_libdir)/${PN}
434 + doexe bin/7z bin/7za bin/7zr bin/7zCon.sfx
435 + doexe bin/*$(get_modname)
436 + if use rar; then
437 + exeinto /usr/$(get_libdir)/${PN}/Codecs/
438 + doexe bin/Codecs/*$(get_modname)
439 + fi
440 +
441 + doman man1/7z.1 man1/7za.1 man1/7zr.1
442 +
443 + if use doc; then
444 + dodoc DOC/*.txt
445 + dohtml -r DOC/MANUAL/*
446 + fi
447 +}