-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
Invalid package error when there is asar path in the command passed to child_process.exec #5571
Comments
From the error information the whole command Before this is fixed you have to modify the module to use |
Hi @zcbenz , Thanks for your input. Using By looking at Electron's What do you think could be a real solution to this issue? Happy to work on it myself if you want. I can think of the following options right now:
The solution number 3 sounds like the most elegant one IMHO. |
Another potential workaround is to set |
@zcbenz I'm working on the patch by following the third mentioned approach, but identifying the parts of the command is not something we could accurately do, since splitting by white spaces doesn't consider cases like paths containing spaces. Some thoughts:
What do you think? I'm wondering if a better solution would be to accept a custom |
I think we can probably patch |
NodeJS implements `child_process.exec` by simply passing the whole command to `child_process.execFile`. See: - https://github.com/nodejs/node/blob/master/lib/child_process.js#L90 - https://github.com/nodejs/node/blob/master/lib/child_process.js#L99 Electron patches `child_process.execFile` to add support for `asar` archives by injecting logic that extracts the required files from the `asar` to a temporary location before delegating the work to the original `child_process.execFile`. In order to decide whether to inject the custom `asar` extracting logic, Electron makes use of a helper function called `splitPath()`. See: - https://github.com/electron/electron/blob/master/lib/common/asar.js#L37 If the first argument of the returned array equals `true`, means that the path is considered to be an `asar` archive, and thus the extraction logic takes place. The problem is that if the command passed to `child_process.execFile` *contains* a path to an asar archive, padded with other commands/arguments, `splitPath()` will consider it to be an `asar` archive, and will try to extract it, throwing a rightfully `Invalid package` error. Fixes: electron#5571 Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
I'm hitting this strange issue when using the
ELECTRON_RUN_AS_NODE=1
feature to run a script inside anasar
, which re-runs itself withchild_process.exec()
as part of an elevation routine provided by sudo-prompt.I've created a small snippet that reproduces the issue here. I tried creating a Gist, but it doesn't allow me to upload asar archives.
Installing the
npm
dependencies and runningnpm start
outputs the following:sudo-prompt
executes the following command:sudo -n -E /Users/jviotti/Projects/playground/electron-elevate-asar/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron /Users/jviotti/Projects/playground/electron-elevate-asar/app.asar/index.js
, which as you can see above, seems to originate the issue, however copy-pasting this command into my terminal succeeds without any problem.Basically, the elevation fails only then the command is executed from an electron process with
ELECTRON_RUN_AS_NODE
enabled.The
asar
archive is of course valid, since the original script wouldn't run from it otherwise.Some observations:
asar
.sudo -n -E electron app.asar/index.js
and we run it with NodeJS. Calling the same new file withELECTRON_RUN_AS_NODE=1 electron
exhibits the issue.The text was updated successfully, but these errors were encountered: