Author eryksun
Recipients CristiFati, eryksun, lars.gustaebel, paul.moore, steve.dower, tim.golden, zach.ware
Date 2019-04-05.12:59:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
_sanitize_windows_name() fails to translate the reserved control characters (0x01-0x1F) and backslash in names. 

What I've seen done in some cases (e.g. Unix network shares mapped to SMB) is to translate names using the private use area block, e.g. 0xF001 - 0xF07F. Windows has no problem with characters in this range in a filename. (Displaying these characters sensibly is another matter.) For Windows 10, this is especially useful since the Linux subsystem automatically translates this PUA block back to ASCII when accessing a Windows volume via drvfs. For example:

    C:\Temp\pua>python -q
    >>> import sys
    >>> sys.platform
    >>> name = ''.join(map(chr, range(0xf001, 0xf080)))
    >>> _ = open(name, 'w')
    >>> ^Z

    C:\Temp\pua>bash -c "python3 -q"
    >>> import os, sys
    >>> sys.platform
    >>> os.listdir()

Also, while _sanitize_windows_name() handles trailing dots, for some reason it overlooks trailing spaces. It also doesn't handle reserved DOS device names. The reserved names include NUL, CON, CONIN$, CONOUT$, AUX, PRN, COM[1-9], LPT[1-9], and these names plus zero or more spaces and possibly a dot or colon and any subsequent characters. For example:

    >>> os.path._getfullpathname('con')
    >>> os.path._getfullpathname('con  ')
    >>> os.path._getfullpathname('con:')
    >>> os.path._getfullpathname('con :')
    >>> os.path._getfullpathname('con : spam')
    >>> os.path._getfullpathname('con . eggs')

It's not a reserved device name if the first character after zero or more spaces is not a dot or colon. For example:

    >>> os.path._getfullpathname('con spam')
    'C:\\con spam'

We can create filenames with reserved device names or trailing spaces and dots by using a \\?\ prefixed path (i.e. a non-normalized device path). However, most programs don't use \\?\ paths, so it's probably better to translate these names.
Date User Action Args
2019-04-05 12:59:15eryksunsetrecipients: + eryksun, paul.moore, lars.gustaebel, tim.golden, zach.ware, steve.dower, CristiFati
2019-04-05 12:59:15eryksunsetmessageid: <>
2019-04-05 12:59:15eryksunlinkissue36534 messages
2019-04-05 12:59:14eryksuncreate