From: Justin Tobler <jltobler@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] meson: detect broken iconv that requires ICONV_RESTART_RESET
Date: Mon, 9 Mar 2026 11:02:24 -0500 [thread overview]
Message-ID: <aa7pwTbyv8TT9WBB@denethor> (raw)
In-Reply-To: <20260305-pks-gitlab-ci-macos-16-v1-2-ce8da0ff29c2@pks.im>
On 26/03/05 12:20PM, Patrick Steinhardt wrote:
> In d0cec08d70 (utf8.c: prepare workaround for iconv under macOS 14/15,
> 2026-01-12) we have introduced a new workaround for a broken version of
> libiconv on macOS. This workaround has for now only been wired up for
> our Makefile, so using Meson with such a broken version will fail.
>
> We can rather easily detect the broken behaviour. Some encodings have
> different modes that can be switched to via an escape sequence. In the
> case of ISO-2022-JP this can be done via "<Esc>$B" and "<Esc>(J" to
> switch between ASCII and JIS modes. The bug now triggers when one does
> multiple calls to iconv(3p) to convert a string piece by piece, where
> the first call enters JIS mode. The second call forgets about the fact
> that it is still in JIS mode, and consequently it will incorrectly treat
> the input as ASCII, and thus the produced output is of course garbage.
>
> Wire up a test that exercises this in Meson and, if it fails, set the
> `ICONV_RESTART_RESET` define.
Makes sense.
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> meson.build | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/meson.build b/meson.build
> index ee3d9ced92..1b9be3d36c 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1060,6 +1060,32 @@ if iconv.found()
> ).returncode() != 0
> libgit_c_args += '-DICONV_OMITS_BOM'
> endif
> +
> + if compiler.run('''
> + #include <iconv.h>
> + #include <string.h>
> +
> + int main(int argc, const char *argv[])
> + {
> + char in[] = "\x1b\x24\x42\x24\x22\x24\x22\x1b\x28\x42", *inpos = in;
This appears to be the ISO-2022-JP encoded sequence that switches
between ASCII and JIS modes. Might we worth mentioning this in a
comment. :)
> + char out[7] = { 0 }, *outpos = out;
> + size_t insz = sizeof(in) - 1, outsz = 4;
> + iconv_t conv = iconv_open("UTF-8", "ISO-2022-JP");
> + if (!conv)
> + return 1;
> + if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) != (size_t) -1)
> + return 2;
> + outsz = sizeof(out) - (outpos - out);
> + if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) == (size_t) -1)
> + return 3;
Here we call iconv twice. If we have a bugged version of iconv, In the
second call we expect that it forgets the mode and returns garbage.
> + return strcmp("\343\201\202\343\201\202", out) ? 4 : 0;
This appears to be the expected UTF-8 string. If the output doesn't
match, it indicates we are encountering this bug.
> + }
> + ''',
> + dependencies: iconv,
> + name: 'iconv handles restarts properly',
> + ).returncode() != 0
Should we be more specific and expect the return code to be 4? It is my
understanding that these other scenarios would not be indicative of the
bug.
> + libgit_c_args += '-DICONV_RESTART_RESET'
> + endif
> endif
> else
> libgit_c_args += '-DNO_ICONV'
The check here looks good, but without the surrounding context, it is
not immediately obvious to me what we are trying to do. It would
probably be nice to leave some breadcrumbs for future readers.
-Justin
next prev parent reply other threads:[~2026-03-09 16:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 11:20 [PATCH 0/3] gitlab-ci: update to macOS 15 images Patrick Steinhardt
2026-03-05 11:20 ` [PATCH 1/3] meson: simplify iconv-emits-BOM check Patrick Steinhardt
2026-03-09 15:33 ` Justin Tobler
2026-03-05 11:20 ` [PATCH 2/3] meson: detect broken iconv that requires ICONV_RESTART_RESET Patrick Steinhardt
2026-03-09 16:02 ` Justin Tobler [this message]
2026-03-05 11:20 ` [PATCH 3/3] gitlab-ci: update to macOS 15 images Patrick Steinhardt
2026-03-09 16:04 ` Justin Tobler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa7pwTbyv8TT9WBB@denethor \
--to=jltobler@gmail.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox