public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* With bad UTF-8, cygwin can create files it can't read
@ 2015-03-25 15:26 Kyzer
  2015-03-30 11:16 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Kyzer @ 2015-03-25 15:26 UTC (permalink / raw)
  To: cygwin

Hello,

I've found that if you use cygwin to create a file with badly-encoded
UTF-8, readdir() gives out an entry with a name that cygwin won't
subsequently accept.

* create a file using filename with hex bytes F4 8F BF BF
* readdir() reports the filename as hex bytes E2 8E B3 ED BF BF
* attempting to open or unlink the filename E2 8E B3 ED BF BF fails
* attempting to open or unlink the filename F4 8F BF BF succeeds

Here's a test case. Beware that it will delete everything in the
current directory.

#include <stdio.h>
#include <dirent.h>
int main() {
  DIR *d;
  struct dirent *de;
  char *fname = "\xF4\x8F\xBF\xBF";

  // touch file
  fclose(fopen(fname, "wb"));

  // iterate through dir
  d = opendir(".");
  while ((de = readdir(d))) {
    if (de->d_name[0] == '.') continue;
    printf("unlink(%s) = %d\n", de->d_name, unlink(de->d_name));
  }
  closedir(d);

  // show that unlink works if you know the real filename
  printf("unlink(%s) = %d\n", fname, unlink(fname));
}

This outputs (piped through hexdump -C)

00000000  75 6e 6c 69 6e 6b 28 e2  8e b3 ed bf bf 29 20 3d  |unlink(......) =|
00000010  20 2d 31 0a 75 6e 6c 69  6e 6b 28 f4 8f bf bf 29  | -1.unlink(....)|
00000020  20 3d 20 30 0a                                    | = 0.|
00000025

e.g.

unlink(\xe2\x8e\xb3\xed\xbf\xbf) = -1
unlink(\xf4\x8f\xbf\xbf) = 0

This is with cygwin package 1.7.35

$ cygcheck -c cygwin
Cygwin Package Information
Package              Version        Status
cygwin               1.7.35-1       OK


WIndows / DOS does not have the problem:

c:\test\t>dir
 Volume in drive C has no label.
 Volume Serial Number is ....-....

 Directory of c:\test\t

25/03/2015  14:30    <DIR>          .
25/03/2015  14:30    <DIR>          ..
25/03/2015  14:30                 0 ??
               1 File(s)              0 bytes
               2 Dir(s)  39,906,525,184 bytes free

c:\test\t>del *
c:\test\t\*, Are you sure (Y/N)? y

c:\test\t>dir
 Volume in drive C has no label.
 Volume Serial Number is ....-....

 Directory of c:\test\t

25/03/2015  14:31    <DIR>          .
25/03/2015  14:31    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  39,906,525,184 bytes free

Regards
Stuart

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-01 16:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 15:26 With bad UTF-8, cygwin can create files it can't read Kyzer
2015-03-30 11:16 ` Corinna Vinschen
2015-04-01 13:34   ` Corinna Vinschen
2015-04-01 16:01     ` Warren Young
2015-04-01 16:16       ` Corinna Vinschen
2015-04-01 16:10     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).