回复: [PATCH] iconvdata: IBM1390/IBM1399 encoders read past input bounds (bug 34914)
skyman wftw
skyman-wftw@hotmail.com
Wed Nov 18 00:46:25 GMT 2026
I have tested this patch as posted, with the one-line adjustment from
your follow-up discussion applied on top:
old: if (cmbp->res1 == ch && inptr + 8 <= inend) \
new: if (cmbp->res1 == ch && inend - inptr >= 8) \
Specifically: the patch from
https://sourceware.org/pipermail/libc-alpha/2026-November/182107.html
applied cleanly with git am on top of master (170ee485fa), plus the
guard change above as a second commit; the tree was otherwise clean.
Tested on x86_64-linux-gnu (Ubuntu 24.04, GCC 13.3.0), built from
that tree with --disable-werror:
make check subdirs=iconvdata
Results: tst-iconv-ibm1390 passes for both IBM1390 and IBM1399, and
the full iconvdata test suite shows no new failures (27 passed, 0
failed; tst-bug33980 among them).
A few observations on the edges of the new test and the guard change,
all reproduced with a small out-of-tree probe (WCHAR_T input, run
against both converters); no objections to the patch itself:
*
The new regression test does not assert successful-conversion
*
output: a combining base that is the last complete code point in
the buffer is consumed and written out as an individual character
*
U+00E6 alone becomes SO 0xd6 0x7b on both converters), and a
complete base+combining pair in a single call produces the combined
double-byte character (e.g. U+00E6 U+0300 becomes SO 0xec 0xc3 on
both converters).
*
With the guard in place, the combining base that ends a buffer is
*
still encoded as an individual character, so a combining character
arriving in the next iconv call cannot combine with it (the XXX
comment at the top of SUB_COMBINED_UCS_TO_IBM13XX; as Andreas put
it upthread, the character is "consumed but encoded as individual
*
What happens next depends on the character: a
split U+00E6 | U+0300 converts fine on the second call (U+0300 has
a standalone double-byte mapping, 0xea 0x51), while a split
U+304B | U+309A fails with EILSEQ on the second call with nothing
consumed (U+309A has no standalone mapping). This looks like a
pre-existing semantic gap rather than something introduced by
this patch.
Tested-by: JT Wang <skyman-wftw@hotmail.com>
________________________________
发件人: Florian Weimer <fweimer@redhat.com>
发送时间: 2026年11月12日 22:19
收件人: Andreas Schwab <schwab@suse.de>
抄送: libc-alpha@sourceware.org <libc-alpha@sourceware.org>
主题: Re: [PATCH] iconvdata: IBM1390/IBM1399 encoders read past input bounds (bug 34914)
* Andreas Schwab:
> Fix a bounds check when the IBM1390 and IBM1399 encoders look up the next
> character after a combining base.
> ---
> iconvdata/Makefile | 3 ++
> iconvdata/ibm1364.c | 2 +-
> iconvdata/tst-iconv-ibm1390.c | 65 +++++++++++++++++++++++++++++++++++
> 3 files changed, 69 insertions(+), 1 deletion(-)
> create mode 100644 iconvdata/tst-iconv-ibm1390.c
>
> diff --git a/iconvdata/Makefile b/iconvdata/Makefile
> index 8d12308c94..2abafa8b0a 100644
> --- a/iconvdata/Makefile
> +++ b/iconvdata/Makefile
> @@ -89,6 +89,7 @@ tests = \
> tst-bug33980 \
> tst-e2big \
> tst-iconv-big5-hkscs-to-2ucs4 \
> + tst-iconv-ibm1390 \
> tst-iconv-iso-2022-cn-ext \
> tst-iconv4 \
> tst-iconv6 \
> @@ -356,6 +357,8 @@ $(objpfx)tst-bug33980.out: $(addprefix $(objpfx), $(gconv-modules)) \
> $(addprefix $(objpfx),$(modules.so))
> $(objpfx)tst-jisx0213-progress.out: \
> $(addprefix $(objpfx), $(gconv-modules)) $(addprefix $(objpfx),$(modules.so))
> +$(objpfx)tst-iconv-ibm1390.out: $(addprefix $(objpfx), $(gconv-modules)) \
> + $(addprefix $(objpfx),$(modules.so))
>
> $(objpfx)iconv-test.out: run-iconv-test.sh \
> $(addprefix $(objpfx), $(gconv-modules)) \
> diff --git a/iconvdata/ibm1364.c b/iconvdata/ibm1364.c
> index 8df66ea048..6c10e8e1a8 100644
> --- a/iconvdata/ibm1364.c
> +++ b/iconvdata/ibm1364.c
> @@ -286,7 +286,7 @@ enum
> while (cmbp->res1 < ch) \
> ++cmbp; \
> /* XXX if last char is beginning of combining store in state */ \
> - if (cmbp->res1 == ch && inptr + 4 < inend) \
> + if (cmbp->res1 == ch && inptr + 8 <= inend) \
Please avoid out-of-bounds pointer arithmetic, given that you are
changing this line anyway. I think the condition should be:
cmbp->res1 == ch && inend - inptr >= 8
I wonder if
/* XXX if last char is beginning of combining store in state */ \
results in a hang with the right buffer boundaries because we never mage
forward progress? Or do we just produce the wrong output?
Thanks,
Florian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20261118/c8087ae2/attachment-0001.htm>
More information about the Libc-alpha
mailing list