by ChrisSD · 6y ago · 0 comments
I've seen this byte people when junk gets written to a filename (either accidentally or maliciously). Especially in shells but also in other programming languages. Issues that aren't always handled well include file names that:
* include a newline or some other control characters
* start with a `-`
* aren't valid UTF-8
Macs let you use "/" in file names, but instead used ":" as the path separation character.
It seemed to work fine and dandy at the time, until you ran "restore" and discovered your backups were corrupted!
https://en.wikipedia.org/wiki/GatorBox
https://news.ycombinator.com/item?id=20007875
Just for fun: guess what happens when you create a Mac file name with a slash in it today?
It works!
Or it seems to work. But behind the scenes, the Finder and Mac user interface libraries actually convert the "/" to a ":", which you can see with "ls". But at least it doesn't corrupt your backups!
Windows has many more restrictions. [1]
[1] https://kizu514.com/blog/forbidden-file-names-on-windows-10/
But yes, Windows reserves (16 bit encoded) ASCII control characters and some special symbols like question mark and colon.
As for . and .. I believe that on UNIX they are just symlinks, though they may be treated specially by applications? On Windows they don't really exist but some APIs emulate them when resolving paths.
No, they are treated specially by the kernel and/or the filesystem. They behave similar to hardlinks to the corresponding directory (hardlinks to directories aren't allowed nowadays, these two are an exception). The special treatment by applications is that many applications hide all files and directories starting with a dot, which happens to also apply to these two.
The other trick that makes dangerous operations always more safe is prepending "./" to the path.
It was the only directory starting that way, so I typed "rm -rf ~<TAB><ENTER>"
Hit control-C a half second later, but the damage was done. Fortunately most of my important files are backed up.
Lesson: when deleting files with tricky names, write the command without flags first, then add "-rf" after the path is confirmed correct.
Quite a few file systems require names to be valid text in a specific encoding, not arbitrary byte sequences.
Also, note the use of a plural in “the file systems in the path”. A file systems mounted in another one can change the rules halfway-through. There is not single fixed set of restrictions to file names.