[COMMITTED 2.41] iconvdata: IBM1390/IBM1399 encoders read past input bounds (bug 34914)

Aurelien Jarno aurelien@aurel32.net
Fri Nov 27 21:41:45 GMT 2026


From: Andreas Schwab <schwab@suse.de>

Fix a bounds check when the IBM1390 and IBM1399 encoders look up the next
character after a combining base.

(cherry picked from commit 77fe280828e85ac329e5644e8546440e9c1b0453)
---
 NEWS                          |  3 ++
 iconvdata/Makefile            |  4 ++-
 iconvdata/ibm1364.c           |  2 +-
 iconvdata/tst-iconv-ibm1390.c | 65 +++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)
 create mode 100644 iconvdata/tst-iconv-ibm1390.c

diff --git a/NEWS b/NEWS
index 70682f415e..87ba87488e 100644
--- a/NEWS
+++ b/NEWS
@@ -54,6 +54,9 @@ The following bugs were resolved with this release:
   [34774] locale: ISO-2022-CN-EXT iconv decoder: SO byte without a
     designation advances the input pointer out of bounds
     (CVE-2026-121758)
+  [34914] locale: iconv: IBM1390/IBM1399 encoders read up to 3 bytes
+    past the input buffer when the last complete character is a
+    combining base (CVE-2026-124024)
   [34920] math: Bug in SVE pow and powf with mixed positive and negative
     base lanes with integer exponent
   [34922] math: AArch64: SVE tanf returns incorrect results when another
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index 36f48749d2..526f418c74 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -76,7 +76,7 @@ tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big tst-iconv4 bug-iconv4 \
 	tst-iconv6 bug-iconv5 bug-iconv6 tst-iconv7 bug-iconv8 bug-iconv9 \
 	bug-iconv10 bug-iconv11 bug-iconv12 tst-iconv-big5-hkscs-to-2ucs4 \
 	bug-iconv13 bug-iconv14 bug-iconv15 \
-	tst-iconv-iso-2022-cn-ext tst-bug33980 \
+	tst-iconv-ibm1390 tst-iconv-iso-2022-cn-ext tst-bug33980 \
 	tst-jisx0213-progress
 ifeq ($(have-thread-library),yes)
 tests += bug-iconv3
@@ -338,6 +338,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 244c61ad7a..3173b9f589 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 && inend - inptr >= 8)				      \
       {									      \
 	/* 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.53.0



More information about the Libc-stable mailing list