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

symlink is - stateful? #27795

Closed
TanninOne opened this issue May 21, 2019 · 5 comments
Closed

symlink is - stateful? #27795

TanninOne opened this issue May 21, 2019 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@TanninOne
Copy link

Version: v11.6.0
Platform: Windows 10 (64bit)
Subsystem: fs

This is easiest to describe with sample code:

let shortPath = 'c:\\temp\\long pathname test';
undefined
let longPath = 'c:\\temp\\long pathname test\\01234567890123456789012345678901234567890123456789\\01234567890123456789012345678901234567890123456789\\01234567890123456789012345678901234567890123456789\\01234567890123456789012345678901234567890123456789\\01234567890123456789012345678901234567890123456789';
undefined
fs.symlinkSync(path.join(shortPath, 'foobar1.jpg'), path.join(longPath, 'foobar1.jpg'));
undefined
fs.symlinkSync(path.join(longPath, 'foobar2.jpg'), path.join(shortPath, 'foobar2.jpg'));
{ Error: EPERM: operation not permitted, symlink ...}
fs.unlinkSync(path.join(longPath, 'foobar1.jpg'))
undefined
fs.symlinkSync(path.join(shortPath, 'foobar1.jpg'), path.join(longPath, 'foobar1.jpg'));
{ Error: EPERM: operation not permitted, symlink ...}

Now there are a few oddities here
a) I can link from a short path to a long one (> MAX_PATH) but not the other way around
b) The error reported is EPERM for some reason, not ENAMETOOLONG or EINVAL
c) after that error has been reported, even the original call linking from short to long fails

c is the most scary of them because it indicates there is some global internal state that gets flipped and breaks all further calls? How does that make sense?

This is independent of the unlink call btw., this problem also happens if I remove the link outside node or if I use a third file.

@Fishrock123 Fishrock123 added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels May 22, 2019
@gireeshpunathil
Copy link
Member

@nodejs/platform-windows

@bzoz bzoz added the confirmed-bug Issues with confirmed bugs. label May 11, 2020
@bzoz
Copy link
Contributor

bzoz commented May 11, 2020

Reproduces with v14, similar code in plain libuv (two uv_fs_symlink calls) works as expected.

@jasnell
Copy link
Member

jasnell commented May 11, 2020

I do not think this is actually a bug but I think @bnoordhuis would have more context on it (see the old issue nodejs/node-v0.x-archive#6342 for example). Windows handles symlinks oddly and the reason you get an EPERM is that the security configuration actually blocks users from making symlinks in this case. If you change the paths to relative paths within the cwd, you'll find that the code just works and the symlinks are created. Attempt to do so outside of the cwd and it will fail with EPERM.

@TanninOne
Copy link
Author

No, it's not a security issue, this happens both when running as admin as well as running in developer mode which allows creation of symlinks with a regular account. As I've written, the error happens due to long paths, it was tested to work with short paths.

And none of that explains problem c, the fact that the function starts behaving differently after it failed once. That can't possibly be intended behavior.

@targos
Copy link
Member

targos commented May 11, 2020

It looks like #33351 might fix this.

bzoz added a commit to JaneaSystems/node that referenced this issue May 21, 2020
Use the namespaced (with the \\?\ prefix) paths for symlink targets when
the path is absolute. This allows creation of symlinks to files with
long filenames.

Fixes: nodejs#27795
@bzoz bzoz closed this as completed in a4e273b May 21, 2020
codebytere pushed a commit that referenced this issue Jun 18, 2020
Use the namespaced (with the \\?\ prefix) paths for symlink targets when
the path is absolute. This allows creation of symlinks to files with
long filenames.

Fixes: #27795

PR-URL: #33351
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
codebytere pushed a commit that referenced this issue Jul 8, 2020
Use the namespaced (with the \\?\ prefix) paths for symlink targets when
the path is absolute. This allows creation of symlinks to files with
long filenames.

Fixes: #27795

PR-URL: #33351
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants