summary refs log tree commit diff
path: root/gnu/packages/patches/texlive-bin-CVE-2018-17407.patch
blob: 63646d420cec87c7dc8f430cbfbf85d249cb6571 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
This patch adds support for newer versions of Poppler and some upstream
TexLive fixes, including one for CVE-2018-17407.

It is taken from Linux From Scratch:
<http://www.linuxfromscratch.org/patches/blfs/svn/texlive-20180414-source-upstream_fixes-3.patch>.

Submitted By: Ken Moffat <ken at linuxfromscratch dot org>
Date: 2018-12-26
Initial Package Version: 20180414
Upstream Status: Applied
Origin: Upstream
Description: Two fixes, cherry-picked from svn plus a CVE fix.
I have removed the partial fixes for various system versions of poppler.

r47469 Fix segfault in dvipdfm-x (XeTeX) on 1/2/4-bit transparent indexed PNGs.

r47477 Fix a ptex regression for discontinuous kinsoku table.

Also, via fedora (I got lost in svn) a critical fix for CVE-2018-17407

"A buffer overflow in the handling of Type 1 fonts allows arbitrary code
execution when a malicious font is loaded by one of the vulnerable tools:
pdflatex, pdftex, dvips, or luatex."

diff -Naur a/texk/dvipdfm-x/pngimage.c b/texk/dvipdfm-x/pngimage.c
--- a/texk/dvipdfm-x/pngimage.c	2018-02-17 08:41:35.000000000 +0000
+++ b/texk/dvipdfm-x/pngimage.c	2018-10-09 01:52:01.648670875 +0100
@@ -964,12 +964,16 @@
   png_bytep   trans;
   int         num_trans;
   png_uint_32 i;
+  png_byte    bpc, mask, shift;
 
   if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ||
       !png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL)) {
     WARN("%s: PNG does not have valid tRNS chunk but tRNS is requested.", PNG_DEBUG_STR);
     return NULL;
   }
+  bpc   = png_get_bit_depth(png_ptr, info_ptr);
+  mask  = 0xff >> (8 - bpc);
+  shift = 8 - bpc;
 
   smask = pdf_new_stream(STREAM_COMPRESS);
   dict  = pdf_stream_dict(smask);
@@ -981,7 +985,8 @@
   pdf_add_dict(dict, pdf_new_name("ColorSpace"), pdf_new_name("DeviceGray"));
   pdf_add_dict(dict, pdf_new_name("BitsPerComponent"), pdf_new_number(8));
   for (i = 0; i < width*height; i++) {
-    png_byte idx = image_data_ptr[i];
+    /* data is packed for 1/2/4 bpc formats, msb first */
+    png_byte idx = (image_data_ptr[bpc * i / 8] >> (shift - bpc * i % 8)) & mask;
     smask_data_ptr[i] = (idx < num_trans) ? trans[idx] : 0xff;
   }
   pdf_add_stream(smask, (char *)smask_data_ptr, width*height);
diff -Naur a/texk/dvipsk/writet1.c b/texk/dvipsk/writet1.c
--- a/texk/dvipsk/writet1.c	2016-11-25 18:24:26.000000000 +0000
+++ b/texk/dvipsk/writet1.c	2018-10-09 01:52:01.648670875 +0100
@@ -1449,7 +1449,9 @@
         *(strend(t1_buf_array) - 1) = ' ';
 
         t1_getline();
+        alloc_array(t1_buf, strlen(t1_line_array) + strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcat(t1_buf_array, t1_line_array);
+        alloc_array(t1_line, strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcpy(t1_line_array, t1_buf_array);
         t1_line_ptr = eol(t1_line_array);
     }
diff -Naur a/texk/web2c/luatexdir/font/writet1.w b/texk/web2c/luatexdir/font/writet1.w
--- a/texk/web2c/luatexdir/font/writet1.w	2016-11-25 18:24:34.000000000 +0000
+++ b/texk/web2c/luatexdir/font/writet1.w	2018-10-09 01:52:01.648670875 +0100
@@ -1625,7 +1625,9 @@
     if (sscanf(p, "%i", &i) != 1) {
         strcpy(t1_buf_array, t1_line_array);
         t1_getline();
+        alloc_array(t1_buf, strlen(t1_line_array) + strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcat(t1_buf_array, t1_line_array);
+        alloc_array(t1_line, strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcpy(t1_line_array, t1_buf_array);
         t1_line_ptr = eol(t1_line_array);
     }
diff -Naur a/texk/web2c/luatexdir/image/pdftoepdf.w b/texk/web2c/luatexdir/image/pdftoepdf.w
--- a/texk/web2c/luatexdir/image/pdftoepdf.w	2018-01-17 18:00:12.000000000 +0000
+++ b/texk/web2c/luatexdir/image/pdftoepdf.w	2018-10-09 01:52:01.648670875 +0100
@@ -472,10 +472,10 @@
         break;
     */
     case objString:
-        copyString(pdf, obj->getString());
+        copyString(pdf, (GooString *)obj->getString());
         break;
     case objName:
-        copyName(pdf, obj->getName());
+        copyName(pdf, (char *)obj->getName());
         break;
     case objNull:
         pdf_add_null(pdf);
diff -Naur a/texk/web2c/luatexdir/lua/lepdflib.cc b/texk/web2c/luatexdir/lua/lepdflib.cc
--- a/texk/web2c/luatexdir/lua/lepdflib.cc	2018-02-14 14:44:38.000000000 +0000
+++ b/texk/web2c/luatexdir/lua/lepdflib.cc	2018-10-09 01:52:01.649670868 +0100
@@ -674,7 +674,7 @@
     uin = (udstruct *) luaL_checkudata(L, 1, M_##in);          \
     if (uin->pd != NULL && uin->pd->pc != uin->pc)             \
         pdfdoc_changed_error(L);                               \
-    gs = ((in *) uin->d)->function();                          \
+    gs = (GooString *)((in *) uin->d)->function();             \
     if (gs != NULL)                                            \
         lua_pushlstring(L, gs->getCString(), gs->getLength()); \
     else                                                       \
@@ -1813,7 +1813,7 @@
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
         pdfdoc_changed_error(L);
     if (((Object *) uin->d)->isString()) {
-        gs = ((Object *) uin->d)->getString();
+        gs = (GooString *)((Object *) uin->d)->getString();
         lua_pushlstring(L, gs->getCString(), gs->getLength());
     } else
         lua_pushnil(L);
diff -Naur a/texk/web2c/pdftexdir/writet1.c b/texk/web2c/pdftexdir/writet1.c
--- a/texk/web2c/pdftexdir/writet1.c	2016-11-25 18:24:37.000000000 +0000
+++ b/texk/web2c/pdftexdir/writet1.c	2018-10-09 01:52:01.649670868 +0100
@@ -1598,7 +1598,9 @@
         *(strend(t1_buf_array) - 1) = ' ';
 
         t1_getline();
+        alloc_array(t1_buf, strlen(t1_line_array) + strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcat(t1_buf_array, t1_line_array);
+        alloc_array(t1_line, strlen(t1_buf_array) + 1, T1_BUF_SIZE);
         strcpy(t1_line_array, t1_buf_array);
         t1_line_ptr = eol(t1_line_array);
     }
diff -Naur a/texk/web2c/ptexdir/ptex_version.h b/texk/web2c/ptexdir/ptex_version.h
--- a/texk/web2c/ptexdir/ptex_version.h	2018-01-21 03:48:06.000000000 +0000
+++ b/texk/web2c/ptexdir/ptex_version.h	2018-10-09 01:52:01.649670868 +0100
@@ -1 +1 @@
-#define PTEX_VERSION "p3.8.0"
+#define PTEX_VERSION "p3.8.1"
diff -Naur a/texk/web2c/ptexdir/tests/free_ixsp.tex b/texk/web2c/ptexdir/tests/free_ixsp.tex
--- a/texk/web2c/ptexdir/tests/free_ixsp.tex	1970-01-01 01:00:00.000000000 +0100
+++ b/texk/web2c/ptexdir/tests/free_ixsp.tex	2018-10-09 01:52:01.649670868 +0100
@@ -0,0 +1,53 @@
+%#!eptex -ini -etex
+\let\dump\relax
+\batchmode
+\input plain
+
+\errorstopmode
+\catcode`@=11
+\newcount\@tempcnta
+\newcount\@tempcntb
+\newcount\@tempcntc
+\mathchardef\LIM=256
+
+\def\MYCHAR#1{%
+  \@tempcntc=\numexpr7*#1+"101\relax
+  \@tempcnta=\@tempcntc\divide\@tempcnta 94
+  \@tempcntb=\numexpr\@tempcntc-94*\@tempcnta+1\relax
+  \ifnum\@tempcntb<0\advance\@tempcntb94 \advance\@tempcnta-1\fi
+  \advance\@tempcnta18 % 18区以降
+  \CNTA=\kuten\numexpr"100*\@tempcnta+\@tempcntb\relax
+}
+
+\newcount\CNT\newcount\CNTA
+\CNT=0
+\loop
+  \MYCHAR\CNT
+  \message{\the\CNT.}
+  \inhibitxspcode\CNTA=1\relax
+  \advance\CNT1\relax
+  \ifnum\CNT<\LIM
+\repeat
+
+\newcount\CNTB
+
+\loop
+  \MYCHAR\CNTB
+  \global\inhibitxspcode\CNTA=3
+{%
+\CNT=0
+\loop
+  \MYCHAR\CNT
+  \count@=\numexpr 1-\inhibitxspcode\CNTA\relax
+  \ifnum\count@=0\else\ifnum\CNTB=\CNT\else
+    \errmessage{<\the\CNTB, \the\CNT, \the\inhibitxspcode\CNTA>}\fi\fi
+  \advance\CNT1\relax
+  \ifnum\CNT<\LIM
+\repeat
+}
+  \MYCHAR\CNTB
+  \global\inhibitxspcode\CNTA=1\relax
+  \advance\CNTB1\relax
+  \ifnum\CNTB<\LIM
+\repeat
+\bye
diff -Naur a/texk/web2c/ptexdir/tests/free_pena.tex b/texk/web2c/ptexdir/tests/free_pena.tex
--- a/texk/web2c/ptexdir/tests/free_pena.tex	1970-01-01 01:00:00.000000000 +0100
+++ b/texk/web2c/ptexdir/tests/free_pena.tex	2018-10-09 01:52:01.649670868 +0100
@@ -0,0 +1,52 @@
+%#!eptex -ini -etex
+\let\dump\relax
+\batchmode
+\input plain
+
+\errorstopmode
+\catcode`@=11
+\newcount\@tempcnta
+\newcount\@tempcntb
+\newcount\@tempcntc
+\mathchardef\LIM=256
+
+\def\MYCHAR#1{%
+  \@tempcntc=\numexpr7*#1+"101\relax
+  \@tempcnta=\@tempcntc\divide\@tempcnta 94
+  \@tempcntb=\numexpr\@tempcntc-94*\@tempcnta+1\relax
+  \ifnum\@tempcntb<0\advance\@tempcntb94 \advance\@tempcnta-1\fi
+  \advance\@tempcnta18 % 18区以降
+  \CNTA=\kuten\numexpr"100*\@tempcnta+\@tempcntb\relax
+}
+
+\newcount\CNT\newcount\CNTA
+\CNT=0
+\loop
+  \MYCHAR\CNT
+  \message{\the\CNT.}
+  \prebreakpenalty\CNTA=\numexpr\CNT+1\relax
+  \advance\CNT1\relax
+  \ifnum\CNT<\LIM
+\repeat
+
+\newcount\CNTB
+
+\loop
+  \MYCHAR\CNTB
+  \global\prebreakpenalty\CNTA=0
+{%
+\CNT=0
+\loop
+  \MYCHAR\CNT
+  \count@=\numexpr -\CNT-1+\prebreakpenalty\CNTA\relax
+  \ifnum\count@=0\else\ifnum\CNTB=\CNT\else\errmessage{<\the\CNTB, \the\CNT>}\fi\fi
+  \advance\CNT1\relax
+  \ifnum\CNT<\LIM
+\repeat
+}
+  \MYCHAR\CNTB
+  \global\prebreakpenalty\CNTA=\numexpr\CNTB+1\relax
+  \advance\CNTB1\relax
+  \ifnum\CNTB<\LIM
+\repeat
+\bye