Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sus::fs and sus::path #385

Open
danakj opened this issue Sep 24, 2023 · 1 comment
Open

sus::fs and sus::path #385

danakj opened this issue Sep 24, 2023 · 1 comment
Labels
design Design of the library systems as a whole, such as concepts safety Memory safety improvements

Comments

@danakj
Copy link
Collaborator

danakj commented Sep 24, 2023

Paths in C++ are a mess.

Some pointers on Windows: https://mastodon.gamedev.place/@AshleyGullen/111109299141510319

std has file paths support but does weird things with operators, and unclear how well it handles windows. Maybe we can build on top of it for good compat.

The std filesystem functions work with paths instead of file objects so its extremely vulnerable to TOCTOU vulns/bugs and needs to be replaced with a port of the Rust apis.

@danakj danakj added design Design of the library systems as a whole, such as concepts safety Memory safety improvements labels Sep 24, 2023
@danakj
Copy link
Collaborator Author

danakj commented Sep 24, 2023

https://news.ycombinator.com/item?id=37632232

There is a note that TOCTOU problems in std filesystem actually causes UB internally.

I think some people might be wary of the std::filesystem APIs because the standard allows implementations to completely disregard TOCTOU issues internally, to the point of breaking memory safety [0]:

A file system race is the condition that occurs when multiple threads, processes, or computers interleave access and modification of the same object within a file system. Behavior is undefined if calls to functions provided by subclause [filesystems] introduce a file system race.

It's not just implementation-defined behavior, but full UB! You're utterly at the mercy of your implementation to do something reasonable when it encounters a TOCTOU issue, or, for that matter, any kind of concurrent modification to a file or directory. And C++ has a long history of implementations being unreliable in their behavior when UB is encountered.

[0] https://wg21.link/fs.race.behavior#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of the library systems as a whole, such as concepts safety Memory safety improvements
Projects
None yet
Development

No branches or pull requests

1 participant