iohook: Pressing Caps Lock with electron-v76-darwin-x64 crashes Electron App with no errors
Expected Behavior
Pressing of Caps Lock shouldn’t crash an electron app
Current Behavior
Pressing Caps Lock with electron-v76-darwin-x64 crashes Electron App with no errors
Steps to Reproduce (for bugs)
Not so many steps TBH. The error reproduces right after I import or require from iohook.
Then start an electron app - click on it to put window on focus and just press Caps Lock. The app will crash with no issues and logs even in debug mode.
Your Environment
- Version used:
"iohook": "^0.6.5" - Environment name and version (e.g. Chrome 39, node.js 5.4):
"electron": "^8.2.0",nodejs: 12.16.1 - Operating System and version (desktop or mobile): MacOS Catalina 10.15.4
From my own debugging I found out that issue is definitely within native code somewhere:
- As only import is enough to reproduce the issue - I blame IOHook constructor code at line
this.load(). Once I commented out code inloadmethod app wasn’t crash anymore but hooks didn’t work either. - I was trying to play within
this._handlermethod and place next code inside at the very beginning of the function to not perform any operation if it was Caps Lock.
if (msg.keyboard && msg.keyboard.keycode === 58) {
console.log('CAPS LOCK PRESSED');
return;
}
I saw the console printed CAPS LOCK PRESSED but app failed anyway so it’s not because of handler logic.
So that’s why I decided it is somewhere in native code and just for MacOS as I wasn’t able to reproduce the issue on Windows.
I’d be happy to hear from you guys and what I can do more in order to have further steps. Thank you.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 5
- Comments: 19 (8 by maintainers)
Alright, I had some unexpected free time on Monday / Tuesday and was able to get a fix in PR #108. I still need to do some more work fixing up some of the per-processor defines and other minor things, but it seems pretty stable. I am not sure if this library will be migrating to my upstream or continue the fork. If you are going to fork, the lines of interest are R476-R560 and possibly a few more bits near the top of the file.
The problem: Turns out this was related to the same random crashes the TIS keycode stuff was experiencing so I have it setup to run on the main runloop as long as you are on 10.6+. Fallback is kind of hacky for 10.5, but it works, doesn’t require OBJC or the main runloop.
Any code review would be appreciated. Let me know if there are any issues.
Together with @gtluszcz we have been investigating these crashes, as they are a deal breaker for us.
We have found, that the problem lays somewhere in this call specifically: https://github.com/wilix-team/iohook/blob/769daedd40bdf583c963d688aaaa81b137fda122/libuiohook/src/darwin/input_hook.c#L601
If you call this line, it doesn’t crash immediately, though. The program continues normally. After some short period of time, the app crashes.
I can only assume (with my limited macOS-APIs knowledge), that
event_refis accessed after it’s destroyed. On the other hand, the program crashes withSIGILL, notSEGFAULT. 🤷♀️I’ve noticed there were some changes in this function in the original repo (https://github.com/kwhat/libuiohook/blob/1.2/src/darwin/input_hook.c#L588-L592), however these changes do not fix the issue.
I’ve been able to reproduce this with:
masterat commit2297744node build.js --upload=false --runtime electron --version 11.2.3 --abi 85I’ve used
defano/hash-iohookrepo from @defano to reproduce.I can also reproduce using:
instead of requiring the
iohooknpm library itself, so the problem is definitely in the original package. I would report an issue there, however this is strictly problematic with Electron, as using it in pure node does not cause any problems.cc: @ash0x0 @kwhat
I’ve created a test case using one of Electron’s “Simple Samples”. To reproduce:
git clone git@github.com:defano/hash-iohook.gityarnyarn startAs noted in
package.jsonthis is based on Electron 8.4.0 and iohook 0.6.6. I am running macOS Catalina 10.15.5.This app is identical to the one posted here, https://www.electronjs.org/blog/simple-samples, except:
package.jsonconst iohook = require('iohook')toapp.js.Hope this helps–