libuv icon indicating copy to clipboard operation
libuv copied to clipboard

Stat functions throw EPERM for read-only / immutable files on Windows

Open aleksey-hoffman opened this issue 4 years ago • 12 comments

See the following issue for more information: https://github.com/nodejs/node/issues/35853

Node.js throws EPERM: operation not permitted, lstat for read-only / immutable files:

Windows 10:

> icacls E:\test.txt /deny "*S-1-1-0:(F)"
> node
> fs.lstatSync('E:\\test.txt')
Uncaught Error: EPERM: operation not permitted, lstat 'E:/test.txt'
    at Object.lstatSync (fs.js:1033:3) {
  errno: -4048,
  syscall: 'lstat',
  code: 'EPERM',
  path: 'E:/test.txt'
}

Windows Explorer and most low level languages (e.g. C++, C#) can read stats of such files without problems.

Can this be fixed on the Libuv end?

  • Version: All
  • Platform: Windows

aleksey-hoffman avatar Aug 06 '21 23:08 aleksey-hoffman

Maybe, pull requests welcome. The relevant code is here:

https://github.com/libuv/libuv/blob/04289fa326b790c1a4abb236d1f9d913bacfc8c6/src/win/fs.c#L1852-L1880

bnoordhuis avatar Aug 07 '21 09:08 bnoordhuis

@bnoordhuis thanks for the reply. I don't know C, so I wouldn't be able to do it properly myself.

If anyone else wants to attempt this, since it's Windows-only issue, you can try using Windows built-in kernel32.dll functions like getfileattributesexa or filesystem lib to get file info like attributes, size, dates, etc.

aleksey-hoffman avatar Aug 07 '21 09:08 aleksey-hoffman

The reason why it works on other languages is because they have a fallback for ERROR_ACCESS_DENIED Windows error code to gather less information (without opening a handle), libuv doesn't.

I went ahead and opened a pull request: https://github.com/libuv/libuv/pull/3268

Let me know what you guys think!

oluan avatar Aug 08 '21 18:08 oluan

@oluan dude, you are the best. Thank you!

aleksey-hoffman avatar Aug 08 '21 19:08 aleksey-hoffman

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 03 '21 02:09 stale[bot]

PR still open, bump

oluan avatar Sep 05 '21 16:09 oluan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 02 '21 01:10 stale[bot]

issue nodejs/node#35853 is still active so I think this one should also

resistcorp avatar Jan 28 '22 15:01 resistcorp

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 04:04 stale[bot]

PR still open, bump

oluan avatar Aug 12 '22 13:08 oluan

out of curiosity, why is the pr to fix this still open? are there some issues that make it dangerous not to gracefully handle things? this would help a lot of windows users of neo-tree.nvim

WillEhrendreich avatar Nov 09 '23 16:11 WillEhrendreich

Sounds like a neo-tree bug, failing to handle an expected error case for lstat on any platform. Unless you are going to fault the kernel also for having a security model that doesn't allow arbitrary users to gain root access.

vtjnash avatar Nov 09 '23 17:11 vtjnash