From 930cc7d721b1ea68468608da3ce2b4e891926834 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Tue, 16 Aug 2022 08:29:51 +0100 Subject: gentoo auto-resync : 16:08:2022 - 08:29:51 --- sys-apps/Manifest.gz | Bin 48176 -> 48170 bytes sys-apps/file/Manifest | 10 +- sys-apps/file/file-5.42-r1.ebuild | 162 +++++++++ sys-apps/file/file-5.42.ebuild | 2 +- sys-apps/file/file-9999.ebuild | 2 +- .../file/files/file-5.39-portage-sandbox.patch | 9 - .../files/file-5.40-seccomp-fstatat64-musl.patch | 9 - sys-apps/file/files/file-5.42-unicode-fixes.patch | 390 +++++++++++++++++++++ 8 files changed, 560 insertions(+), 24 deletions(-) create mode 100644 sys-apps/file/file-5.42-r1.ebuild create mode 100644 sys-apps/file/files/file-5.42-unicode-fixes.patch (limited to 'sys-apps') diff --git a/sys-apps/Manifest.gz b/sys-apps/Manifest.gz index 5b87f78b808c..8ac9d77d104e 100644 Binary files a/sys-apps/Manifest.gz and b/sys-apps/Manifest.gz differ diff --git a/sys-apps/file/Manifest b/sys-apps/file/Manifest index 43f9345b2ecd..56a00b9d404a 100644 --- a/sys-apps/file/Manifest +++ b/sys-apps/file/Manifest @@ -1,9 +1,11 @@ -AUX file-5.39-portage-sandbox.patch 604 BLAKE2B d755d85ae85826df5d2beb2d05f570e230af671c23f27bb1e3e811d1f2f710ae3d4f14d271f9dc4da4d1aa4e71070561d1121deaccf8781de72ff9aec059caa3 SHA512 a65368ed9225b0ca6e7341283a20b308c5d5ca38838849d5228be762d4d87de0438084af8f7cd7b6ee1a707125226940490a80cc1eafc2c817fc865a6211c890 -AUX file-5.40-seccomp-fstatat64-musl.patch 723 BLAKE2B cb6e5151b863328a4764f38f49cf42420eb13444783301af5f5e380e67da932d298ed94fb64a2a1a50ca349b43d73b77d6495df090d8b3adddc2b236b7fe3a42 SHA512 b25110ca59be28ca67a972c9737315efe357c2bbb8dbae4e6ecf80283bb0e9db4184574bfef2d965087493ede4979f649a762fa9bef2415d2359db117dfdb04f +AUX file-5.39-portage-sandbox.patch 457 BLAKE2B ff4b67570144d5995ef62326da5f7a4ac5fe4befc3db56ff6d6a711c84bb4316da9e1a203326a6bc219066acd8e40634bf17f28f95d583bfa2f3d4698bcd57fc SHA512 20f66d918a605233f733fa6f5c038d9c56ec1175e706b76b16ecb8be81d64d79c3a932824b61092bf1edcd55c29fc2bcfa8bdf506e5717c10e849ec6110bbd3d +AUX file-5.40-seccomp-fstatat64-musl.patch 578 BLAKE2B c2c074e4dca62253303bae3af88a7ce0bc7d3efd608bd7269d624ad69b0fe4022db38efc5bb63d8f6d1f7bf45c2a1d749c406e76cf1ce42be731e663e2874ad5 SHA512 008c2a2c18b14eaa49f62b87fa14f4bea46bfd56efda17e49541fd51d87201d4d5511d3aae50b53dfcd68cc8e9a38884711ac59458acff9bf3290e267c2891bb +AUX file-5.42-unicode-fixes.patch 10989 BLAKE2B af85384f3d2461d30deda506e1e624ffb9d72ef3a25c7e902a747f10dbcb6ca7782d24900b1d5cc856763052975d6e3649d880d005d82bd5f64d310b014f82a8 SHA512 824f128b44a51fee1673110e90be6fdf7831a5220cc608dc94ef1367e1550de05170a8e9a4c4e90a1f372e975b9c391a2cb5ea968df1cb263734bd78ce585403 DIST file-5.41.tar.gz 1064097 BLAKE2B 56fe8a58d9497bb1bfe3ed6b3ce5df70dd27cc308eb0cfdac8e91ba81c733a96aa622c120ac59079986c6d84901c6f2d82fa24f698d481d7f77e6cfdd432d648 SHA512 bbf2d8e39450b31d0ba8d76d202790fea953775657f942f06e6dc9091798d4a395f7205e542388e4a25b6a4506d07f36c5c4da37cfce0734133e9203a3b00654 DIST file-5.42.tar.gz 1105846 BLAKE2B c557facb066ae0599db832ddbbc3fed7db2e057faefe832cb4bed8f860b63456217bee39f0c82b17902c3b91426e522681216d2d3ed689501fa00d69a4a09832 SHA512 33c3c339a561c6cf787cc06a16444a971c62068b01827612c948207a9714107b617bed8148cd67e6280cb1c62ad4dfb1205fb8486ea9c042ce7e19b067d3bb05 DIST file-5.42.tar.gz.asc 195 BLAKE2B 9b930bcd6b98878e60cd72d8d71b40201ebbf3ab1dda7d2b0e3228abdc0c1e21473a012b9799dcac8638ded1bdbe03865c5e41ed4086076a7df6bf6aadbfe29d SHA512 a7105c48f6c671638f5fb7f18f9b193d108456655b4c734208e00aca36fab54dd330ec2fdc3ff29fb78adbc16874af4fb0916c560e50228f82003a8cd258491a EBUILD file-5.41.ebuild 3347 BLAKE2B 413305c675ac4b0af437e2ca48d4edd3ca29bbd3cfac376ebaed000142eb5a191f7d1c85449838ae204ec6c294828af68cfd7e6fe885b82c255d0570bc16b18d SHA512 396ef33817680b5bd48d7239e455f3c798f8813267ab7ea19dae7f845ad039164b88c6600887aba4254916a4ec857baaf01b949c6276510490e089d1f5b52f9b -EBUILD file-5.42.ebuild 3704 BLAKE2B 9f295023ba04d33d544c466487c7b760ecda69dd5afddfed8ec1ed738d9f5df636abe938eef5ad78b4092bc134ad160f1cadf03d431ee17d1c2cc1de2d1170e9 SHA512 0ca5dd550e09ad7be5392742a561368c699a70da25ea9448a903b947feb8f76388e5a7aec4f33c1797485cc50c33092b4d72a042701d662b23faadd94e231e3e -EBUILD file-9999.ebuild 3630 BLAKE2B 7eaf1c27c8b192957a7f3ba08f6e0ba3f45e52689fdd87e98a9d2d9e955b1f43fdf2410dd48a3c8c858f0c6eb467d6c987b02fd432ec25d6be16fa6e71c89880 SHA512 28655fdb206cc8d60778f63da73cfed704c9e4c3304c76885448eac56bd9549c950a0d70102b341459834694bae87e5cdd9d9159d29f308da0f6b33690513bca +EBUILD file-5.42-r1.ebuild 3761 BLAKE2B c728fae0d35f7514271fc1923b57e08954b7907efba7709b593c055f05cdd7210a496b90fc876c4daf253503d570120040439f6b0524f01e9eb5b63be679e5f8 SHA512 eb66ac896763f5bf7750f0b124ce832af2b7d4e0b70d775344c6d4944b285d92b5c7f023518b05c589aac251fa2292f83e0fc4bdad4d2a0953abc59e6dbe2fec +EBUILD file-5.42.ebuild 3712 BLAKE2B 5f769622b69aa3836386f50da10da5f9e8ef8bc0e8ae82637686a791d6b2c20261056f8386ba896aa0d9450367127312c601d9371da1fa5c912900deeb1d505d SHA512 eac92daa30a5c84a9205498d1bf994a17f84b8d815b62b5c580c783cedf845d45a0d55d7f29a088306b4b40386bc819f13b8f929d988f1770388a1d16d42efc3 +EBUILD file-9999.ebuild 3633 BLAKE2B 73f50ffd23c0abb9adf2eecc57a03e91b660b9b7fc1a9f3bfb2d465ccebcc5901fd6f5870ea4406623916e9ac10178ef1246c17fee07340c0aec320a801db9e2 SHA512 fb628df3e45d37351f8e94d6f94182792f460d5367a813546bf953b6f8dd76af1c70686913540c18fb78b37e3dcaf47787e9059796ac77c19615eccd2dddffd2 MISC metadata.xml 439 BLAKE2B d937d412b733516f49ca24a5de5238688ba56c06872cec060608139cb551f78e165e05990bcf6ea5bb1e98d27eb2650f5a972a4cded85eb67dbe9218d5d705b8 SHA512 20ff0c1b94dae95c3b277cfcc10da2b6ff31582cfe8f4e2ae60a74ec45db2a854eef40950f354465a45563ee6333f327566565e40cb16249d191bde585c5b1f2 diff --git a/sys-apps/file/file-5.42-r1.ebuild b/sys-apps/file/file-5.42-r1.ebuild new file mode 100644 index 000000000000..e74d71b49e84 --- /dev/null +++ b/sys-apps/file/file-5.42-r1.ebuild @@ -0,0 +1,162 @@ +# Copyright 1999-2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_USE_PEP517=setuptools +DISTUTILS_OPTIONAL=1 +PYTHON_COMPAT=( python3_{8..11} ) + +inherit distutils-r1 libtool toolchain-funcs multilib-minimal + +if [[ ${PV} == 9999 ]] ; then + EGIT_REPO_URI="https://github.com/glensc/file.git" + inherit autotools git-r3 +else + VERIFY_SIG_OPENPGP_KEY_PATH="${BROOT}"/usr/share/openpgp-keys/file.asc + inherit verify-sig + SRC_URI="ftp://ftp.astron.com/pub/file/${P}.tar.gz" + SRC_URI+=" verify-sig? ( ftp://ftp.astron.com/pub/file/${P}.tar.gz.asc )" + + #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" + + BDEPEND="verify-sig? ( sec-keys/openpgp-keys-file )" +fi + +DESCRIPTION="Identify a file's format by scanning binary data for patterns" +HOMEPAGE="https://www.darwinsys.com/file/" + +LICENSE="BSD-2" +SLOT="0" +IUSE="bzip2 lzma python seccomp static-libs zlib" +REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )" + +DEPEND=" + bzip2? ( app-arch/bzip2[${MULTILIB_USEDEP}] ) + lzma? ( app-arch/xz-utils[${MULTILIB_USEDEP}] ) + python? ( + ${PYTHON_DEPS} + dev-python/setuptools[${PYTHON_USEDEP}] + ) + zlib? ( >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}] )" +RDEPEND="${DEPEND} + python? ( !dev-python/python-magic ) + seccomp? ( sys-libs/libseccomp[${MULTILIB_USEDEP}] )" +BDEPEND+=" + python? ( + ${PYTHON_DEPS} + ${DISTUTILS_DEPS} + )" + +PATCHES=( + "${FILESDIR}/file-5.39-portage-sandbox.patch" #713710 #728978 + "${FILESDIR}/file-5.40-seccomp-fstatat64-musl.patch" #789336, not upstream yet + "${FILESDIR}/${P}-unicode-fixes.patch" #861089 +) + +src_prepare() { + default + + if [[ ${PV} == 9999 ]] ; then + eautoreconf + else + elibtoolize + fi + + # don't let python README kill main README, bug ##60043 + mv python/README.md python/README.python.md || die + # bug #662090 + sed 's@README.md@README.python.md@' -i python/setup.py || die +} + +multilib_src_configure() { + local myeconfargs=( + --enable-fsect-man5 + $(use_enable bzip2 bzlib) + $(use_enable lzma xzlib) + $(use_enable seccomp libseccomp) + $(use_enable static-libs static) + $(use_enable zlib) + ) + econf "${myeconfargs[@]}" +} + +build_src_configure() { + local myeconfargs=( + --disable-shared + --disable-libseccomp + --disable-bzlib + --disable-xzlib + --disable-zlib + ) + + econf_build "${myeconfargs[@]}" +} + +need_build_file() { + # when cross-compiling, we need to build up our own file + # because people often don't keep matching host/target + # file versions, bug #362941 + tc-is-cross-compiler && ! has_version -b "~${CATEGORY}/${P}" +} + +src_configure() { + local ECONF_SOURCE="${S}" + + if need_build_file ; then + mkdir -p "${WORKDIR}"/build || die + cd "${WORKDIR}"/build || die + build_src_configure + fi + + multilib-minimal_src_configure +} + +multilib_src_compile() { + if multilib_is_native_abi ; then + emake + else + # bug #586444 + emake -C src magic.h + emake -C src libmagic.la + fi +} + +src_compile() { + if need_build_file ; then + # bug #586444 + emake -C "${WORKDIR}"/build/src magic.h + emake -C "${WORKDIR}"/build/src file + local -x PATH="${WORKDIR}/build/src:${PATH}" + fi + + multilib-minimal_src_compile + + if use python ; then + cd python || die + distutils-r1_src_compile + fi +} + +multilib_src_install() { + if multilib_is_native_abi ; then + default + else + emake -C src install-{nodist_includeHEADERS,libLTLIBRARIES} DESTDIR="${D}" + fi +} + +multilib_src_install_all() { + dodoc ChangeLog MAINT # README + + # Required for `file -C` + insinto /usr/share/misc/magic + doins -r magic/Magdir/* + + if use python ; then + cd python || die + distutils-r1_src_install + fi + + find "${ED}" -type f -name "*.la" -delete || die +} diff --git a/sys-apps/file/file-5.42.ebuild b/sys-apps/file/file-5.42.ebuild index dee13cbe1e88..0b9cc3af8dba 100644 --- a/sys-apps/file/file-5.42.ebuild +++ b/sys-apps/file/file-5.42.ebuild @@ -18,7 +18,7 @@ else SRC_URI="ftp://ftp.astron.com/pub/file/${P}.tar.gz" SRC_URI+=" verify-sig? ( ftp://ftp.astron.com/pub/file/${P}.tar.gz.asc )" - 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" + 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" BDEPEND="verify-sig? ( sec-keys/openpgp-keys-file )" fi diff --git a/sys-apps/file/file-9999.ebuild b/sys-apps/file/file-9999.ebuild index 7f27cf37781f..a4e9e2299f36 100644 --- a/sys-apps/file/file-9999.ebuild +++ b/sys-apps/file/file-9999.ebuild @@ -145,7 +145,7 @@ multilib_src_install() { } multilib_src_install_all() { - dodoc ChangeLog MAINT README + dodoc ChangeLog MAINT README.md # Required for `file -C` insinto /usr/share/misc/magic diff --git a/sys-apps/file/files/file-5.39-portage-sandbox.patch b/sys-apps/file/files/file-5.39-portage-sandbox.patch index 3ea26641671f..1880f6223c06 100644 --- a/sys-apps/file/files/file-5.39-portage-sandbox.patch +++ b/sys-apps/file/files/file-5.39-portage-sandbox.patch @@ -4,12 +4,6 @@ Date: Wed, 24 Jun 2020 11:18:45 +0200 Subject: [PATCH] Allow getcwd for Gentoo's portage sandbox Bug: https://bugs.gentoo.org/728978 ---- - src/seccomp.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/seccomp.c b/src/seccomp.c -index db9364ae..7f5d6f26 100644 --- a/src/seccomp.c +++ b/src/seccomp.c @@ -229,6 +229,8 @@ enable_sandbox_full(void) @@ -21,6 +15,3 @@ index db9364ae..7f5d6f26 100644 #if 0 // needed by valgrind --- -2.28.0 - diff --git a/sys-apps/file/files/file-5.40-seccomp-fstatat64-musl.patch b/sys-apps/file/files/file-5.40-seccomp-fstatat64-musl.patch index 4cc648017860..28a278e73f07 100644 --- a/sys-apps/file/files/file-5.40-seccomp-fstatat64-musl.patch +++ b/sys-apps/file/files/file-5.40-seccomp-fstatat64-musl.patch @@ -10,12 +10,6 @@ sys/stat.h in musl does this: Counteract this with an #undef. Bug: https://bugs.gentoo.org/789336 ---- - src/seccomp.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/seccomp.c b/src/seccomp.c -index 3318367c..eb8b1e57 100644 --- a/src/seccomp.c +++ b/src/seccomp.c @@ -179,6 +179,7 @@ enable_sandbox_full(void) @@ -26,6 +20,3 @@ index 3318367c..eb8b1e57 100644 ALLOW_RULE(fstatat64); #endif ALLOW_RULE(futex); --- -2.32.0 - diff --git a/sys-apps/file/files/file-5.42-unicode-fixes.patch b/sys-apps/file/files/file-5.42-unicode-fixes.patch new file mode 100644 index 000000000000..cc6ee7196b49 --- /dev/null +++ b/sys-apps/file/files/file-5.42-unicode-fixes.patch @@ -0,0 +1,390 @@ +https://bugs.gentoo.org/861089 +https://github.com/file/file/commit/19bf47777d0002ee884467e45e6ace702e40a4c1 +https://github.com/file/file/commit/c80065fe6900be5e794941e29b32440e9969b1c3 +https://github.com/file/file/commit/7e59d34206d7c962e093d4239e5367a2cd8b7623 +https://github.com/file/file/commit/f042050f59bfc037677871c4d1037c33273f5213 +https://github.com/file/file/commit/d471022b2772071877895759f209f2c346757a4c +https://github.com/file/file/commit/441ac2b15508909e82ad467960df4ac0adf9644c + +From 19bf47777d0002ee884467e45e6ace702e40a4c1 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 4 Jul 2022 17:00:51 +0000 +Subject: [PATCH] PR/358: Fix width for -f - (jpalus) + +--- a/src/file.c ++++ b/src/file.c +@@ -506,35 +506,47 @@ unwrap(struct magic_set *ms, const char *fn) + size_t llen = 0; + int wid = 0, cwid; + int e = 0; ++ size_t fi = 0, fimax = 100; ++ char **flist = malloc(sizeof(*flist) * fimax); + +- if (strcmp("-", fn) == 0) { ++ if (flist == NULL) ++out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); ++ ++ if (strcmp("-", fn) == 0) + f = stdin; +- wid = 1; +- } else { ++ else { + if ((f = fopen(fn, "r")) == NULL) { + file_warn("Cannot open `%s'", fn); + return 1; + } +- +- while ((len = getline(&line, &llen, f)) > 0) { +- if (line[len - 1] == '\n') +- line[len - 1] = '\0'; +- cwid = file_mbswidth(ms, line); +- if (cwid > wid) +- wid = cwid; +- } +- +- rewind(f); + } + + while ((len = getline(&line, &llen, f)) > 0) { + if (line[len - 1] == '\n') + line[len - 1] = '\0'; +- e |= process(ms, line, wid); ++ if (fi >= fimax) { ++ fimax += 100; ++ char **nf = realloc(flist, fimax * sizeof(*flist)); ++ if (nf == NULL) ++ goto out; ++ } ++ flist[fi++] = line; ++ cwid = file_mbswidth(ms, line); ++ if (cwid > wid) ++ wid = cwid; ++ line = NULL; ++ llen = 0; ++ } ++ ++ fimax = fi; ++ for (fi = 0; fi < fimax; fi++) { ++ e |= process(ms, flist[fi], wid); ++ free(flist[fi]); + } ++ free(flist); + +- free(line); +- (void)fclose(f); ++ if (f != stdin) ++ (void)fclose(f); + return e; + } + + +From c80065fe6900be5e794941e29b32440e9969b1c3 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 4 Jul 2022 19:44:35 +0000 +Subject: [PATCH] PR/362: ro-ee: fix wide char printing + +--- a/src/file.c ++++ b/src/file.c +@@ -60,6 +60,12 @@ FILE_RCSID("@(#)$File: file.c,v 1.196 2022/07/04 17:00:51 christos Exp $") + #ifdef HAVE_WCTYPE_H + #include + #endif ++#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \ ++ defined(HAVE_WCTYPE_H) ++#define FILE_WIDE_SUPPORT ++#else ++#include ++#endif + + #if defined(HAVE_GETOPT_H) && defined(HAVE_STRUCT_OPTION) + # include +@@ -550,6 +556,55 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); + return e; + } + ++private void ++file_octal(unsigned char c) ++{ ++ putc('\\', stdout); ++ putc(((c >> 6) & 7) + '0', stdout); ++ putc(((c >> 3) & 7) + '0', stdout); ++ putc(((c >> 0) & 7) + '0', stdout); ++} ++ ++private void ++fname_print(const char *inname) ++{ ++ size_t n = strlen(inname); ++#ifdef FILE_WIDE_SUPPORT ++ mbstate_t state; ++ wchar_t nextchar; ++ size_t bytesconsumed; ++ ++ ++ (void)mbrlen(NULL, 0, &state); ++ while (n > 0) { ++ bytesconsumed = mbrtowc(&nextchar, inname, n, &state); ++ if (bytesconsumed == CAST(size_t, -1) || ++ bytesconsumed == CAST(size_t, -2)) { ++ nextchar = *inname; ++ bytesconsumed = 1; ++ } ++ inname += bytesconsumed; ++ n -= bytesconsumed; ++ if (iswprint(nextchar)) { ++ putwc(nextchar, stdout); ++ continue; ++ } ++ /* XXX: What if it is > 255? */ ++ file_octal(CAST(unsigned char, nextchar)); ++ } ++#else ++ size_t i; ++ for (i = 0; i < n; i++) { ++ unsigned char c = CAST(unsigned char, inname[i]); ++ if (isprint(c)) { ++ putc(c); ++ continue; ++ } ++ file_octal(c); ++ } ++#endif ++} ++ + /* + * Called for each input file on the command line (or in a list of files) + */ +@@ -559,15 +614,13 @@ process(struct magic_set *ms, const char *inname, int wid) + const char *type, c = nulsep > 1 ? '\0' : '\n'; + int std_in = strcmp(inname, "-") == 0; + int haderror = 0; +- size_t plen = 4 * wid + 1; +- char *pbuf, *pname; +- +- if ((pbuf = CAST(char *, malloc(plen))) == NULL) +- file_err(EXIT_FAILURE, "Can't allocate %zu bytes", plen); + + if (wid > 0 && !bflag) { +- pname = file_printable(ms, pbuf, plen, inname, wid); +- (void)printf("%s", std_in ? "/dev/stdin" : pname); ++ const char *pname = std_in ? "/dev/stdin" : inname; ++ if ((ms->flags & MAGIC_RAW) == 0) ++ fname_print(pname); ++ else ++ (void)printf("%s", pname); + if (nulsep) + (void)putc('\0', stdout); + if (nulsep < 2) { +@@ -586,7 +639,6 @@ process(struct magic_set *ms, const char *inname, int wid) + } + if (nobuffer) + haderror |= fflush(stdout) != 0; +- free(pbuf); + return haderror || type == NULL; + } + +@@ -594,35 +646,33 @@ protected size_t + file_mbswidth(struct magic_set *ms, const char *s) + { + size_t width = 0; +-#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \ +- defined(HAVE_WCTYPE_H) +- size_t bytesconsumed, old_n, n; ++#ifdef FILE_WIDE_SUPPORT ++ size_t bytesconsumed, n; + mbstate_t state; + wchar_t nextchar; +- (void)memset(&state, 0, sizeof(mbstate_t)); +- old_n = n = strlen(s); ++ ++ (void)mbrlen(NULL, 0, &state); ++ n = strlen(s); + + while (n > 0) { + bytesconsumed = mbrtowc(&nextchar, s, n, &state); + if (bytesconsumed == CAST(size_t, -1) || + bytesconsumed == CAST(size_t, -2)) { +- /* Something went wrong, return something reasonable */ +- return old_n; ++ nextchar = *s; ++ bytesconsumed = 1; + } + width += ((ms->flags & MAGIC_RAW) != 0 + || iswprint(nextchar)) ? wcwidth(nextchar) : 4; + + s += bytesconsumed, n -= bytesconsumed; + } +- return width; + #else + while (*s) { + width += (ms->flags & MAGIC_RAW) != 0 + || isprint(CAST(unsigned char, *s)) ? 1 : 4; + } +- +- return strlen(s); + #endif ++ return width; + } + + private void +--- a/src/file.h ++++ b/src/file.h +@@ -575,7 +575,7 @@ protected size_t file_pstring_length_size(struct magic_set *, + const struct magic *); + protected size_t file_pstring_get_length(struct magic_set *, + const struct magic *, const char *); +-public char * file_printable(struct magic_set *, char *, size_t, ++protected char * file_printable(struct magic_set *, char *, size_t, + const char *, size_t); + #ifdef __EMX__ + protected int file_os2_apptype(struct magic_set *, const char *, const void *, +--- a/src/funcs.c ++++ b/src/funcs.c +@@ -763,7 +763,7 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) + /* + * convert string to ascii printable format. + */ +-public char * ++protected char * + file_printable(struct magic_set *ms, char *buf, size_t bufsiz, + const char *str, size_t slen) + { + +From 7e59d34206d7c962e093d4239e5367a2cd8b7623 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 4 Jul 2022 20:16:29 +0000 +Subject: [PATCH] Handle invalid characters as octal (idea from PR/363 by + dimich) + +--- a/src/file.c ++++ b/src/file.c +@@ -580,8 +580,11 @@ fname_print(const char *inname) + bytesconsumed = mbrtowc(&nextchar, inname, n, &state); + if (bytesconsumed == CAST(size_t, -1) || + bytesconsumed == CAST(size_t, -2)) { +- nextchar = *inname; +- bytesconsumed = 1; ++ nextchar = *inname++; ++ n--; ++ (void)mbrlen(NULL, 0, &state); ++ file_octal(CAST(unsigned char, nextchar)); ++ continue; + } + inname += bytesconsumed; + n -= bytesconsumed; +@@ -660,9 +663,12 @@ file_mbswidth(struct magic_set *ms, const char *s) + bytesconsumed == CAST(size_t, -2)) { + nextchar = *s; + bytesconsumed = 1; ++ (void)mbrlen(NULL, 0, &state); ++ width += 4; ++ } else { ++ width += ((ms->flags & MAGIC_RAW) != 0 ++ || iswprint(nextchar)) ? wcwidth(nextchar) : 4; + } +- width += ((ms->flags & MAGIC_RAW) != 0 +- || iswprint(nextchar)) ? wcwidth(nextchar) : 4; + + s += bytesconsumed, n -= bytesconsumed; + } + + +From f042050f59bfc037677871c4d1037c33273f5213 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 4 Jul 2022 22:30:51 +0000 +Subject: [PATCH] mbrlen(NULL, is not portable; revert to using memset to + initialize the state. + +--- a/src/file.c ++++ b/src/file.c +@@ -575,14 +575,14 @@ fname_print(const char *inname) + size_t bytesconsumed; + + +- (void)mbrlen(NULL, 0, &state); ++ (void)memset(&state, 0, sizeof(state)); + while (n > 0) { + bytesconsumed = mbrtowc(&nextchar, inname, n, &state); + if (bytesconsumed == CAST(size_t, -1) || + bytesconsumed == CAST(size_t, -2)) { + nextchar = *inname++; + n--; +- (void)mbrlen(NULL, 0, &state); ++ (void)memset(&state, 0, sizeof(state)); + file_octal(CAST(unsigned char, nextchar)); + continue; + } +@@ -654,7 +654,7 @@ file_mbswidth(struct magic_set *ms, const char *s) + mbstate_t state; + wchar_t nextchar; + +- (void)mbrlen(NULL, 0, &state); ++ (void)memset(&state, 0, sizeof(state)); + n = strlen(s); + + while (n > 0) { +@@ -663,7 +663,7 @@ file_mbswidth(struct magic_set *ms, const char *s) + bytesconsumed == CAST(size_t, -2)) { + nextchar = *s; + bytesconsumed = 1; +- (void)mbrlen(NULL, 0, &state); ++ (void)memset(&state, 0, sizeof(state)); + width += 4; + } else { + width += ((ms->flags & MAGIC_RAW) != 0 + + +From d471022b2772071877895759f209f2c346757a4c Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Tue, 5 Jul 2022 19:53:42 +0000 +Subject: [PATCH] Use printf("%lc") instead of putwc(). Somehow mixing wide and + narrow stdio does not work on Linux? + +--- a/src/file.c ++++ b/src/file.c +@@ -589,7 +589,7 @@ fname_print(const char *inname) + inname += bytesconsumed; + n -= bytesconsumed; + if (iswprint(nextchar)) { +- putwc(nextchar, stdout); ++ printf("%lc", nextchar); + continue; + } + /* XXX: What if it is > 255? */ + +From 441ac2b15508909e82ad467960df4ac0adf9644c Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Tue, 5 Jul 2022 20:05:23 +0000 +Subject: [PATCH] wcwidth is not supposed to return -1 if the character is + printable, but it does for 0xff... Prevent it from decreasing the width. + +--- a/src/file.c ++++ b/src/file.c +@@ -666,8 +666,9 @@ file_mbswidth(struct magic_set *ms, const char *s) + (void)memset(&state, 0, sizeof(state)); + width += 4; + } else { ++ int w = wcwidth(nextchar); + width += ((ms->flags & MAGIC_RAW) != 0 +- || iswprint(nextchar)) ? wcwidth(nextchar) : 4; ++ || iswprint(nextchar)) ? (w > 0 ? w : 1) : 4; + } + + s += bytesconsumed, n -= bytesconsumed; + +From be1ac8c0aa6d21921012f62582f51a9e546e4972 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Tue, 26 Jul 2022 15:10:05 +0000 +Subject: [PATCH] Fix bug with large flist (Florian Weimer) + +--- a/src/file.c ++++ b/src/file.c +@@ -535,6 +535,7 @@ out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); + char **nf = realloc(flist, fimax * sizeof(*flist)); + if (nf == NULL) + goto out; ++ flist = nf; + } + flist[fi++] = line; + cwid = file_mbswidth(ms, line); + -- cgit v1.2.3