Validating destination file paths
ERROR_INVALID_NAME = 123 ''' Windows-specific error code indicating an invalid pathname.
See Also ---------- https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85)Official listing of all such codes.
dirname = dirname(pathname) or os.getcwd() return os.access(dirname, os.
Passing pathnames residing in any other directory (and hence not guaranteed to exist) to are susceptible to Denial of Service (Do S) attacks and other black-hat shenanigans.
_, pathname = splitdrive(pathname) # Directory guaranteed to exist.
If the current OS is Windows, this is # the drive to which Windows was installed (e.g., the "%HOMEDRIVE%" # environment variable); else, the typical root directory.
Yes – unless we modify those pathnames to reside in existing directories. Shouldn't modifying a pathname prevent us from validating the original pathname? It reduces the larger problem of validating the full pathname in one fell swoop to the smaller problem of only validating all path components in that pathname.
To answer this question, recall from above that syntactically correct pathnames on the real-world filesystems of interest. Any arbitrary pathname is validatable (regardless of whether that pathname resides in an existing directory or not) in a cross-platform manner by following the following algorithm: Is there a directory guaranteed to exist?