From patchwork Mon Jun 10 13:33:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 91812 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B89D3858288 for ; Mon, 10 Jun 2024 13:34:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 933CC3858433 for ; Mon, 10 Jun 2024 13:33:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 933CC3858433 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 933CC3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718026420; cv=none; b=t2eiDqtbiea0tfqiuLCDD8qYtfar0PQlYxOjAtQdSjA0fW8MemJq+ZkB9z92Czg4Wwv1UDI8o+LSd9iVafii7WWv8RRF2r9akEcdGX++Nba1ys6iuoG5wKLoQ9waF1Xrugg2cdcQx7XRzGPDIy4RufYHt6Oukm1bG1HYRbpOwco= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718026420; c=relaxed/simple; bh=+u5smC1Zap6pqA99hLOaGiaZj0ZtfkVP0nRIL4sbjV4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=dk/yEqFkyK6aDz99DYQz9cg7BA8g4eM3CRhWb/kP16O5oatGCQBsnZohjF7HoJJu1WTPATn7WtptyNPYBO/t06yykj0w+g2NYREzXGaP4h2KG9FsLA1Vd7dtU6FCxBSumTQ8/NTQiBOr85RGo80+bRXl3NTXmi9pl7+b56IKZ88= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [10.168.4.11]) by smtp-out2.suse.de (Postfix) with ESMTP id 5B1031F7F3 for ; Mon, 10 Jun 2024 13:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718026416; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZLHncZh/cSVbsoXiiYtKRkDjrx6I26d5Nbjsofkhd6k=; b=SIyCrVYG+eLNZQgEkBTpePly3+3xUWrCeBfiXoF47KguMf6kTSMa3LabnB+3GnSABZAMaD 86ESctBzUGwe0lcJ6uQwfdPvE1EjWHAKbJKL3E7LXMLkTH47zxsnLKHsX4Xp7l8S7nXGt5 oB7JlznKMuJXl5ZKJJnAOz3J85GWaKY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718026416; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZLHncZh/cSVbsoXiiYtKRkDjrx6I26d5Nbjsofkhd6k=; b=KNefMSEmLoBUozvPL81wVjqIedYQJX0S5I+z2rYDBJHT/47J6IlTRn8lpUYDYbEVyEQyn5 LIzQd3GUuOnS2zAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718026415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZLHncZh/cSVbsoXiiYtKRkDjrx6I26d5Nbjsofkhd6k=; b=eF2d235ANaeTJqlqDml5W/rtFNLSlmg/8TuAPSdxBxApizv4mqFLZUdnjoa+0q1BFTYey3 mYJ9ja0VGgKMiTeFM4XL1/JzcGHweRVi4R1s9NFqmRX/3aoqfYL0X0ubtncZcMdTjgp1PV GXx1YbwhujdNZb1ljeUA7cr9upPGLmI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718026415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZLHncZh/cSVbsoXiiYtKRkDjrx6I26d5Nbjsofkhd6k=; b=GcvpVdI/rsd0QhqCvqF1S2wUee5CO+hZkLc/wzw6VPWWbyzUuHNRluROZzBZ9NaBtMSPjd kuvyMWfZyIstmMBA== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id 48CE94A0570; Mon, 10 Jun 2024 15:33:35 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH v2] iconv: Fix matching of multi-character transliterations (bug 31859) Date: Mon, 10 Jun 2024 15:33:35 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Score: -4.20 X-Spam-Level: X-Spamd-Result: default: False [-4.20 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[hawking.nue2.suse.org:helo, gnu.org:url, tst-translit-mchar.sh:url, suse.de:email, tst-iconv_prog.sh:url] X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Only return __GCONV_INCOMPLETE_INPUT for a partial match when the end of the input buffer is reached. Otherwise it is a non-match, and other patterns should be tried. --- iconv/Makefile | 13 ++++++++++ iconv/gconv_trans.c | 2 +- iconv/tst-translit-locale | 10 ++++++++ iconv/tst-translit-mchar.c | 47 ++++++++++++++++++++++++++++++++++++ iconv/tst-translit-mchar.sh | 48 +++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 iconv/tst-translit-locale create mode 100644 iconv/tst-translit-mchar.c create mode 100644 iconv/tst-translit-mchar.sh diff --git a/iconv/Makefile b/iconv/Makefile index 63afc853ff..e93322da85 100644 --- a/iconv/Makefile +++ b/iconv/Makefile @@ -57,6 +57,10 @@ tests = \ tst-iconv-opt \ # tests +test-srcs := \ + tst-translit-mchar \ + # test-srcs + others = iconv_prog iconvconfig install-others-programs = $(inst_bindir)/iconv install-sbin = iconvconfig @@ -73,6 +77,7 @@ include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left)) ifeq ($(run-built-tests),yes) xtests-special += $(objpfx)test-iconvconfig.out tests-special += $(objpfx)tst-iconv_prog.out +tests-special += $(objpfx)tst-translit-mchar.out endif # Make a copy of the file because gconv module names are constructed @@ -126,3 +131,11 @@ $(objpfx)tst-iconv_prog.out: tst-iconv_prog.sh $(objpfx)iconv_prog $(BASH) $< $(common-objdir) '$(test-wrapper-env)' \ '$(run-program-env)' > $@; \ $(evaluate-test) + +$(objpfx)tst-translit-mchar.out: tst-translit-mchar.sh \ + $(objpfx)tst-translit-mchar \ + tst-translit-locale + $(SHELL) $< $(common-objpfx) '$(run-program-prefix-before-env)' \ + '$(run-program-env)' '$(run-program-prefix-after-env)' \ + $< > $@; \ + $(evaluate-test) diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c index 08b7a3f71d..44f0fd849a 100644 --- a/iconv/gconv_trans.c +++ b/iconv/gconv_trans.c @@ -150,7 +150,7 @@ __gconv_transliterate (struct __gconv_step *step, /* Nothing found, continue searching. */ } - else if (cnt > 0) + else if (cnt > 0 && winbuf + cnt == winbufend) /* This means that the input buffer contents matches a prefix of an entry. Since we cannot match it unless we get more input, we will tell the caller about it. */ diff --git a/iconv/tst-translit-locale b/iconv/tst-translit-locale new file mode 100644 index 0000000000..712b08628a --- /dev/null +++ b/iconv/tst-translit-locale @@ -0,0 +1,10 @@ +# Test multi-character transliteration rule + +LC_CTYPE +copy "POSIX" + +translit_start +"ÄÄ" "AA" +translit_end + +END LC_CTYPE diff --git a/iconv/tst-translit-mchar.c b/iconv/tst-translit-mchar.c new file mode 100644 index 0000000000..b3e54db6a2 --- /dev/null +++ b/iconv/tst-translit-mchar.c @@ -0,0 +1,47 @@ +/* Test multi-character transliterations. + Copyright (C) 2024 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 + . */ + +#include +#include +#include +#include + +static int +do_test (void) +{ + iconv_t cd; + /* An input sequence with a common prefix with a transliteration rule. */ + char input[] = "\xc3\x84\xc3\x85"; + char *inptr = input; + char outbuf[10]; + char *outptr = outbuf; + size_t inlen = sizeof (input), outlen = sizeof (outbuf); + size_t n; + + xsetlocale (LC_CTYPE, "tst-translit"); + + cd = iconv_open ("ASCII//TRANSLIT", "UTF-8"); + TEST_VERIFY (cd != (iconv_t) -1); + + /* This call used to loop infinitely. */ + n = iconv (cd, &inptr, &inlen, &outptr, &outlen); + iconv_close (cd); + return n != 0; +} + +#include diff --git a/iconv/tst-translit-mchar.sh b/iconv/tst-translit-mchar.sh new file mode 100644 index 0000000000..79efd6abc8 --- /dev/null +++ b/iconv/tst-translit-mchar.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Testing of multi-character transliterations +# Copyright (C) 2024 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 +# . + +set -e + +common_objpfx=$1 +run_program_prefix_before_env=$2 +run_program_env=$3 +run_program_prefix_after_env=$4 + +# Generate data files. +${run_program_prefix_before_env} \ +${run_program_env} \ +I18NPATH=../localedata \ +${run_program_prefix_after_env} ${common_objpfx}locale/localedef \ +--quiet -i tst-translit-locale -f UTF-8 ${common_objpfx}iconv/tst-translit || ret=$? +if [ $ret -ne 1 ]; then + echo "FAIL: Locale compilation for tst-translit-locale failed (error $ret)." + exit 1 +fi + +set -x + +# Run the test. +${run_program_prefix_before_env} \ +${run_program_env} \ +LOCPATH=${common_objpfx}iconv \ +${run_program_prefix_after_env} ${common_objpfx}iconv/tst-translit-mchar + +# Local Variables: +# mode:shell-script +# End: