From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#42904: [PATCH] Non-Unicode frame title crashes Emacs on macOS Date: Tue, 18 Aug 2020 13:48:10 +0200 Message-ID: <243A5DA8-2865-485D-A8A2-1F543B046BAA@acm.org> References: <83lfidgtc7.fsf@gnu.org> <838sedgq2x.fsf@gnu.org> <02F52D43-7EAB-4E61-A567-E8CCD11D856B@acm.org> <20200817195610.GA70682@breton.holly.idiocy.org> <3F71EF82-A143-4E3A-AEF3-8A236091891D@acm.org> <20200818084306.GA89999@breton.holly.idiocy.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_24D051E2-E0BF-46A4-A406-355502745148" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25362"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 42904@debbugs.gnu.org To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 18 13:49:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k8074-0006Tr-H4 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Aug 2020 13:49:10 +0200 Original-Received: from localhost ([::1]:44720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8072-0003vG-Ss for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Aug 2020 07:49:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k806w-0003ur-EJ for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 07:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k806w-0005E6-5a for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 07:49:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k806w-0005wa-3A for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2020 07:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Aug 2020 11:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 42904-submit@debbugs.gnu.org id=B42904.159775130122801 (code B ref 42904); Tue, 18 Aug 2020 11:49:02 +0000 Original-Received: (at 42904) by debbugs.gnu.org; 18 Aug 2020 11:48:21 +0000 Original-Received: from localhost ([127.0.0.1]:34352 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k806H-0005vg-3N for submit@debbugs.gnu.org; Tue, 18 Aug 2020 07:48:21 -0400 Original-Received: from mail177c50.megamailservers.eu ([91.136.10.187]:50560 helo=mail51c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k806D-0005vU-QV for 42904@debbugs.gnu.org; Tue, 18 Aug 2020 07:48:19 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1597751294; bh=k0kQgH68HQ5N2IQWfZwEi8aHh+IYFlimNCo6op6AZng=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=MN09LCUwm5QMaLP3KsHjJZr0DkiGSUfhA19a6EAmb8Ucr8OaPrHUmnwYdQNga4WSM Sf+bKEHU+7dIeWuAwqkxJAHH/liTmx9YBMtqM4m/4ALvuxtvKiDdN050ZnEm0DbfGR RDa8QReodHtqPnB+Tid1EbRpNaGIczJWUkrvVJOY= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail51c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 07IBmAXL028334; Tue, 18 Aug 2020 11:48:13 +0000 In-Reply-To: <20200818084306.GA89999@breton.holly.idiocy.org> X-Mailer: Apple Mail (2.3445.104.15) X-CTCH-RefID: str=0001.0A782F27.5F3BBFFE.008C, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=MOMeZ/Rl c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=hIj89exaAAAA:8 a=94QdGpDQX0ZQNFkfVvsA:9 a=CjuIK1q_8ugA:10 a=aLiXyXexwL43tN057eoA:9 a=B2y7HmGcmWMA:10 a=lS9wXHQM5UdnNJ4u63Ry:22 X-Origin-Country: SE X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:185462 Archived-At: --Apple-Mail=_24D051E2-E0BF-46A4-A406-355502745148 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 18 aug. 2020 kl. 10.43 skrev Alan Third : >> Presumably this should be utf_16be on big-endian platforms. We still = support PowerPC macOS, don't we? >=20 > No, however I imagine we support GNUstep on big endian systems. Well then, it's easy to deal with. >>> + str =3D [NSString stringWithCharacters: (const unichar *) SDATA = (encoded_name) >>=20 >> Is SDATA guaranteed to be 16-bit aligned? Doesn't matter on x86 or >> PowerPC, but strictly speaking... >=20 > I've no idea, I adapted the code from make_multibyte_string in > alloc.c, and one of it's callers (although I can't remember which > right now). I'm expecting Eli to appear and tell me this is the > entirely wrong way of doing this. ;) Data alignment trapping is optional on 64-bit ARM but I'd be surprised = if macOS enabled it. It might be hazardous for all the GNUStep-on-MIPS = workstations. > Anyway, as I understand it the internal representation of NS strings > are UTF-16, so the conversion through UTF-8 seems a bit of a waste if > we can go direct. Maybe, but the conversion to UTF-16 then has to be done on the Emacs = side instead, probably less efficiently than in the NS libs. It's = probably a wash. Anyway, here is an alternative patch using your method. Tell us what you = think. --Apple-Mail=_24D051E2-E0BF-46A4-A406-355502745148 Content-Disposition: attachment; filename*0=0001-UTF-16-Fix-NS-crash-on-invalid-frame-title-string-bug-42904; filename*1=.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-UTF-16-Fix-NS-crash-on-invalid-frame-title-string-bug-42904.patch" Content-Transfer-Encoding: quoted-printable =46rom=209858f0409cc83eefcc153109e180c230868d20a5=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Tue,=2018=20Aug=202020=2012:58:12=20+0200=0A= Subject:=20[PATCH]=20Fix=20NS=20crash=20on=20invalid=20frame=20title=20= string=20(bug#42904)=0A=0AInstead=20of=20blindly=20assuming=20that=20all=20= Emacs=20strings=20are=20valid=20UTF-8,=0Awhich=20they=20are=20not,=20use=20= UTF-16=20because=20this=20conversion=20seems=20to=20be=0Amore=20robust=20= (after=20making=20sure=20that=20they=20use=20the=20correct=20replacement=0A= character).=20=20Unpaired=20surrogates=20will=20still=20go=20through=20= to=20the=20NSString=0Aobjects,=20but=20the=20NS=20libs=20handle=20them=20= gracefully.=0A=0A*=20src/nsfns.m=20(string_to_nsstring):=20New=20= function.=0A(ns_set_name_internal):=20Use=20string_to_nsstring.=0A*=20= lisp/international/mule-conf.el=20(utf-16le,=20utf-16be)=0A= (utf-16le-with-signature,=20utf-16be-with-signature,=20utf-16):=0AUse=20= U+FFFD=20as=20:default-char=20instead=20of=20ASCII=20space.=0A*=20= test/src/coding-tests.el=20(coding-utf-16-replacement-char):=20New=20= test.=0A---=0A=20lisp/international/mule-conf.el=20|=20=205=20+++++=0A=20= src/nsfns.m=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=2034=20+++++++++++++++++++--------------=0A=20test/src/coding-tests.el=20= =20=20=20=20=20=20=20|=2012=20++++++++++++=0A=203=20files=20changed,=20= 37=20insertions(+),=2014=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/international/mule-conf.el=20b/lisp/international/mule-conf.el=0A= index=20edda79ba4e..b9acafc158=20100644=0A---=20= a/lisp/international/mule-conf.el=0A+++=20= b/lisp/international/mule-conf.el=0A@@=20-1336,6=20+1336,7=20@@=20= 'utf-16le=0A=20=20=20:mnemonic=20?U=0A=20=20=20:charset-list=20= '(unicode)=0A=20=20=20:endian=20'little=0A+=20=20:default-char=20#xfffd=0A= =20=20=20:mime-text-unsuitable=20t=0A=20=20=20:mime-charset=20'utf-16le)=0A= =20=0A@@=20-1345,6=20+1346,7=20@@=20'utf-16be=0A=20=20=20:mnemonic=20?U=0A= =20=20=20:charset-list=20'(unicode)=0A=20=20=20:endian=20'big=0A+=20=20= :default-char=20#xfffd=0A=20=20=20:mime-text-unsuitable=20t=0A=20=20=20= :mime-charset=20'utf-16be)=0A=20=0A@@=20-1355,6=20+1357,7=20@@=20= 'utf-16le-with-signature=0A=20=20=20:charset-list=20'(unicode)=0A=20=20=20= :bom=20t=0A=20=20=20:endian=20'little=0A+=20=20:default-char=20#xfffd=0A=20= =20=20:mime-text-unsuitable=20t=0A=20=20=20:mime-charset=20'utf-16)=0A=20= =0A@@=20-1365,6=20+1368,7=20@@=20'utf-16be-with-signature=0A=20=20=20= :charset-list=20'(unicode)=0A=20=20=20:bom=20t=0A=20=20=20:endian=20'big=0A= +=20=20:default-char=20#xfffd=0A=20=20=20:mime-text-unsuitable=20t=0A=20=20= =20:mime-charset=20'utf-16)=0A=20=0A@@=20-1375,6=20+1379,7=20@@=20= 'utf-16=0A=20=20=20:charset-list=20'(unicode)=0A=20=20=20:bom=20= '(utf-16le-with-signature=20.=20utf-16be-with-signature)=0A=20=20=20= :endian=20'big=0A+=20=20:default-char=20#xfffd=0A=20=20=20= :mime-text-unsuitable=20t=0A=20=20=20:mime-charset=20'utf-16)=0A=20=0A= diff=20--git=20a/src/nsfns.m=20b/src/nsfns.m=0Aindex=20= 628233ea0d..e514585dc1=20100644=0A---=20a/src/nsfns.m=0A+++=20= b/src/nsfns.m=0A@@=20-398,29=20+398,35=20@@=20Turn=20the=20input=20menu=20= (an=20NSMenu)=20into=20a=20lisp=20list=20for=20tracking=20on=20lisp=20= side.=0A=20=20=20=20=20=20=20=20=20[NSString=20stringWithUTF8String:=20= SSDATA=20(arg)]];=0A=20}=0A=20=0A+static=20NSString=20*=0A= +string_to_nsstring=20(Lisp_Object=20string)=0A+{=0A+=20=20Lisp_Object=20= coding=20=3D=0A+#ifdef=20WORDS_BIGENDIAN=0A+=20=20=20=20Qutf_16be=0A= +#else=0A+=20=20=20=20Qutf_16le=0A+#endif=0A+=20=20=20=20;=0A+=20=20= Lisp_Object=20utf16=20=3D=20code_convert_string_norecord=20(string,=20= coding,=20true);=0A+=20=20/*=20Here=20we=20somewhat=20precariously=20= assume=20that=20SDATA=20is=2016-bit=20aligned,=0A+=20=20=20=20=20or=20= that=20unaligned=20access=20is=20OK.=20=20*/=0A+=20=20return=20[NSString=20= stringWithCharacters:=20(const=20unichar=20*)=20SDATA=20(utf16)=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20length:=20SBYTES=20(utf16)=20/=20sizeof=20(unichar)];=0A= +}=0A+=0A=20static=20void=0A=20ns_set_name_internal=20(struct=20frame=20= *f,=20Lisp_Object=20name)=0A=20{=0A-=20=20Lisp_Object=20encoded_name,=20= encoded_icon_name;=0A-=20=20NSString=20*str;=0A=20=20=20NSView=20*view=20= =3D=20FRAME_NS_VIEW=20(f);=0A-=0A-=0A-=20=20encoded_name=20=3D=20= ENCODE_UTF_8=20(name);=0A-=0A-=20=20str=20=3D=20[NSString=20= stringWithUTF8String:=20SSDATA=20(encoded_name)];=0A-=0A+=20=20NSString=20= *str=20=3D=20string_to_nsstring=20(name);=0A=20=0A=20=20=20/*=20Don't=20= change=20the=20name=20if=20it's=20already=20NAME.=20=20*/=0A=20=20=20if=20= (!=20[[[view=20window]=20title]=20isEqualToString:=20str])=0A=20=20=20=20= =20[[view=20window]=20setTitle:=20str];=0A=20=0A-=20=20if=20(!STRINGP=20= (f->icon_name))=0A-=20=20=20=20encoded_icon_name=20=3D=20encoded_name;=0A= -=20=20else=0A-=20=20=20=20encoded_icon_name=20=3D=20ENCODE_UTF_8=20= (f->icon_name);=0A-=0A-=20=20str=20=3D=20[NSString=20= stringWithUTF8String:=20SSDATA=20(encoded_icon_name)];=0A+=20=20if=20= (STRINGP=20(f->icon_name))=0A+=20=20=20=20str=20=3D=20string_to_nsstring=20= (f->icon_name);=0A=20=0A=20=20=20if=20([[view=20window]=20= miniwindowTitle]=0A=20=20=20=20=20=20=20&&=20!=20[[[view=20window]=20= miniwindowTitle]=20isEqualToString:=20str])=0Adiff=20--git=20= a/test/src/coding-tests.el=20b/test/src/coding-tests.el=0Aindex=20= c438ae22ce..8b0adf0ad8=20100644=0A---=20a/test/src/coding-tests.el=0A+++=20= b/test/src/coding-tests.el=0A@@=20-429,6=20+429,18=20@@=20= coding-check-coding-systems-region=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20'((iso-latin-1=203)=20(us-ascii=201=203))))=0A=20=20=20= (should-error=20(check-coding-systems-region=20"=C3=A5"=20nil=20= '(bad-coding-system))))=0A=20=0A+(ert-deftest=20= coding-utf-16-replacement-char=20()=0A+=20=20(should=20(equal=20= (encode-coding-string=20"A\351B"=20'utf-16be)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(unibyte-string=200=20?A=20#xff=20#xfd=200=20= ?B)))=0A+=20=20(should=20(equal=20(encode-coding-string=20"A\351B"=20= 'utf-16le)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (unibyte-string=20?A=200=20#xfd=20#xff=20?B=200)))=0A+=20=20(should=20= (equal=20(encode-coding-string=20"A\ud8b6B=CE=A3\227D=F0=9D=84=9E"=20= 'utf-16be)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (unibyte-string=200=20?A=20#xd8=20#xb6=200=20?B=20#x03=20#xa3=20#xff=20= #xfd=200=20?D=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20#xd8=20#x34=20#xdd=20#x1e)))=0A= +=20=20(should=20(equal=20(encode-coding-string=20"A\ud8b6B=CE=A3\227D=F0=9D= =84=9E"=20'utf-16le)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (unibyte-string=20?A=200=20#xb6=20#xd8=20?B=200=20#xa3=20#x03=20#xfd=20= #xff=20?D=200=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20#x34=20#xd8=20#x1e=20#xdd))))=0A= +=0A=20;;=20Local=20Variables:=0A=20;;=20byte-compile-warnings:=20(not=20= obsolete)=0A=20;;=20End:=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_24D051E2-E0BF-46A4-A406-355502745148--