From patchwork Wed Jun 12 08:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1946732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fHRFD/wm; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=22WQ7IRk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=fHRFD/wm; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=22WQ7IRk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzfQC4h4Mz20Pb for ; Wed, 12 Jun 2024 18:50:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E1EC3858416 for ; Wed, 12 Jun 2024 08:50:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 76BFA3858D34 for ; Wed, 12 Jun 2024 08:50:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76BFA3858D34 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 76BFA3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718182224; cv=none; b=Cx65yk5z7xeklprLY4SluF/EQx3C+q9bWxP4LAzyqhdaXmHGTtAG5gh1wHKGkmohEV7uw0X8h9DHl4KXrYYpUs2Ak2imYJVLyL+S9xbQ3tOchp4bC5JXFT/6I1RFpbIXyVHZGDsG6KAuxMcq/7Iu5R7GwmX50b2UcjMuAWbupCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718182224; c=relaxed/simple; bh=vDETFhsT/8CAYOe8V7KpAN6GzyeqDyZqT6etyNDlAG4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=hrt53UTiMQKpE9MEWY5hsAYZgqtRhl1WEGwdrulNYCu5dlJdvt1rQgfcyy+x0dhS7GpAe6AT5PNuMBlcPn4k6LZDkTsr19ddPZ8jCtsZ3Ti7ZWl0asUn9MvSXk6G3I4WlJwhDuekmgS/7+K56gjDVJC+gLSDTy3AvA4Ad7Q3Ye4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [10.168.4.11]) by smtp-out1.suse.de (Postfix) with ESMTP id 165DA34164 for ; Wed, 12 Jun 2024 08:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718182221; 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=q3/1wjGa54zjtbIjiLx2FFlvnCa2aP3jYVCJwQGvIkg=; b=fHRFD/wmv8Q1fZNUZwI8GNf6YYRRxioMUyYvQyzYephP4zDyQ1Ue/ryv10ffJot82qQWaP eQr3hjYpqzNr2J/X74SJPYQaeFWCiviEnWo7TVc7TmBQg9xI3rB/WrUPAdV+Ev21sDts6x 6BSGoq24nXtyNFyf05aOTVF5E1hFcGI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718182221; 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=q3/1wjGa54zjtbIjiLx2FFlvnCa2aP3jYVCJwQGvIkg=; b=22WQ7IRkKIiz93ENNO2MvQmnVHbu6D9p0hVlDq8mFNTFx5u6hKSCJ7yAo2XCAMteBGUpc0 FRS7C4eH2yYVESCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718182221; 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=q3/1wjGa54zjtbIjiLx2FFlvnCa2aP3jYVCJwQGvIkg=; b=fHRFD/wmv8Q1fZNUZwI8GNf6YYRRxioMUyYvQyzYephP4zDyQ1Ue/ryv10ffJot82qQWaP eQr3hjYpqzNr2J/X74SJPYQaeFWCiviEnWo7TVc7TmBQg9xI3rB/WrUPAdV+Ev21sDts6x 6BSGoq24nXtyNFyf05aOTVF5E1hFcGI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718182221; 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=q3/1wjGa54zjtbIjiLx2FFlvnCa2aP3jYVCJwQGvIkg=; b=22WQ7IRkKIiz93ENNO2MvQmnVHbu6D9p0hVlDq8mFNTFx5u6hKSCJ7yAo2XCAMteBGUpc0 FRS7C4eH2yYVESCg== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id 082994A0570; Wed, 12 Jun 2024 10:50:21 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] iconv: Fix matching of multi-character transliterations (bug 31859) X-Yow: I'm ANN LANDERS!! I can SHOPLIFT!! Date: Wed, 12 Jun 2024 10:50:21 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spamd-Result: default: False [-4.19 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.20)[-0.979]; 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)[suse.de:email] X-Spam-Score: -4.19 X-Spam-Level: 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+incoming=patchwork.ozlabs.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 | 48 +++++++++++++++++++++++++++++++++++++ iconv/tst-translit-mchar.sh | 48 +++++++++++++++++++++++++++++++++++++ 5 files changed, 120 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..72335976d6 --- /dev/null +++ b/iconv/tst-translit-mchar.c @@ -0,0 +1,48 @@ +/* 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 that shares 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); + TEST_VERIFY (iconv_close (cd) == 0); + 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: