From: Stefan Monnier Date: Sun, 10 Jul 2022 14:13:27 +0000 (-0400) Subject: * src/dired.c (directory_files_internal): Fix bug#56469 X-Git-Tag: emacs-29.0.90~1447^2~1042 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=46a2e5dc93ccbb36309f859460cb527c91adc4d1;p=emacs.git * src/dired.c (directory_files_internal): Fix bug#56469 Avoid concatenating encoded and decoded file names. --- diff --git a/src/dired.c b/src/dired.c index 6bb8c2fcb9f..9aeff516369 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 decoded as well (bug#56469). */ + directory = DECODE_FILE (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 (nbytes) + : make_uninit_multibyte_string (nchars, nbytes); memcpy (SDATA (finalname), SDATA (directory), directory_nbytes); if (needsep) SSET (finalname, directory_nbytes, DIRECTORY_SEP);