From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#48902: 28.0.50; Directory names containing apostrophes and backticks cause problems Date: Tue, 8 Jun 2021 21:33:01 +0100 Message-ID: References: <51cb-60bf4900-1dd-2840bc80@23790836> <875yyoo9gy.fsf@gnus.org> <87r1hcmu2q.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="elxjuvetJJX+FCtm" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16117"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 48902@debbugs.gnu.org, Lars Ingebrigtsen , Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= , naofumi@yasufuku.dev To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 08 22:34:12 2021 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 1lqiQO-0003tP-DH for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Jun 2021 22:34:12 +0200 Original-Received: from localhost ([::1]:37294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqiQN-0002j2-Dl for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Jun 2021 16:34:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqiQE-0002cY-Br for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 16:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqiQE-0005gL-3T for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 16:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lqiQD-0005tv-S7 for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 16:34:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Jun 2021 20:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48902 X-GNU-PR-Package: emacs Original-Received: via spool by 48902-submit@debbugs.gnu.org id=B48902.162318439522628 (code B ref 48902); Tue, 08 Jun 2021 20:34:01 +0000 Original-Received: (at 48902) by debbugs.gnu.org; 8 Jun 2021 20:33:15 +0000 Original-Received: from localhost ([127.0.0.1]:59863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqiPT-0005su-Cs for submit@debbugs.gnu.org; Tue, 08 Jun 2021 16:33:15 -0400 Original-Received: from outbound.soverin.net ([116.202.65.218]:52163) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqiPQ-0005sb-HC for 48902@debbugs.gnu.org; Tue, 08 Jun 2021 16:33:14 -0400 Original-Received: from smtp.soverin.net (unknown [10.10.3.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 285A66062D; Tue, 8 Jun 2021 20:33:06 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.142]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1623184385; bh=cn4efAjRwl4PvQ6ySKU5Q+OUAGsZX47UGYnwM7PzOpM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P3UFtWmjS/PGoY+vaME/oykPx3OF7HRfpQVNwMoy4GSViHTVu2uY8gfLSA1LEcTxo 0J1oH3g/4c1NupgclJW20Uv1rYX//279JJ0gxwS2z7Z2Co0JeUtKRw0uIXFxhxwLqK o2Gt2bolfhVtzis12ooT/ivk8cbiklQEgnvzSQ4JYyh2XChWa3GIWjNnKK5TsA6HQe MUgeiobOxmj3U+T3ABuYGyFuuWYld+bJ3tm9q4zjYbooXEVXjMVAyvEUTPrJ5KtB88 UdeWVC5eInBwGFqgdjPMpl21zoytHnH8+hPw2e4l92d5tLjEveqDORrBNFrQnG8bpf Dm1eZ08MHTpGA== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.94.2) (envelope-from ) id 1lqiPF-001HQr-IW; Tue, 08 Jun 2021 21:33:01 +0100 Mail-Followup-To: Alan Third , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Lars Ingebrigtsen , naofumi@yasufuku.dev, 48902@debbugs.gnu.org, Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= Content-Disposition: inline In-Reply-To: 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:208266 Archived-At: --elxjuvetJJX+FCtm Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Jun 08, 2021 at 09:52:51PM +0200, Mattias Engdegård wrote: > 8 juni 2021 kl. 21.10 skrev Alan Third : > > > I think the attached should solve this. > > Thank you, that would work and I don't mind you pushing that right > away. We probably should clear up the encodedness of `file` in > allocInitFromFile: -- as Eli said, the convention is keeping strings > unencoded until needed by low-level operations and it really makes > the most sense. It's not just allocInitFromFile, I'm looking at the other callers of image_find_image_file and they all call ENCODE_FILE after it too. The only direct caller of image_find_image_fd that actually uses the contents of the returned string (svg_load) also encodes the file name. So I think we could restrict the use of the encoded filename within image_find_image_fd to *only* when it actually opens the file. Patch attached. I've tested it here but I only have a couple of images to try it with. I've been looking at the other changes I made in 747a923b9a35533f98573ad5b01fccf096195079 and I'm not sure they're correct. They clearly work now, but most of the time it's probably simple ASCII which should pass easily. Before they *all* seem to have assumed the data was UTF8 encoded, which is surely wrong since most of the time it's coming from Emacs. It's things like menu item titles. These are the use cases stringWithLispString was designed for, right? The only odd one is image filenames because they're explicitly encoded? -- Alan Third --elxjuvetJJX+FCtm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Fix-image-filename-encoding-issues-bug-48902.patch" >From 48763cfe123955173ad82085125b2f08295daa7d Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 8 Jun 2021 20:08:34 +0100 Subject: [PATCH v2] Fix image filename encoding issues (bug#48902) * src/image.c (image_find_image_fd): Don't return an encoded filename string. * src/nsfns.m: ([NSString stringWithLispString:]): Clarify usage comment. --- src/image.c | 19 ++++++++----------- src/nsfns.m | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/image.c b/src/image.c index b34dc3e916..d1aaaf8f53 100644 --- a/src/image.c +++ b/src/image.c @@ -3153,19 +3153,16 @@ image_find_image_fd (Lisp_Object file, int *pfd) /* Try to find FILE in data-directory/images, then x-bitmap-file-path. */ fd = openp (search_path, file, Qnil, &file_found, pfd ? Qt : make_fixnum (R_OK), false, false); - if (fd >= 0 || fd == -2) + if (fd == -2) { - file_found = ENCODE_FILE (file_found); - if (fd == -2) - { - /* The file exists locally, but has a file name handler. - (This happens, e.g., under Auto Image File Mode.) - 'openp' didn't open the file, so we should, because the - caller expects that. */ - fd = emacs_open (SSDATA (file_found), O_RDONLY, 0); - } + /* The file exists locally, but has a file name handler. + (This happens, e.g., under Auto Image File Mode.) + 'openp' didn't open the file, so we should, because the + caller expects that. */ + Lisp_Object encoded_name = ENCODE_FILE (file_found); + fd = emacs_open (SSDATA (encoded_name), O_RDONLY, 0); } - else /* fd < 0, but not -2 */ + else if (fd < 0) return Qnil; if (pfd) *pfd = fd; diff --git a/src/nsfns.m b/src/nsfns.m index d14f7b51ea..98801d8526 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -3024,7 +3024,8 @@ - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename } @implementation NSString (EmacsString) -/* Make an NSString from a Lisp string. */ +/* Make an NSString from a Lisp string. STRING must not be in an + encoded form (e.g. UTF-8). */ + (NSString *)stringWithLispString:(Lisp_Object)string { /* Shortcut for the common case. */ -- 2.30.2 --elxjuvetJJX+FCtm--