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

Can't read a file with readonly attribute #164

Closed
Kaplas80 opened this issue Feb 24, 2021 · 0 comments · Fixed by #165
Closed

Can't read a file with readonly attribute #164

Kaplas80 opened this issue Feb 24, 2021 · 0 comments · Fixed by #165

Comments

@Kaplas80
Copy link
Contributor

Describe the bug
Reading a DataStream from a readonly file throws a UnauthorizedAccessException.

Seems to happen only in Windows.

To Reproduce

            string tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            File.WriteAllBytes(tempFile, new byte[] { 0xCA, 0xFE, 0x00, 0xFF });
            File.SetAttributes(tempFile, FileAttributes.ReadOnly);

            Node node = NodeFactory.FromFile(tempFile);
            byte[] buffer = new byte[4];
            _ = node.Stream.Read(buffer, 0, 4);
            node.Dispose();

            File.SetAttributes(tempFile, FileAttributes.Normal);
            File.Delete(tempFile);

Expected behavior
It should read the file contents.

Exceptions

  Message: 
    System.UnauthorizedAccessException : Access to the path 'C:\Users\<removed>\AppData\Local\Temp\ojuirizr.zau' is denied.
  Stack Trace: 
    FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
    FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
    FileStream.ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
    FileStream.ctor(String path, FileMode mode, FileAccess access)
    LazyFileStream.Initialize() line 145
    LazyFileStream.Read(Byte[] buffer, Int32 index, Int32 count) line 86
    DataStream.Read(Byte[] buffer, Int32 offset, Int32 count) line 475
    NodeFactoryTests.ReadFromReadonlyFile() line 616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants