-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Disallow reading directories as files #36605
Comments
Surprisingly I hit the same issue yesterday. In my case, the |
This should definitely error. |
We used to have an |
That is unfortunate. Perhaps we could check if it's a directory iff the file is size zero? I think a zero-size file can be determined when filling the initial buffer, so it should be very fast. It will, of course, slow down opening zero-size files that are actually files. |
You can do e.g.:
|
Consequence: julia> using TOML
julia> TOML.parsefile(homedir())
Dict{String, Any}() |
I'm pretty sure this is the branch that needs a special case: https://github.com/JuliaLang/julia/pull/35925/files#r509678679 |
Just a note that some filesystems (this is CephFS) allows reading directories:
|
This whole situation still seems pretty unfortunate to me. @vtjnash, how big a performance hit would it be to reinstate the explicit check for whether the thing we're opening is a directory and erroring when it is? |
But directories don't have zero size according to |
I think it's different notions of file size, Mose: e.g. And on file systems where directories are readable, Julia will read them, which is probably(?) the correct behaviour? It's what |
C and Go use very thin wrappers around read(2) and you get this EISDIR "is a directory" error. Julia's handling of all error codes is to set EOF: Lines 312 to 315 in bb5b98e
I suggest handling the error codes properly, then you won't need an explicit check before opening the file, and it will work properly with directories that are also readable as files. edit: I looked at this a bit more and there is an |
Assigning @vtjnash since he made the change that broke this 😁 |
Thinking on this more, I wonder if we could call faccessat on the new fd, and if that doesn't instantly fail (unlike fstat which slowly succeeded), then we know we accidentally opened a directory |
That would mean that julia couldn't read directories on filesystems where directories are readable (CephFS example above), which is probably better than the status quo, but (arguably) worse than perfect. |
Ran into this bug yesterday. |
Isn't it best to disallow reading as files (as done before?) and have a keyword-arg allowing it, the current default behavior? Since it might sometimes be useful: |
Right now, you can do:
That doesn't make much sense to me - presumably, attempting to read a directory is always a mistake, so we may as well error there. In fact, I discovered this because I accidentally read a directory and couldn't figure out why my program didn't give any output!
As a sanity check, Python refuses to do this:
The text was updated successfully, but these errors were encountered: