[PATCH] iconvdata: IBM1390/IBM1399 encoders read past input bounds (bug 34914)
Andreas Schwab
schwab@suse.de
Thu Nov 12 15:09:30 GMT 2026
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) \
{ \
/* See if input is part of a combined character. */ \
uint32_t ch_next = get32 (inptr + 4); \
diff --git a/iconvdata/tst-iconv-ibm1390.c b/iconvdata/tst-iconv-ibm1390.c
new file mode 100644
index 0000000000..939588df0a
--- /dev/null
+++ b/iconvdata/tst-iconv-ibm1390.c
@@ -0,0 +1,65 @@
+/* Verify IBM1390/IBM1399 do not read past the input bounds.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <string.h>
+#include <errno.h>
+#include <iconv.h>
+
+#include <support/check.h>
+#include <support/next_to_fault.h>
+#include <support/support.h>
+
+static void
+test_ibm139x (const char *coding)
+{
+ /* Use WCHAR_T as input encoding so that the encoder reads directly from
+ the input buffer. */
+ iconv_t cd = iconv_open (coding, "WCHAR_T");
+ TEST_VERIFY_EXIT (cd != (iconv_t) -1);
+
+ /* Place a combining base one byte before the end of the buffer, to
+ check that the encoder does not read past the end of it. */
+ struct support_next_to_fault ntf = support_next_to_fault_allocate (9);
+ memcpy (ntf.buffer, L"a\x00E6", 8);
+ ntf.buffer[8] = 0;
+
+ char *inp = ntf.buffer;
+ size_t inleft = 9;
+
+ char outbuf[32];
+ char *outp = outbuf;
+ size_t outleft = sizeof (outbuf);
+
+ TEST_COMPARE (iconv (cd, &inp, &inleft, &outp, &outleft), (size_t) -1);
+ TEST_COMPARE (errno, EINVAL);
+ TEST_COMPARE (inleft, 1);
+ TEST_VERIFY (inp == ntf.buffer + 8);
+ TEST_COMPARE (iconv_close (cd), 0);
+ support_next_to_fault_free (&ntf);
+}
+
+static int
+do_test (void)
+{
+ test_ibm139x ("IBM1390");
+ test_ibm139x ("IBM1399");
+
+ return 0;
+}
+
+#include <support/test-driver.c>
--
2.56.1
--
Andreas Schwab, SUSE Labs, schwab@suse.de
More information about the Libc-alpha
mailing list