From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11023 Path: news.gmane.org!.POSTED!not-for-mail From: He X Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: a bug in bindtextdomain() and strip '.UTF-8' Date: Sat, 11 Feb 2017 14:00:56 +0800 Message-ID: References: <20170129133946.GT17692@port70.net> <20170129140747.GJ1533@brightrain.aerifal.cx> <20170129155507.GK1533@brightrain.aerifal.cx> <20170129163329.GL1533@brightrain.aerifal.cx> <20170208143147.GY1533@brightrain.aerifal.cx> <20170211023610.GA1520@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=001a1144a44e54b4f205483af187 X-Trace: blaine.gmane.org 1486792899 13736 195.159.176.226 (11 Feb 2017 06:01:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 11 Feb 2017 06:01:39 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11038-gllmg-musl=m.gmane.org@lists.openwall.com Sat Feb 11 07:01:32 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ccQkS-00030r-Pk for gllmg-musl@m.gmane.org; Sat, 11 Feb 2017 07:01:28 +0100 Original-Received: (qmail 25628 invoked by uid 550); 11 Feb 2017 06:01:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 25600 invoked from network); 11 Feb 2017 06:01:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=aFiOEPIUeccWatQXAAIEkI56cCgsXgH5j3s3U9y3Row=; b=RNvdjqwL4LCZEsGlc0wQgGg9xB/rT7QejTZbdDWaZJZZJeEyNF2VOuWNl3UELaHurW 1uAIuLdS8cK4U0bQ+9WjmcjIspXQD0Kyb/EfVO2EKqMzUn8fk5UAmw/uET03G8wZB2tP sToS+zMwF1ESi09tBw2JXaqUyWkDtVTbhmMd26lNE6GRDtetD/PlhvM/yHCixdwEnlwM OxlJx1NJiJM54WeOZExU8arA5ZxFxqRfyLj5F2TPdddMXTOg0DFM6XAwOUaor3AjWZlr t4ShhjQy6HglPGjdLiXRp2yxCV7ORtEvOI4+9HiijkL/+KlNnV+FJSkK9RHd/FxhvimA LzyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=aFiOEPIUeccWatQXAAIEkI56cCgsXgH5j3s3U9y3Row=; b=AGz/jrgPiV1JJUmHd4KGTtteCaE6/lxJNZjpSoxIbQwNVw1tuMTcIUDxlFCRtAjl23 STgaEnj1s1vWiDvz2CoOkpS3DA6QU/HBPrkI6mr86XTzNYo1MkwdOaBnfluM1JcIjlil 9U9PktneHnaZ72P+BSPQrcgKuzBoKprhm84TM1nNVT0K+g8gCXkuUgPuSptlRPlsW4iF Dzrfz0iSNq08EoTwZt36xeer0nKksWEdkbKZy9R7QVGSHfCFwNklvUBFXHS3+ZXp3CHk w3PTJSNTsgzQbRzJ4Ut56IWgg2xPZbHvmv39KNXDZ4yHL4pYPu4qvUI9K6MXtyqsnVC0 dzxA== X-Gm-Message-State: AMke39l2apPgtaq9q8GHlTcCAkGZA84gqn69Fg+4R1rw5T0CMKG6/QfQxB4KKSyK056nM9cbSZVh/1iYAurHUw== X-Received: by 10.31.51.68 with SMTP id z65mr6153347vkz.40.1486792877663; Fri, 10 Feb 2017 22:01:17 -0800 (PST) In-Reply-To: <20170211023610.GA1520@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:11023 Archived-At: --001a1144a44e54b4f205483af187 Content-Type: multipart/alternative; boundary=001a1144a44e54b4ed05483af185 --001a1144a44e54b4ed05483af185 Content-Type: text/plain; charset=UTF-8 fresh patch :) 1. It's easier that just stopping at dot, and i think this should be commented in the wiki or somewhere. 2. I read your first part of reply for 20mins, but im not sure; If i understand right, you mean, let the __locale_map* and strcut binding* be the id-card for msgcat list instead of the long name string, not only faster, but also more easy to construct pathname string. But there's some questions: + I removed name from msgcat, i can't find its use there, is it safe? + gettextdir() is replaced by a new loop, since i need the pointer of struct binding not only the dirname, but then, gettextdir() is only called by bindtextdomain(), is there a need to keep it? Or we have a better way to get the pointer of struct binding? + you said msgcat's indexed by ( struct __locale_map *, struct binding *, category ), but i found lm(locale_map) is located by category, so if category is different, then we can't get the same lm, so we can just compare lm, right? 2017-02-11 10:36 GMT+08:00 Rich Felker : > On Thu, Feb 09, 2017 at 05:49:13PM +0800, He X wrote: > > sry! > > > > 2017-02-08 22:31 GMT+08:00 Rich Felker : > > > > > On Wed, Feb 08, 2017 at 06:13:30PM +0800, He X wrote: > > > > here the patch is: http://paste.ubuntu.com/23953329/ > > > > The code tested, but maybe it sucks. > > > > > > Patches need to be attached and sent to the list, not pastebins that > > > might disappear. The latter don't work for discussing and preserving > > > discussion of the patch. > > > --- a/src/locale/dcngettext.c 2017-02-06 14:39:17.860482624 +0000 > > +++ b/src/locale/dcngettext.c 2017-02-06 14:39:17.860482624 +0000 > > @@ -19,6 +19,7 @@ > > }; > > > > static void *volatile bindings; > > +char *__strchrnul(const char *, int); > > > > static char *gettextdir(const char *domainname, size_t *dirlen) > > { > > @@ -143,7 +143,7 @@ > > > > catname = catnames[category]; > > catlen = catlens[category]; > > - loclen = strlen(locname); > > + loclen = __strchrnul(locname, '.') - locname; > > > > size_t namelen = dirlen+1 + loclen+1 + catlen+1 + domlen+3; > > char name[namelen+1], *s = name; > > @@ -157,6 +157,8 @@ > > +rewrite_loc: > > memcpy(s, locname, loclen); > > s[loclen] = '/'; > > s += loclen + 1; > > +skip_loc: > > memcpy(s, catname, catlen); > > s[catlen] = '/'; > > s += catlen + 1; > > @@ -174,7 +175,22 @@ > > void *old_cats; > > size_t map_size; > > const void *map = __map_file(name, &map_size); > > - if (!map) goto notrans; > > + if (!map) { > > + if (s = strchr(name + dirlen + 1, '@')) { > > + *s++ = '/'; > > + goto skip_loc; > > + } > > + if (locname && (s = strchr(name + dirlen + 1, > '_')) && (strchr(name + dirlen +1, '/') > s) ) { > > + if (locname = strchr(locname, '@')) { > > + loclen = __strchrnul(lm->name, > '.') - locname; > > + goto rewrite_loc; > > + } else { > > + *s++ = '/'; > > + goto skip_loc; > > + } > > + } > > + goto notrans; > > + } > > This doesn't work because it changes both the key used for the lookup > and the filename mapped. If you try this code with a translation that > requires a fallback, and run it under strace, you'll see that _every_ > call to gettext will try again to find the nonexistent files. > > It could be fixed, but I think the code should be refactored so that, > rather than the msgcat list being indexed by pathname strings, it's > indexed by tuples of: > > ( struct __locale_map *, struct binding *, category ) > > These are all integers/pointers and thus compare very fast versus the > current strcmp operation, and it's very quick to look them up. Then we > only have to construct the pathname string when a new file needs to be > loaded, not on every call, and you're free to clobber the pathname > string while doing fallbacks. > > > p = calloc(sizeof *p + namelen + 1, 1); > > if (!p) { > > __munmap((void *)map, map_size); > > --- a/src/locale/locale_map.c 2017-02-06 14:39:17.797148750 +0000 > > +++ b/src/locale/locale_map.c 2017-02-06 14:39:17.797148750 +0000 > > @@ -32,6 +32,7 @@ > > struct __locale_map *new = 0; > > const char *path = 0, *z; > > char buf[256]; > > + char *dotp; > > size_t l, n; > > > > if (!*val) { > > @@ -40,6 +41,12 @@ > > (val = getenv("LANG")) && *val || > > (val = "C.UTF-8"); > > } > > + if (dotp = strchr(val, '.')) { > > + char part[256]; > > + memcpy(part, val, dotp - val); > > + memcpy(&part[dotp - val], ".UTF-8\0", 7); > > + val = part; > > + } > > > > /* Limit name length and forbid leading dot or any slashes. */ > > for (n=0; n > I don't think this part is desirable, but if it were, it would need to > be done differently. As-is, it has serious UB, use of part[] after the > end of its lifetime. It also seems to have no check to see that > dotp-val is less than 256-7 or even that it's bounded, whereas the > code that immediately follows checks the length of the string pointed > to by val. > > I think what it should be doing is the opposite, stopping when hitting > a dot in the name and only using the part up to the dot, except in the > one special case "C.UTF-8". The subsequent path search for the locale > file should probably then be repeated with combinations of dropping > @mod and _CC suffixes, but this dropping should _not_ affect the name > that's saved and reported back. (That is, if LC_TIME=fr_CA but only a > "fr" locale file exists, the "fr" file should get mapped but the name > returned by setlocale, and saved for use by gettext, should still be > the full "fr_CA" in case applications have "fr_CA" translations.) > > Rich > --001a1144a44e54b4ed05483af185 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
fresh patch :)
1. It's easier that just stop= ping at dot, and i think this should be commented in the wiki or somewhere.=
2. I read your first part of reply for 20mins, but im not sure; If i u= nderstand right, you mean, let the __locale_map* and strcut binding* be the= id-card for msgcat list instead of the long name string, not only faster, = but also more easy to construct pathname string. But there's some quest= ions:
+ I removed name from msgcat, i can't find its use ther= e, is it safe?
+ gettextdir() is replaced by a new loop, since i = need the pointer of struct binding not only the dirname, but then, gettextd= ir() is only called by bindtextdomain(), is there a need to keep it? Or we = have a better way to get the pointer of struct binding?
+ you sai= d msgcat's indexed by=C2=A0=C2=A0( struct __locale_map *, struct bindin= g *, category ), but i found lm(locale_map) is located by category, so if c= ategory is different, then we can't get the same lm, so we can just com= pare lm, right?

2017-02-11 10:36 GMT+08:00 Rich Felker <dalias@libc.org>:
On Thu, Feb 09, 20= 17 at 05:49:13PM +0800, He X wrote:
> sry!
>
> 2017-02-08 22:31 GMT+08:00 Rich Felker <dalias@libc.org>:
>
> > On Wed, Feb 08, 2017 at 06:13:30PM +0800, He X wrote:
> > > here the patch is: http://paste.ubuntu.com/2395= 3329/
> > > The code tested, but maybe it sucks.
> >
> > Patches need to be attached and sent to the list, not pastebins t= hat
> > might disappear. The latter don't work for discussing and pre= serving
> > discussion of the patch.

> --- a/src/locale/dcngettext.c 2017-02-06 14:39:17.860482624 +00= 00
> +++ b/src/locale/dcngettext.c 2017-02-06 14:39:17.860482624 +0000
> @@ -19,6 +19,7 @@
>=C2=A0 };
>
>=C2=A0 static void *volatile bindings;
> +char *__strchrnul(const char *, int);
>
>=C2=A0 static char *gettextdir(const char *domainname, size_t *dirlen)<= br> >=C2=A0 {
> @@ -143,7 +143,7 @@
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0catname =3D catnames[category];
>=C2=A0 =C2=A0 =C2=A0 =C2=A0catlen =3D catlens[category];
> -=C2=A0 =C2=A0 =C2=A0loclen =3D strlen(locname);
> +=C2=A0 =C2=A0 =C2=A0loclen =3D __strchrnul(locname, '.') - lo= cname;
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t namelen =3D dirlen+1 + loclen+1 + cat= len+1 + domlen+3;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0char name[namelen+1], *s =3D name;
> @@ -157,6 +157,8 @@
> +rewrite_loc:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0memcpy(s, locname, loclen);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0s[loclen] =3D '/';
>=C2=A0 =C2=A0 =C2=A0 =C2=A0s +=3D loclen + 1;
> +skip_loc:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0memcpy(s, catname, catlen);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0s[catlen] =3D '/';
>=C2=A0 =C2=A0 =C2=A0 =C2=A0s +=3D catlen + 1;
> @@ -174,7 +175,22 @@
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0void *old_cats;<= br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t map_size;=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const void *map = =3D __map_file(name, &map_size);
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!map) goto notran= s;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!map) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0if (s =3D strchr(name + dirlen + 1, '@')) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*s++ =3D '/';
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto skip_loc;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0}
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0if (locname && (s =3D strchr(name + dirlen + 1, '_')= ) && (strchr(name + dirlen +1, '/') > s) ) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (locname =3D strchr(locname, '@&#= 39;)) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0loclen =3D _= _strchrnul(lm->name, '.') - locname;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto rewrite= _loc;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*s++ =3D = 9;/';
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto skip_lo= c;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0}
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0goto notrans;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}

This doesn't work because it changes both the key used for the lookup and the filename mapped. If you try this code with a translation that
requires a fallback, and run it under strace, you'll see that _every_ call to gettext will try again to find the nonexistent files.

It could be fixed, but I think the code should be refactored so that,
rather than the msgcat list being indexed by pathname strings, it's
indexed by tuples of:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 ( struct __locale_map *, struct binding *, cate= gory )

These are all integers/pointers and thus compare very fast versus the
current strcmp operation, and it's very quick to look them up. Then we<= br> only have to construct the pathname string when a new file needs to be
loaded, not on every call, and you're free to clobber the pathname
string while doing fallbacks.

>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D calloc(siz= eof *p + namelen + 1, 1);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!p) {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0__munmap((void *)map, map_size);
> --- a/src/locale/locale_map.c 2017-02-06 14:39:17.797148750 +0000
> +++ b/src/locale/locale_map.c 2017-02-06 14:39:17.797148750 +0000
> @@ -32,6 +32,7 @@
>=C2=A0 =C2=A0 =C2=A0 =C2=A0struct __locale_map *new =3D 0;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0const char *path =3D 0, *z;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0char buf[256];
> +=C2=A0 =C2=A0 =C2=A0char *dotp;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t l, n;
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!*val) {
> @@ -40,6 +41,12 @@
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(val =3D getenv(= "LANG")) && *val ||
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(val =3D "C= .UTF-8");
>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +=C2=A0 =C2=A0 =C2=A0if (dotp =3D strchr(val, '.')) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0char part[256];
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0memcpy(part, val, dot= p - val);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0memcpy(&part[dotp= - val], ".UTF-8\0", 7);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0val =3D part;
> +=C2=A0 =C2=A0 =C2=A0}
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Limit name length and forbid leading dot = or any slashes. */
>=C2=A0 =C2=A0 =C2=A0 =C2=A0for (n=3D0; n<LOCALE_NAME_MAX && = val[n] && val[n]!=3D'/'; n++);

I don't think this part is desirable, but if it were, it would need to<= br> be done differently. As-is, it has serious UB, use of part[] after the
end of its lifetime. It also seems to have no check to see that
dotp-val is less than 256-7 or even that it's bounded, whereas the
code that immediately follows checks the length of the string pointed
to by val.

I think what it should be doing is the opposite, stopping when hitting
a dot in the name and only using the part up to the dot, except in the
one special case "C.UTF-8". The subsequent path search for the lo= cale
file should probably then be repeated with combinations of dropping
@mod and _CC suffixes, but this dropping should _not_ affect the name
that's saved and reported back. (That is, if LC_TIME=3Dfr_CA but only a=
"fr" locale file exists, the "fr" file should get mappe= d but the name
returned by setlocale, and saved for use by gettext, should still be
the full "fr_CA" in case applications have "fr_CA" tran= slations.)

Rich

--001a1144a44e54b4ed05483af185-- --001a1144a44e54b4f205483af187 Content-Type: text/plain; charset=US-ASCII; name="locale.diff" Content-Disposition: attachment; filename="locale.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iz0u1ea90 LS0tIGEvc3JjL2xvY2FsZS9kY25nZXR0ZXh0LmMJMjAxNy0wMi0wNiAxNDozOToxNy44NjA0ODI2 MjQgKzAwMDAgCisrKyBiL3NyYy9sb2NhbGUvZGNuZ2V0dGV4dC5jCTIwMTctMDItMDYgMTQ6Mzk6 MTcuODYwNDgyNjI0ICswMDAwCkBAIC0xMDAsNyArMTAwLDggQEAKIAlzaXplX3QgbWFwX3NpemU7 CiAJdm9pZCAqdm9sYXRpbGUgcGx1cmFsX3J1bGU7CiAJdm9sYXRpbGUgaW50IG5wbHVyYWxzOwot CWNoYXIgbmFtZVtdOworCXN0cnVjdCBiaW5kaW5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