admin管理员组

文章数量:1322850

This question builds on a previous solution, where a method was requested to restrict R functions for use in an exam: Restrict R functions for an exam

The solution marked as accepted works very well. However, I have a follow-up question.

Currently, on Windows, pressing the TAB key triggers an error stating "utils:::.win32consoleCompletion is Forbidden," which causes the R console to close unexpectedly. While I am fine with disabling autocompletion, it is crucial that the R console does not close abruptly, as this would result in the loss of variables. For example, if a student prepares some variables and then accidentally presses TAB, they would lose all their work.

The .Rprofile of the linked answer is used. R.exe is started through a batch-file with the .Rprofile on the command line interface of Windows.

This question builds on a previous solution, where a method was requested to restrict R functions for use in an exam: Restrict R functions for an exam

The solution marked as accepted works very well. However, I have a follow-up question.

Currently, on Windows, pressing the TAB key triggers an error stating "utils:::.win32consoleCompletion is Forbidden," which causes the R console to close unexpectedly. While I am fine with disabling autocompletion, it is crucial that the R console does not close abruptly, as this would result in the loss of variables. For example, if a student prepares some variables and then accidentally presses TAB, they would lose all their work.

The .Rprofile of the linked answer is used. R.exe is started through a batch-file with the .Rprofile on the command line interface of Windows.

Share Improve this question edited Jan 21 at 12:52 Johannes Titz asked Jan 14 at 14:57 Johannes TitzJohannes Titz 1,0018 silver badges13 bronze badges 8
  • 1 This question should be self-contained, i.e. include the .Rprofile you're using - especially if you made the suggested changes to tighten access to the compiler package. Regarding how to disable autocomplete, you've mentioned the Safe Exam Browser but how are you accessing R in the browser? With an IDE? Also just to note I'm still sceptical of approach. While the accepted answer made R far more secure than I thought possible, a quick web search finds multiple ways to bypass Safe Exam Browser itself e.g. through opening it in a virtual machine and browsing the web on the main device. – SamR Commented Jan 14 at 15:41
  • I am not worried about SEB. There is practically no way to circumvent it with our approach, but this feels off topic so I will not go into details. I added the other information. – Johannes Titz Commented Jan 15 at 14:12
  • 1 I’m unable to provide a complete solution, but one approach would be to carefully add further exceptions to the allow-list, such as .win32consoleCompletion, until the errors go away. – Konrad Rudolph Commented Jan 15 at 15:15
  • 1 @KonradRudolph not sure it's safe. The call stack goes win32consoleCompletion -> pleteToken -> specialCompletions -> specialOpCompletionsHelper -> tryToEval -> eval. @JohannesTitz Which version of R are you using? A forbidden function being called shouldn't cause the R console to crash. There was a bug where any errors in this function would crash R that was reportedly fixed in R 4.2.3. – SamR Commented Jan 15 at 15:45
  • 2 @SamR You can disable the evaluation by having rc.settings(ops = FALSE) in your R profile. But I believe that that this instance of eval() is also safe: even if the user could inject arbitrary expressions here (and I don’t think they can!), the evaluation takes place in the global environment and therefore cannot run anything that the user couldn’t run anyway. – Konrad Rudolph Commented Jan 15 at 16:06
 |  Show 3 more comments

1 Answer 1

Reset to default 2

This is caused by a bug in earlier versions of R on Windows. Pressing TAB triggered a problem in utils:::.win32consoleCompletion(), which caused R to crash.

Essentially, the bug occurred because R wasn't able to gracefully catch certain errors during autocompletion. .win32consoleCompletion() was evaluated in a separate thread, which used incorrect stack start detection for overflow checks. R's error-handling mechanism wasn't able to reliably guard against long jumps caused by errors during autocompletion. This combination sometimes led to a stack overflow or invalid memory access, causing R to exit unexpectedly.

This has been fixed from R 4.2.2 and should be resolved simply by updating R. The fix ensures that autocompletion requests are routed through the main thread, using a dummy window for synchronisation and robust error handling. You can read the full details in an R Project blog post.

本文标签: Problem with Autocompletion in Restricted R Environments for Exams under WindowsStack Overflow