Skip to content

os string marshalling on Linux is inconsistent for unencodable characters #2070

Description

@slozier

On Linux, some of our os methods use .NET methods while others use Mono.Unix.Native.Syscall. For example, os.mkdir uses the .NET Directory.CreateDirectory, but os.stat uses Syscall.stat. It appears that the string marshalling used by .NET and Mono.Unix is different (only?) for unencodable characters. This causes unexpected exceptions:

import os
f = '\udcff'
os.mkdir(f)
os.stat(f) # raises FileNotFoundError
os.rmdir(f)

Similarly for other calls that use Syscall behind the scenes, such as os.open which uses Syscall.open.

I only tested this with .NET 10 on Linux so it's possible Mono doesn't have this issue? Note that during my testing Directory.CreateDirectory, Syscall.mkdir and the CPython (3.12) os.mkdir all created different folders for the \udcff filename. I'm just noting the difference with CPython because I noticed it, my main concern is incompatibility with our own os methods. Although in practice it's probably all irrelevant. 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions