emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#56469: closed (29.0.50; Unibyte dir in directory_files_internal)


From: GNU bug Tracking System
Subject: bug#56469: closed (29.0.50; Unibyte dir in directory_files_internal)
Date: Wed, 07 Sep 2022 13:33:02 +0000

Your message dated Wed, 07 Sep 2022 16:32:17 +0300
with message-id <83v8pzgvj2.fsf@gnu.org>
and subject line Re: bug#56469: 29.0.50; Unibyte dir in directory_files_internal
has caused the debbugs.gnu.org bug report #56469,
regarding 29.0.50; Unibyte dir in directory_files_internal
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
56469: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=56469
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 29.0.50; Unibyte dir in directory_files_internal Date: Sat, 09 Jul 2022 13:44:52 -0400
Package: Emacs
Version: 29.0.50


If you have a directory named "/tmp/\303a" with a file named "fée"
inside, then (directory-files "/tmp/\303a" 'full) is likely to return
a funny string which is multibyte but contains an invalid
utf-8 sequence (its bytes spell "/tmp/\303a/f\303\251e").
That strings seems to be printed as "/tmp/¡/fée" which corresponds
to "/tmp/\303\241/f\303\251e".

Such a string with an invalid UTF-8 sequence is handled quite graciously
by Emacs, so I wasn't able to get an actual crash out of it, but it's
still something we should avoid.

I suggest the patch below.  In a comment I suggest we don't try to use
unibyte strings when a multibyte string would work as well.  This is
because for those ASCII-only strings, it's cheaper to test bytes==chars
to (re)discover that they are ASCII-only (when they're multibyte) than
having to loop through the bytes (when they're unibyte).


        Stefan


diff --git a/src/dired.c b/src/dired.c
index 6bb8c2fcb9f..33ddfafd8e7 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -219,6 +219,13 @@ directory_files_internal (Lisp_Object directory, 
Lisp_Object full,
     }
 #endif
 
+  if (!NILP (full) && !STRING_MULTIBYTE (directory))
+    { /* We will be concatenating 'directory' with local file name.
+         We always decode local file names, so in order to safely concatenate
+         them we need 'directory' to be multibyte.  */
+      directory = Fstring_to_multibyte (directory);
+    }
+
   ptrdiff_t directory_nbytes = SBYTES (directory);
   re_match_object = Qt;
 
@@ -263,9 +270,10 @@ directory_files_internal (Lisp_Object directory, 
Lisp_Object full,
          ptrdiff_t name_nbytes = SBYTES (name);
          ptrdiff_t nbytes = directory_nbytes + needsep + name_nbytes;
          ptrdiff_t nchars = SCHARS (directory) + needsep + SCHARS (name);
-         finalname = make_uninit_multibyte_string (nchars, nbytes);
-         if (nchars == nbytes)
-           STRING_SET_UNIBYTE (finalname);
+         /* FIXME: Why not make them all multibyte?  */
+         finalname = (nchars == nbytes)
+                     ? make_uninit_string (nchars, nbytes)
+                     : make_uninit_multibyte_string (nchars, nbytes);
          memcpy (SDATA (finalname), SDATA (directory), directory_nbytes);
          if (needsep)
            SSET (finalname, directory_nbytes, DIRECTORY_SEP);




--- End Message ---
--- Begin Message --- Subject: Re: bug#56469: 29.0.50; Unibyte dir in directory_files_internal Date: Wed, 07 Sep 2022 16:32:17 +0300
> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,  56469@debbugs.gnu.org
> Date: Mon, 05 Sep 2022 21:21:36 +0200
> 
> Skimming this bug report lightly, it seems like the proposed patch was
> applied, but then the discussion continued.  It's not clear to me
> whether there's more to be done here -- should this report be closed?

Yes, I think so.  Done.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]