1 |
commit: 253ca90f3f968a03ea6fff8f0011cf411764b22e |
2 |
Author: Sam James <sam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Aug 16 02:28:55 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Aug 16 02:29:57 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=253ca90f |
7 |
|
8 |
sys-apps/file: backport unicode handling fixes to 5.42 |
9 |
|
10 |
Temporarily unkeyworded given I had a few issues before I threw |
11 |
in a few extra patches. Want to give it a test run for a day |
12 |
or so myself first before keywording. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/861089 |
15 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
16 |
|
17 |
sys-apps/file/file-5.42-r1.ebuild | 162 +++++++++ |
18 |
sys-apps/file/files/file-5.42-unicode-fixes.patch | 414 ++++++++++++++++++++++ |
19 |
2 files changed, 576 insertions(+) |
20 |
|
21 |
diff --git a/sys-apps/file/file-5.42-r1.ebuild b/sys-apps/file/file-5.42-r1.ebuild |
22 |
new file mode 100644 |
23 |
index 000000000000..e74d71b49e84 |
24 |
--- /dev/null |
25 |
+++ b/sys-apps/file/file-5.42-r1.ebuild |
26 |
@@ -0,0 +1,162 @@ |
27 |
+# Copyright 1999-2022 Gentoo Authors |
28 |
+# Distributed under the terms of the GNU General Public License v2 |
29 |
+ |
30 |
+EAPI=8 |
31 |
+ |
32 |
+DISTUTILS_USE_PEP517=setuptools |
33 |
+DISTUTILS_OPTIONAL=1 |
34 |
+PYTHON_COMPAT=( python3_{8..11} ) |
35 |
+ |
36 |
+inherit distutils-r1 libtool toolchain-funcs multilib-minimal |
37 |
+ |
38 |
+if [[ ${PV} == 9999 ]] ; then |
39 |
+ EGIT_REPO_URI="https://github.com/glensc/file.git" |
40 |
+ inherit autotools git-r3 |
41 |
+else |
42 |
+ VERIFY_SIG_OPENPGP_KEY_PATH="${BROOT}"/usr/share/openpgp-keys/file.asc |
43 |
+ inherit verify-sig |
44 |
+ SRC_URI="ftp://ftp.astron.com/pub/file/${P}.tar.gz" |
45 |
+ SRC_URI+=" verify-sig? ( ftp://ftp.astron.com/pub/file/${P}.tar.gz.asc )" |
46 |
+ |
47 |
+ #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris" |
48 |
+ |
49 |
+ BDEPEND="verify-sig? ( sec-keys/openpgp-keys-file )" |
50 |
+fi |
51 |
+ |
52 |
+DESCRIPTION="Identify a file's format by scanning binary data for patterns" |
53 |
+HOMEPAGE="https://www.darwinsys.com/file/" |
54 |
+ |
55 |
+LICENSE="BSD-2" |
56 |
+SLOT="0" |
57 |
+IUSE="bzip2 lzma python seccomp static-libs zlib" |
58 |
+REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )" |
59 |
+ |
60 |
+DEPEND=" |
61 |
+ bzip2? ( app-arch/bzip2[${MULTILIB_USEDEP}] ) |
62 |
+ lzma? ( app-arch/xz-utils[${MULTILIB_USEDEP}] ) |
63 |
+ python? ( |
64 |
+ ${PYTHON_DEPS} |
65 |
+ dev-python/setuptools[${PYTHON_USEDEP}] |
66 |
+ ) |
67 |
+ zlib? ( >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}] )" |
68 |
+RDEPEND="${DEPEND} |
69 |
+ python? ( !dev-python/python-magic ) |
70 |
+ seccomp? ( sys-libs/libseccomp[${MULTILIB_USEDEP}] )" |
71 |
+BDEPEND+=" |
72 |
+ python? ( |
73 |
+ ${PYTHON_DEPS} |
74 |
+ ${DISTUTILS_DEPS} |
75 |
+ )" |
76 |
+ |
77 |
+PATCHES=( |
78 |
+ "${FILESDIR}/file-5.39-portage-sandbox.patch" #713710 #728978 |
79 |
+ "${FILESDIR}/file-5.40-seccomp-fstatat64-musl.patch" #789336, not upstream yet |
80 |
+ "${FILESDIR}/${P}-unicode-fixes.patch" #861089 |
81 |
+) |
82 |
+ |
83 |
+src_prepare() { |
84 |
+ default |
85 |
+ |
86 |
+ if [[ ${PV} == 9999 ]] ; then |
87 |
+ eautoreconf |
88 |
+ else |
89 |
+ elibtoolize |
90 |
+ fi |
91 |
+ |
92 |
+ # don't let python README kill main README, bug ##60043 |
93 |
+ mv python/README.md python/README.python.md || die |
94 |
+ # bug #662090 |
95 |
+ sed 's@××××××.md@README.python.md@' -i python/setup.py || die |
96 |
+} |
97 |
+ |
98 |
+multilib_src_configure() { |
99 |
+ local myeconfargs=( |
100 |
+ --enable-fsect-man5 |
101 |
+ $(use_enable bzip2 bzlib) |
102 |
+ $(use_enable lzma xzlib) |
103 |
+ $(use_enable seccomp libseccomp) |
104 |
+ $(use_enable static-libs static) |
105 |
+ $(use_enable zlib) |
106 |
+ ) |
107 |
+ econf "${myeconfargs[@]}" |
108 |
+} |
109 |
+ |
110 |
+build_src_configure() { |
111 |
+ local myeconfargs=( |
112 |
+ --disable-shared |
113 |
+ --disable-libseccomp |
114 |
+ --disable-bzlib |
115 |
+ --disable-xzlib |
116 |
+ --disable-zlib |
117 |
+ ) |
118 |
+ |
119 |
+ econf_build "${myeconfargs[@]}" |
120 |
+} |
121 |
+ |
122 |
+need_build_file() { |
123 |
+ # when cross-compiling, we need to build up our own file |
124 |
+ # because people often don't keep matching host/target |
125 |
+ # file versions, bug #362941 |
126 |
+ tc-is-cross-compiler && ! has_version -b "~${CATEGORY}/${P}" |
127 |
+} |
128 |
+ |
129 |
+src_configure() { |
130 |
+ local ECONF_SOURCE="${S}" |
131 |
+ |
132 |
+ if need_build_file ; then |
133 |
+ mkdir -p "${WORKDIR}"/build || die |
134 |
+ cd "${WORKDIR}"/build || die |
135 |
+ build_src_configure |
136 |
+ fi |
137 |
+ |
138 |
+ multilib-minimal_src_configure |
139 |
+} |
140 |
+ |
141 |
+multilib_src_compile() { |
142 |
+ if multilib_is_native_abi ; then |
143 |
+ emake |
144 |
+ else |
145 |
+ # bug #586444 |
146 |
+ emake -C src magic.h |
147 |
+ emake -C src libmagic.la |
148 |
+ fi |
149 |
+} |
150 |
+ |
151 |
+src_compile() { |
152 |
+ if need_build_file ; then |
153 |
+ # bug #586444 |
154 |
+ emake -C "${WORKDIR}"/build/src magic.h |
155 |
+ emake -C "${WORKDIR}"/build/src file |
156 |
+ local -x PATH="${WORKDIR}/build/src:${PATH}" |
157 |
+ fi |
158 |
+ |
159 |
+ multilib-minimal_src_compile |
160 |
+ |
161 |
+ if use python ; then |
162 |
+ cd python || die |
163 |
+ distutils-r1_src_compile |
164 |
+ fi |
165 |
+} |
166 |
+ |
167 |
+multilib_src_install() { |
168 |
+ if multilib_is_native_abi ; then |
169 |
+ default |
170 |
+ else |
171 |
+ emake -C src install-{nodist_includeHEADERS,libLTLIBRARIES} DESTDIR="${D}" |
172 |
+ fi |
173 |
+} |
174 |
+ |
175 |
+multilib_src_install_all() { |
176 |
+ dodoc ChangeLog MAINT # README |
177 |
+ |
178 |
+ # Required for `file -C` |
179 |
+ insinto /usr/share/misc/magic |
180 |
+ doins -r magic/Magdir/* |
181 |
+ |
182 |
+ if use python ; then |
183 |
+ cd python || die |
184 |
+ distutils-r1_src_install |
185 |
+ fi |
186 |
+ |
187 |
+ find "${ED}" -type f -name "*.la" -delete || die |
188 |
+} |
189 |
|
190 |
diff --git a/sys-apps/file/files/file-5.42-unicode-fixes.patch b/sys-apps/file/files/file-5.42-unicode-fixes.patch |
191 |
new file mode 100644 |
192 |
index 000000000000..91c46a358120 |
193 |
--- /dev/null |
194 |
+++ b/sys-apps/file/files/file-5.42-unicode-fixes.patch |
195 |
@@ -0,0 +1,414 @@ |
196 |
+https://bugs.gentoo.org/861089 |
197 |
+https://github.com/file/file/commit/19bf47777d0002ee884467e45e6ace702e40a4c1 |
198 |
+https://github.com/file/file/commit/c80065fe6900be5e794941e29b32440e9969b1c3 |
199 |
+https://github.com/file/file/commit/7e59d34206d7c962e093d4239e5367a2cd8b7623 |
200 |
+https://github.com/file/file/commit/f042050f59bfc037677871c4d1037c33273f5213 |
201 |
+https://github.com/file/file/commit/d471022b2772071877895759f209f2c346757a4c |
202 |
+https://github.com/file/file/commit/441ac2b15508909e82ad467960df4ac0adf9644c |
203 |
+ |
204 |
+From 19bf47777d0002ee884467e45e6ace702e40a4c1 Mon Sep 17 00:00:00 2001 |
205 |
+From: Christos Zoulas <christos@××××××.com> |
206 |
+Date: Mon, 4 Jul 2022 17:00:51 +0000 |
207 |
+Subject: [PATCH] PR/358: Fix width for -f - (jpalus) |
208 |
+ |
209 |
+--- |
210 |
+ src/file.c | 46 +++++++++++++++++++++++++++++----------------- |
211 |
+ 2 files changed, 31 insertions(+), 18 deletions(-) |
212 |
+ |
213 |
+diff --git a/src/file.c b/src/file.c |
214 |
+index 5300e5af8..bb058ce1e 100644 |
215 |
+--- a/src/file.c |
216 |
++++ b/src/file.c |
217 |
+@@ -506,35 +506,47 @@ unwrap(struct magic_set *ms, const char *fn) |
218 |
+ size_t llen = 0; |
219 |
+ int wid = 0, cwid; |
220 |
+ int e = 0; |
221 |
++ size_t fi = 0, fimax = 100; |
222 |
++ char **flist = malloc(sizeof(*flist) * fimax); |
223 |
+ |
224 |
+- if (strcmp("-", fn) == 0) { |
225 |
++ if (flist == NULL) |
226 |
++out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); |
227 |
++ |
228 |
++ if (strcmp("-", fn) == 0) |
229 |
+ f = stdin; |
230 |
+- wid = 1; |
231 |
+- } else { |
232 |
++ else { |
233 |
+ if ((f = fopen(fn, "r")) == NULL) { |
234 |
+ file_warn("Cannot open `%s'", fn); |
235 |
+ return 1; |
236 |
+ } |
237 |
+- |
238 |
+- while ((len = getline(&line, &llen, f)) > 0) { |
239 |
+- if (line[len - 1] == '\n') |
240 |
+- line[len - 1] = '\0'; |
241 |
+- cwid = file_mbswidth(ms, line); |
242 |
+- if (cwid > wid) |
243 |
+- wid = cwid; |
244 |
+- } |
245 |
+- |
246 |
+- rewind(f); |
247 |
+ } |
248 |
+ |
249 |
+ while ((len = getline(&line, &llen, f)) > 0) { |
250 |
+ if (line[len - 1] == '\n') |
251 |
+ line[len - 1] = '\0'; |
252 |
+- e |= process(ms, line, wid); |
253 |
++ if (fi >= fimax) { |
254 |
++ fimax += 100; |
255 |
++ char **nf = realloc(flist, fimax * sizeof(*flist)); |
256 |
++ if (nf == NULL) |
257 |
++ goto out; |
258 |
++ } |
259 |
++ flist[fi++] = line; |
260 |
++ cwid = file_mbswidth(ms, line); |
261 |
++ if (cwid > wid) |
262 |
++ wid = cwid; |
263 |
++ line = NULL; |
264 |
++ llen = 0; |
265 |
++ } |
266 |
++ |
267 |
++ fimax = fi; |
268 |
++ for (fi = 0; fi < fimax; fi++) { |
269 |
++ e |= process(ms, flist[fi], wid); |
270 |
++ free(flist[fi]); |
271 |
+ } |
272 |
++ free(flist); |
273 |
+ |
274 |
+- free(line); |
275 |
+- (void)fclose(f); |
276 |
++ if (f != stdin) |
277 |
++ (void)fclose(f); |
278 |
+ return e; |
279 |
+ } |
280 |
+ |
281 |
+ |
282 |
+From c80065fe6900be5e794941e29b32440e9969b1c3 Mon Sep 17 00:00:00 2001 |
283 |
+From: Christos Zoulas <christos@××××××.com> |
284 |
+Date: Mon, 4 Jul 2022 19:44:35 +0000 |
285 |
+Subject: [PATCH] PR/362: ro-ee: fix wide char printing |
286 |
+ |
287 |
+--- a/src/file.c |
288 |
++++ b/src/file.c |
289 |
+@@ -60,6 +60,12 @@ FILE_RCSID("@(#)$File: file.c,v 1.196 2022/07/04 17:00:51 christos Exp $") |
290 |
+ #ifdef HAVE_WCTYPE_H |
291 |
+ #include <wctype.h> |
292 |
+ #endif |
293 |
++#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \ |
294 |
++ defined(HAVE_WCTYPE_H) |
295 |
++#define FILE_WIDE_SUPPORT |
296 |
++#else |
297 |
++#include <ctype.h> |
298 |
++#endif |
299 |
+ |
300 |
+ #if defined(HAVE_GETOPT_H) && defined(HAVE_STRUCT_OPTION) |
301 |
+ # include <getopt.h> |
302 |
+@@ -550,6 +556,55 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); |
303 |
+ return e; |
304 |
+ } |
305 |
+ |
306 |
++private void |
307 |
++file_octal(unsigned char c) |
308 |
++{ |
309 |
++ putc('\\', stdout); |
310 |
++ putc(((c >> 6) & 7) + '0', stdout); |
311 |
++ putc(((c >> 3) & 7) + '0', stdout); |
312 |
++ putc(((c >> 0) & 7) + '0', stdout); |
313 |
++} |
314 |
++ |
315 |
++private void |
316 |
++fname_print(const char *inname) |
317 |
++{ |
318 |
++ size_t n = strlen(inname); |
319 |
++#ifdef FILE_WIDE_SUPPORT |
320 |
++ mbstate_t state; |
321 |
++ wchar_t nextchar; |
322 |
++ size_t bytesconsumed; |
323 |
++ |
324 |
++ |
325 |
++ (void)mbrlen(NULL, 0, &state); |
326 |
++ while (n > 0) { |
327 |
++ bytesconsumed = mbrtowc(&nextchar, inname, n, &state); |
328 |
++ if (bytesconsumed == CAST(size_t, -1) || |
329 |
++ bytesconsumed == CAST(size_t, -2)) { |
330 |
++ nextchar = *inname; |
331 |
++ bytesconsumed = 1; |
332 |
++ } |
333 |
++ inname += bytesconsumed; |
334 |
++ n -= bytesconsumed; |
335 |
++ if (iswprint(nextchar)) { |
336 |
++ putwc(nextchar, stdout); |
337 |
++ continue; |
338 |
++ } |
339 |
++ /* XXX: What if it is > 255? */ |
340 |
++ file_octal(CAST(unsigned char, nextchar)); |
341 |
++ } |
342 |
++#else |
343 |
++ size_t i; |
344 |
++ for (i = 0; i < n; i++) { |
345 |
++ unsigned char c = CAST(unsigned char, inname[i]); |
346 |
++ if (isprint(c)) { |
347 |
++ putc(c); |
348 |
++ continue; |
349 |
++ } |
350 |
++ file_octal(c); |
351 |
++ } |
352 |
++#endif |
353 |
++} |
354 |
++ |
355 |
+ /* |
356 |
+ * Called for each input file on the command line (or in a list of files) |
357 |
+ */ |
358 |
+@@ -559,15 +614,13 @@ process(struct magic_set *ms, const char *inname, int wid) |
359 |
+ const char *type, c = nulsep > 1 ? '\0' : '\n'; |
360 |
+ int std_in = strcmp(inname, "-") == 0; |
361 |
+ int haderror = 0; |
362 |
+- size_t plen = 4 * wid + 1; |
363 |
+- char *pbuf, *pname; |
364 |
+- |
365 |
+- if ((pbuf = CAST(char *, malloc(plen))) == NULL) |
366 |
+- file_err(EXIT_FAILURE, "Can't allocate %zu bytes", plen); |
367 |
+ |
368 |
+ if (wid > 0 && !bflag) { |
369 |
+- pname = file_printable(ms, pbuf, plen, inname, wid); |
370 |
+- (void)printf("%s", std_in ? "/dev/stdin" : pname); |
371 |
++ const char *pname = std_in ? "/dev/stdin" : inname; |
372 |
++ if ((ms->flags & MAGIC_RAW) == 0) |
373 |
++ fname_print(pname); |
374 |
++ else |
375 |
++ (void)printf("%s", pname); |
376 |
+ if (nulsep) |
377 |
+ (void)putc('\0', stdout); |
378 |
+ if (nulsep < 2) { |
379 |
+@@ -586,7 +639,6 @@ process(struct magic_set *ms, const char *inname, int wid) |
380 |
+ } |
381 |
+ if (nobuffer) |
382 |
+ haderror |= fflush(stdout) != 0; |
383 |
+- free(pbuf); |
384 |
+ return haderror || type == NULL; |
385 |
+ } |
386 |
+ |
387 |
+@@ -594,35 +646,33 @@ protected size_t |
388 |
+ file_mbswidth(struct magic_set *ms, const char *s) |
389 |
+ { |
390 |
+ size_t width = 0; |
391 |
+-#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \ |
392 |
+- defined(HAVE_WCTYPE_H) |
393 |
+- size_t bytesconsumed, old_n, n; |
394 |
++#ifdef FILE_WIDE_SUPPORT |
395 |
++ size_t bytesconsumed, n; |
396 |
+ mbstate_t state; |
397 |
+ wchar_t nextchar; |
398 |
+- (void)memset(&state, 0, sizeof(mbstate_t)); |
399 |
+- old_n = n = strlen(s); |
400 |
++ |
401 |
++ (void)mbrlen(NULL, 0, &state); |
402 |
++ n = strlen(s); |
403 |
+ |
404 |
+ while (n > 0) { |
405 |
+ bytesconsumed = mbrtowc(&nextchar, s, n, &state); |
406 |
+ if (bytesconsumed == CAST(size_t, -1) || |
407 |
+ bytesconsumed == CAST(size_t, -2)) { |
408 |
+- /* Something went wrong, return something reasonable */ |
409 |
+- return old_n; |
410 |
++ nextchar = *s; |
411 |
++ bytesconsumed = 1; |
412 |
+ } |
413 |
+ width += ((ms->flags & MAGIC_RAW) != 0 |
414 |
+ || iswprint(nextchar)) ? wcwidth(nextchar) : 4; |
415 |
+ |
416 |
+ s += bytesconsumed, n -= bytesconsumed; |
417 |
+ } |
418 |
+- return width; |
419 |
+ #else |
420 |
+ while (*s) { |
421 |
+ width += (ms->flags & MAGIC_RAW) != 0 |
422 |
+ || isprint(CAST(unsigned char, *s)) ? 1 : 4; |
423 |
+ } |
424 |
+- |
425 |
+- return strlen(s); |
426 |
+ #endif |
427 |
++ return width; |
428 |
+ } |
429 |
+ |
430 |
+ private void |
431 |
+--- a/src/file.h |
432 |
++++ b/src/file.h |
433 |
+@@ -575,7 +575,7 @@ protected size_t file_pstring_length_size(struct magic_set *, |
434 |
+ const struct magic *); |
435 |
+ protected size_t file_pstring_get_length(struct magic_set *, |
436 |
+ const struct magic *, const char *); |
437 |
+-public char * file_printable(struct magic_set *, char *, size_t, |
438 |
++protected char * file_printable(struct magic_set *, char *, size_t, |
439 |
+ const char *, size_t); |
440 |
+ #ifdef __EMX__ |
441 |
+ protected int file_os2_apptype(struct magic_set *, const char *, const void *, |
442 |
+--- a/src/funcs.c |
443 |
++++ b/src/funcs.c |
444 |
+@@ -763,7 +763,7 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) |
445 |
+ /* |
446 |
+ * convert string to ascii printable format. |
447 |
+ */ |
448 |
+-public char * |
449 |
++protected char * |
450 |
+ file_printable(struct magic_set *ms, char *buf, size_t bufsiz, |
451 |
+ const char *str, size_t slen) |
452 |
+ { |
453 |
+ |
454 |
+From 7e59d34206d7c962e093d4239e5367a2cd8b7623 Mon Sep 17 00:00:00 2001 |
455 |
+From: Christos Zoulas <christos@××××××.com> |
456 |
+Date: Mon, 4 Jul 2022 20:16:29 +0000 |
457 |
+Subject: [PATCH] Handle invalid characters as octal (idea from PR/363 by |
458 |
+ dimich) |
459 |
+ |
460 |
+--- |
461 |
+ src/file.c | 16 +++++++++++----- |
462 |
+ 1 file changed, 11 insertions(+), 5 deletions(-) |
463 |
+ |
464 |
+diff --git a/src/file.c b/src/file.c |
465 |
+index 5e89137d7..af9be0f0c 100644 |
466 |
+--- a/src/file.c |
467 |
++++ b/src/file.c |
468 |
+@@ -580,8 +580,11 @@ fname_print(const char *inname) |
469 |
+ bytesconsumed = mbrtowc(&nextchar, inname, n, &state); |
470 |
+ if (bytesconsumed == CAST(size_t, -1) || |
471 |
+ bytesconsumed == CAST(size_t, -2)) { |
472 |
+- nextchar = *inname; |
473 |
+- bytesconsumed = 1; |
474 |
++ nextchar = *inname++; |
475 |
++ n--; |
476 |
++ (void)mbrlen(NULL, 0, &state); |
477 |
++ file_octal(CAST(unsigned char, nextchar)); |
478 |
++ continue; |
479 |
+ } |
480 |
+ inname += bytesconsumed; |
481 |
+ n -= bytesconsumed; |
482 |
+@@ -660,9 +663,12 @@ file_mbswidth(struct magic_set *ms, const char *s) |
483 |
+ bytesconsumed == CAST(size_t, -2)) { |
484 |
+ nextchar = *s; |
485 |
+ bytesconsumed = 1; |
486 |
++ (void)mbrlen(NULL, 0, &state); |
487 |
++ width += 4; |
488 |
++ } else { |
489 |
++ width += ((ms->flags & MAGIC_RAW) != 0 |
490 |
++ || iswprint(nextchar)) ? wcwidth(nextchar) : 4; |
491 |
+ } |
492 |
+- width += ((ms->flags & MAGIC_RAW) != 0 |
493 |
+- || iswprint(nextchar)) ? wcwidth(nextchar) : 4; |
494 |
+ |
495 |
+ s += bytesconsumed, n -= bytesconsumed; |
496 |
+ } |
497 |
+ |
498 |
+ |
499 |
+From f042050f59bfc037677871c4d1037c33273f5213 Mon Sep 17 00:00:00 2001 |
500 |
+From: Christos Zoulas <christos@××××××.com> |
501 |
+Date: Mon, 4 Jul 2022 22:30:51 +0000 |
502 |
+Subject: [PATCH] mbrlen(NULL, is not portable; revert to using memset to |
503 |
+ initialize the state. |
504 |
+ |
505 |
+--- |
506 |
+ src/file.c | 10 +++++----- |
507 |
+ 1 file changed, 5 insertions(+), 5 deletions(-) |
508 |
+ |
509 |
+diff --git a/src/file.c b/src/file.c |
510 |
+index af9be0f0c..8b4f14c2e 100644 |
511 |
+--- a/src/file.c |
512 |
++++ b/src/file.c |
513 |
+@@ -575,14 +575,14 @@ fname_print(const char *inname) |
514 |
+ size_t bytesconsumed; |
515 |
+ |
516 |
+ |
517 |
+- (void)mbrlen(NULL, 0, &state); |
518 |
++ (void)memset(&state, 0, sizeof(state)); |
519 |
+ while (n > 0) { |
520 |
+ bytesconsumed = mbrtowc(&nextchar, inname, n, &state); |
521 |
+ if (bytesconsumed == CAST(size_t, -1) || |
522 |
+ bytesconsumed == CAST(size_t, -2)) { |
523 |
+ nextchar = *inname++; |
524 |
+ n--; |
525 |
+- (void)mbrlen(NULL, 0, &state); |
526 |
++ (void)memset(&state, 0, sizeof(state)); |
527 |
+ file_octal(CAST(unsigned char, nextchar)); |
528 |
+ continue; |
529 |
+ } |
530 |
+@@ -654,7 +654,7 @@ file_mbswidth(struct magic_set *ms, const char *s) |
531 |
+ mbstate_t state; |
532 |
+ wchar_t nextchar; |
533 |
+ |
534 |
+- (void)mbrlen(NULL, 0, &state); |
535 |
++ (void)memset(&state, 0, sizeof(state)); |
536 |
+ n = strlen(s); |
537 |
+ |
538 |
+ while (n > 0) { |
539 |
+@@ -663,7 +663,7 @@ file_mbswidth(struct magic_set *ms, const char *s) |
540 |
+ bytesconsumed == CAST(size_t, -2)) { |
541 |
+ nextchar = *s; |
542 |
+ bytesconsumed = 1; |
543 |
+- (void)mbrlen(NULL, 0, &state); |
544 |
++ (void)memset(&state, 0, sizeof(state)); |
545 |
+ width += 4; |
546 |
+ } else { |
547 |
+ width += ((ms->flags & MAGIC_RAW) != 0 |
548 |
+ |
549 |
+ |
550 |
+From d471022b2772071877895759f209f2c346757a4c Mon Sep 17 00:00:00 2001 |
551 |
+From: Christos Zoulas <christos@××××××.com> |
552 |
+Date: Tue, 5 Jul 2022 19:53:42 +0000 |
553 |
+Subject: [PATCH] Use printf("%lc") instead of putwc(). Somehow mixing wide and |
554 |
+ narrow stdio does not work on Linux? |
555 |
+ |
556 |
+--- a/src/file.c |
557 |
++++ b/src/file.c |
558 |
+@@ -589,7 +589,7 @@ fname_print(const char *inname) |
559 |
+ inname += bytesconsumed; |
560 |
+ n -= bytesconsumed; |
561 |
+ if (iswprint(nextchar)) { |
562 |
+- putwc(nextchar, stdout); |
563 |
++ printf("%lc", nextchar); |
564 |
+ continue; |
565 |
+ } |
566 |
+ /* XXX: What if it is > 255? */ |
567 |
+ |
568 |
+From 441ac2b15508909e82ad467960df4ac0adf9644c Mon Sep 17 00:00:00 2001 |
569 |
+From: Christos Zoulas <christos@××××××.com> |
570 |
+Date: Tue, 5 Jul 2022 20:05:23 +0000 |
571 |
+Subject: [PATCH] wcwidth is not supposed to return -1 if the character is |
572 |
+ printable, but it does for 0xff... Prevent it from decreasing the width. |
573 |
+ |
574 |
+--- a/src/file.c |
575 |
++++ b/src/file.c |
576 |
+@@ -666,8 +666,9 @@ file_mbswidth(struct magic_set *ms, const char *s) |
577 |
+ (void)memset(&state, 0, sizeof(state)); |
578 |
+ width += 4; |
579 |
+ } else { |
580 |
++ int w = wcwidth(nextchar); |
581 |
+ width += ((ms->flags & MAGIC_RAW) != 0 |
582 |
+- || iswprint(nextchar)) ? wcwidth(nextchar) : 4; |
583 |
++ || iswprint(nextchar)) ? (w > 0 ? w : 1) : 4; |
584 |
+ } |
585 |
+ |
586 |
+ s += bytesconsumed, n -= bytesconsumed; |
587 |
+ |
588 |
+From be1ac8c0aa6d21921012f62582f51a9e546e4972 Mon Sep 17 00:00:00 2001 |
589 |
+From: Christos Zoulas <christos@××××××.com> |
590 |
+Date: Tue, 26 Jul 2022 15:10:05 +0000 |
591 |
+Subject: [PATCH] Fix bug with large flist (Florian Weimer) |
592 |
+ |
593 |
+--- |
594 |
+ src/file.c | 3 ++- |
595 |
+ 1 file changed, 2 insertions(+), 1 deletion(-) |
596 |
+ |
597 |
+diff --git a/src/file.c b/src/file.c |
598 |
+index e169c08fc..c0b8aa197 100644 |
599 |
+--- a/src/file.c |
600 |
++++ b/src/file.c |
601 |
+@@ -535,6 +535,7 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); |
602 |
+ char **nf = realloc(flist, fimax * sizeof(*flist)); |
603 |
+ if (nf == NULL) |
604 |
+ goto out; |
605 |
++ flist = nf; |
606 |
+ } |
607 |
+ flist[fi++] = line; |
608 |
+ cwid = file_mbswidth(ms, line); |
609 |
+ |