1 |
commit: eb1365ccd7332af4595538bc6b2244058db7b79b |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jan 26 03:54:26 2018 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jan 26 22:25:18 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=eb1365cc |
7 |
|
8 |
media-libs/tiff: add upstream fix for CVE-2017-9935 #624696 |
9 |
|
10 |
Also drop some pdfium patches that they dropped when moving to 4.0.8. |
11 |
|
12 |
Bug: https://bugs.gentoo.org/624696 |
13 |
|
14 |
.../tiff/files/tiff-4.0.9-CVE-2017-9935.patch | 153 +++++++++++++++++++++ |
15 |
media-libs/tiff/tiff-4.0.9-r1.ebuild | 79 +++++++++++ |
16 |
2 files changed, 232 insertions(+) |
17 |
|
18 |
diff --git a/media-libs/tiff/files/tiff-4.0.9-CVE-2017-9935.patch b/media-libs/tiff/files/tiff-4.0.9-CVE-2017-9935.patch |
19 |
new file mode 100644 |
20 |
index 00000000000..96a10aa9b37 |
21 |
--- /dev/null |
22 |
+++ b/media-libs/tiff/files/tiff-4.0.9-CVE-2017-9935.patch |
23 |
@@ -0,0 +1,153 @@ |
24 |
+From 3dd8f6a357981a4090f126ab9025056c938b6940 Mon Sep 17 00:00:00 2001 |
25 |
+From: Brian May <brian@×××××××××××××.xyz> |
26 |
+Date: Thu, 7 Dec 2017 07:46:47 +1100 |
27 |
+Subject: [PATCH] tiff2pdf: Fix CVE-2017-9935 |
28 |
+ |
29 |
+Fix for http://bugzilla.maptools.org/show_bug.cgi?id=2704 |
30 |
+ |
31 |
+This vulnerability - at least for the supplied test case - is because we |
32 |
+assume that a tiff will only have one transfer function that is the same |
33 |
+for all pages. This is not required by the TIFF standards. |
34 |
+ |
35 |
+We than read the transfer function for every page. Depending on the |
36 |
+transfer function, we allocate either 2 or 4 bytes to the XREF buffer. |
37 |
+We allocate this memory after we read in the transfer function for the |
38 |
+page. |
39 |
+ |
40 |
+For the first exploit - POC1, this file has 3 pages. For the first page |
41 |
+we allocate 2 extra extra XREF entries. Then for the next page 2 more |
42 |
+entries. Then for the last page the transfer function changes and we |
43 |
+allocate 4 more entries. |
44 |
+ |
45 |
+When we read the file into memory, we assume we have 4 bytes extra for |
46 |
+each and every page (as per the last transfer function we read). Which |
47 |
+is not correct, we only have 2 bytes extra for the first 2 pages. As a |
48 |
+result, we end up writing past the end of the buffer. |
49 |
+ |
50 |
+There are also some related issues that this also fixes. For example, |
51 |
+TIFFGetField can return uninitalized pointer values, and the logic to |
52 |
+detect a N=3 vs N=1 transfer function seemed rather strange. |
53 |
+ |
54 |
+It is also strange that we declare the transfer functions to be of type |
55 |
+float, when the standard says they are unsigned 16 bit values. This is |
56 |
+fixed in another patch. |
57 |
+ |
58 |
+This patch will check to ensure that the N value for every transfer |
59 |
+function is the same for every page. If this changes, we abort with an |
60 |
+error. In theory, we should perhaps check that the transfer function |
61 |
+itself is identical for every page, however we don't do that due to the |
62 |
+confusion of the type of the data in the transfer function. |
63 |
+--- |
64 |
+ libtiff/tif_dir.c | 3 +++ |
65 |
+ tools/tiff2pdf.c | 65 +++++++++++++++++++++++++++++++++++++------------------ |
66 |
+ 2 files changed, 47 insertions(+), 21 deletions(-) |
67 |
+ |
68 |
+diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c |
69 |
+index 2ccaf448fc40..cbf2b6933a40 100644 |
70 |
+--- a/libtiff/tif_dir.c |
71 |
++++ b/libtiff/tif_dir.c |
72 |
+@@ -1065,6 +1065,9 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) |
73 |
+ if (td->td_samplesperpixel - td->td_extrasamples > 1) { |
74 |
+ *va_arg(ap, uint16**) = td->td_transferfunction[1]; |
75 |
+ *va_arg(ap, uint16**) = td->td_transferfunction[2]; |
76 |
++ } else { |
77 |
++ *va_arg(ap, uint16**) = NULL; |
78 |
++ *va_arg(ap, uint16**) = NULL; |
79 |
+ } |
80 |
+ break; |
81 |
+ case TIFFTAG_REFERENCEBLACKWHITE: |
82 |
+diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c |
83 |
+index d1a9b0959f84..c3ec07465e5a 100644 |
84 |
+--- a/tools/tiff2pdf.c |
85 |
++++ b/tools/tiff2pdf.c |
86 |
+@@ -1047,6 +1047,8 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ |
87 |
+ uint16 pagen=0; |
88 |
+ uint16 paged=0; |
89 |
+ uint16 xuint16=0; |
90 |
++ uint16 tiff_transferfunctioncount=0; |
91 |
++ float* tiff_transferfunction[3]; |
92 |
+ |
93 |
+ directorycount=TIFFNumberOfDirectories(input); |
94 |
+ t2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t,directorycount,sizeof(T2P_PAGE))); |
95 |
+@@ -1147,26 +1149,48 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){ |
96 |
+ } |
97 |
+ #endif |
98 |
+ if (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION, |
99 |
+- &(t2p->tiff_transferfunction[0]), |
100 |
+- &(t2p->tiff_transferfunction[1]), |
101 |
+- &(t2p->tiff_transferfunction[2]))) { |
102 |
+- if((t2p->tiff_transferfunction[1] != (float*) NULL) && |
103 |
+- (t2p->tiff_transferfunction[2] != (float*) NULL) && |
104 |
+- (t2p->tiff_transferfunction[1] != |
105 |
+- t2p->tiff_transferfunction[0])) { |
106 |
+- t2p->tiff_transferfunctioncount = 3; |
107 |
+- t2p->tiff_pages[i].page_extra += 4; |
108 |
+- t2p->pdf_xrefcount += 4; |
109 |
+- } else { |
110 |
+- t2p->tiff_transferfunctioncount = 1; |
111 |
+- t2p->tiff_pages[i].page_extra += 2; |
112 |
+- t2p->pdf_xrefcount += 2; |
113 |
+- } |
114 |
+- if(t2p->pdf_minorversion < 2) |
115 |
+- t2p->pdf_minorversion = 2; |
116 |
++ &(tiff_transferfunction[0]), |
117 |
++ &(tiff_transferfunction[1]), |
118 |
++ &(tiff_transferfunction[2]))) { |
119 |
++ |
120 |
++ if((tiff_transferfunction[1] != (float*) NULL) && |
121 |
++ (tiff_transferfunction[2] != (float*) NULL) |
122 |
++ ) { |
123 |
++ tiff_transferfunctioncount=3; |
124 |
++ } else { |
125 |
++ tiff_transferfunctioncount=1; |
126 |
++ } |
127 |
+ } else { |
128 |
+- t2p->tiff_transferfunctioncount=0; |
129 |
++ tiff_transferfunctioncount=0; |
130 |
+ } |
131 |
++ |
132 |
++ if (i > 0){ |
133 |
++ if (tiff_transferfunctioncount != t2p->tiff_transferfunctioncount){ |
134 |
++ TIFFError( |
135 |
++ TIFF2PDF_MODULE, |
136 |
++ "Different transfer function on page %d", |
137 |
++ i); |
138 |
++ t2p->t2p_error = T2P_ERR_ERROR; |
139 |
++ return; |
140 |
++ } |
141 |
++ } |
142 |
++ |
143 |
++ t2p->tiff_transferfunctioncount = tiff_transferfunctioncount; |
144 |
++ t2p->tiff_transferfunction[0] = tiff_transferfunction[0]; |
145 |
++ t2p->tiff_transferfunction[1] = tiff_transferfunction[1]; |
146 |
++ t2p->tiff_transferfunction[2] = tiff_transferfunction[2]; |
147 |
++ if(tiff_transferfunctioncount == 3){ |
148 |
++ t2p->tiff_pages[i].page_extra += 4; |
149 |
++ t2p->pdf_xrefcount += 4; |
150 |
++ if(t2p->pdf_minorversion < 2) |
151 |
++ t2p->pdf_minorversion = 2; |
152 |
++ } else if (tiff_transferfunctioncount == 1){ |
153 |
++ t2p->tiff_pages[i].page_extra += 2; |
154 |
++ t2p->pdf_xrefcount += 2; |
155 |
++ if(t2p->pdf_minorversion < 2) |
156 |
++ t2p->pdf_minorversion = 2; |
157 |
++ } |
158 |
++ |
159 |
+ if( TIFFGetField( |
160 |
+ input, |
161 |
+ TIFFTAG_ICCPROFILE, |
162 |
+@@ -1828,9 +1852,8 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){ |
163 |
+ &(t2p->tiff_transferfunction[1]), |
164 |
+ &(t2p->tiff_transferfunction[2]))) { |
165 |
+ if((t2p->tiff_transferfunction[1] != (float*) NULL) && |
166 |
+- (t2p->tiff_transferfunction[2] != (float*) NULL) && |
167 |
+- (t2p->tiff_transferfunction[1] != |
168 |
+- t2p->tiff_transferfunction[0])) { |
169 |
++ (t2p->tiff_transferfunction[2] != (float*) NULL) |
170 |
++ ) { |
171 |
+ t2p->tiff_transferfunctioncount=3; |
172 |
+ } else { |
173 |
+ t2p->tiff_transferfunctioncount=1; |
174 |
+-- |
175 |
+2.15.1 |
176 |
+ |
177 |
|
178 |
diff --git a/media-libs/tiff/tiff-4.0.9-r1.ebuild b/media-libs/tiff/tiff-4.0.9-r1.ebuild |
179 |
new file mode 100644 |
180 |
index 00000000000..fbb216176cd |
181 |
--- /dev/null |
182 |
+++ b/media-libs/tiff/tiff-4.0.9-r1.ebuild |
183 |
@@ -0,0 +1,79 @@ |
184 |
+# Copyright 1999-2018 Gentoo Foundation |
185 |
+# Distributed under the terms of the GNU General Public License v2 |
186 |
+ |
187 |
+EAPI="6" |
188 |
+inherit autotools eutils libtool multilib-minimal |
189 |
+ |
190 |
+DESCRIPTION="Tag Image File Format (TIFF) library" |
191 |
+HOMEPAGE="http://libtiff.maptools.org" |
192 |
+SRC_URI="http://download.osgeo.org/libtiff/${P}.tar.gz |
193 |
+ ftp://ftp.remotesensing.org/pub/libtiff/${P}.tar.gz" |
194 |
+ |
195 |
+LICENSE="libtiff" |
196 |
+SLOT="0" |
197 |
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~x64-solaris ~x86-solaris" |
198 |
+IUSE="+cxx jbig jpeg lzma static-libs test zlib" |
199 |
+ |
200 |
+RDEPEND="jpeg? ( >=virtual/jpeg-0-r2:0=[${MULTILIB_USEDEP}] ) |
201 |
+ jbig? ( >=media-libs/jbigkit-2.1:=[${MULTILIB_USEDEP}] ) |
202 |
+ lzma? ( >=app-arch/xz-utils-5.0.5-r1:=[${MULTILIB_USEDEP}] ) |
203 |
+ zlib? ( >=sys-libs/zlib-1.2.8-r1:=[${MULTILIB_USEDEP}] ) |
204 |
+ abi_x86_32? ( |
205 |
+ !<=app-emulation/emul-linux-x86-baselibs-20130224-r9 |
206 |
+ !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] |
207 |
+ )" |
208 |
+DEPEND="${RDEPEND}" |
209 |
+ |
210 |
+REQUIRED_USE="test? ( jpeg )" #483132 |
211 |
+ |
212 |
+PATCHES=( |
213 |
+ "${FILESDIR}"/${PN}-4.0.7-pdfium-0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch |
214 |
+ "${FILESDIR}"/${PN}-4.0.7-pdfium-0008-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch |
215 |
+ "${FILESDIR}"/${P}-CVE-2017-9935.patch #624696 |
216 |
+) |
217 |
+ |
218 |
+MULTILIB_WRAPPED_HEADERS=( |
219 |
+ /usr/include/tiffconf.h |
220 |
+) |
221 |
+ |
222 |
+src_prepare() { |
223 |
+ default |
224 |
+ |
225 |
+ # tiffcp-thumbnail.sh fails as thumbnail binary doesn't get built anymore since tiff-4.0.7 |
226 |
+ sed '/tiffcp-thumbnail\.sh/d' -i test/Makefile.am || die |
227 |
+ |
228 |
+ eautoreconf |
229 |
+} |
230 |
+ |
231 |
+multilib_src_configure() { |
232 |
+ ECONF_SOURCE="${S}" econf \ |
233 |
+ $(use_enable static-libs static) \ |
234 |
+ $(use_enable zlib) \ |
235 |
+ $(use_enable jpeg) \ |
236 |
+ $(use_enable jbig) \ |
237 |
+ $(use_enable lzma) \ |
238 |
+ $(use_enable cxx) \ |
239 |
+ --without-x |
240 |
+ |
241 |
+ # remove useless subdirs |
242 |
+ if ! multilib_is_native_abi ; then |
243 |
+ sed -i \ |
244 |
+ -e 's/ tools//' \ |
245 |
+ -e 's/ contrib//' \ |
246 |
+ -e 's/ man//' \ |
247 |
+ -e 's/ html//' \ |
248 |
+ Makefile || die |
249 |
+ fi |
250 |
+} |
251 |
+ |
252 |
+multilib_src_test() { |
253 |
+ if ! multilib_is_native_abi ; then |
254 |
+ emake -C tools |
255 |
+ fi |
256 |
+ emake check |
257 |
+} |
258 |
+ |
259 |
+multilib_src_install_all() { |
260 |
+ prune_libtool_files --all |
261 |
+ rm -f "${ED}"/usr/share/doc/${PF}/{COPYRIGHT,README*,RELEASE-DATE,TODO,VERSION} |
262 |
+} |