Permission denied when trying to create file from Slicer in most recent Nightly

I’m a little mystified why I can’t seem to save screenshots or other files on a recent nightly on Windows (4.13.0-2021-02-04). I wonder if this Slicer version has been put into some kind of sandbox, but I’m not sure how to test that. After some experimentation, I have found that a minimal example which demonstrates the problem on my machine is to put the following at the python interactor prompt

f = open('c:/Users/mikeb/Documents/test.txt','w')

This works fine for me in 4.11.20200930, but fails with a “PermissionError [Errno 13]” on 4.13.0-2021-02-04. I think this demonstrates that the problem is not a permission setting on the folder itself (because then the stable Slicer release also wouldn’t have permission to write there).

Oddly, if I go further up the file hierarchy, both Slicer versions can create a file in “c:/tempslicer”, so it is also not the case that 4.13.0-2021-02-04 can’t create files anywhere.

I would appreciate any help, suggestions, or insight anyone can provide. This feels like a weird error and I’m not sure how to troubleshoot it.

I have no idea what can cause this, but very interesting.

  • Do you get the same error for any filenames in the Documents folder (test1.txt, test2.txt, …)?
  • Can you reproduce the issue in a subfolder (“c:/Users/mikeb/Documents/something/test.txt”)?
  • Do you run any antivirus software?
  • Does it make any difference if you set a different encoding (f = open('c:/Users/mikeb/Documents/test111.txt','w', encoding="latin1")?
  • You can trace all file access operations using Process Monitor to see if Slicer even gets to a system call and if any other software manipulates files in that folder.
  • Does it work if you install a new Slicer (e.g., latest Slicer Preview Release)?

This is the “Event Properties” of the Access Denied event pasted from ProcessMonitor (process is C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.13.0-2021-02-04\bin\SlicerApp-real.exe):

High Resolution Date & Time: 2/10/2021 5:35:34.7648711 PM
Event Class: File System
Operation: CreateFile
Result: ACCESS DENIED
Path: C:\Users\mikeb\Documents\test111.txt
TID: 9448
Duration: 0.0000197
Desired Access: Generic Write, Read Attributes
Disposition: OverwriteIf
Options: Synchronous IO Non-Alert, Non-Directory File
Attributes: N
ShareMode: Read, Write
AllocationSize: 0

I do not see anything obvious around this time in ProcessMonitor, but I’m also not sure what I’m looking for. There are a tremendous number of events recorded (100s of thousands in a few seconds). Searching for test111 finds only the single event.

The ProcessMonitor event shows that the Slicer properly requests opening the file but the system rejects the request. Since Windows typically does not block file applications like this (prevent a specific application from creating a file in a folder that is meant to be modified by the user), it is more likely that Avast sandboxes Slicer. It may be because Slicer Preview Releases are not signed (we only sign Slicer Stable Releases). You can try to uninstall Avast or disable real-time protection/sandbox/etc. features and see if it helps.

I don’t think you need antivirus on Windows 10 as the chances that a third-party software can stop something that slips through built-in protections are quite slim; but it is very likely that the antivirus will interfere with normal operation of your computer (slows it down and causes random failures).

Using ProcessMonitor is indeed enlightening. It shows you just how busy your computer is with millions of things even when you don’t do anything.

1 Like

Thanks @lassoan. It does appear to have been due to Avast. In the past, I have typically had Avast pop up a warning alert the first time I open a newly installed nightly version of Slicer, but I have always clicked been able to say “Run Anyway” and I think this has created an exception which allowed normal Slicer operation. I honestly don’t remember whether something like that warning came up this time, but if so, it appears that the same exception was not created this time. I could open and use Slicer normally, but it seems like it was sandboxed in some way to prevent creation of files in my Documents directory or below. When I turned off Avast temporarily and restarted the Slicer version that had not been able to save, the problem disappeared. I added the SlicerApp-real.exe exception for the new version to the list manually, and the problem has not recurred.

Thanks for your help.

1 Like