osx-sign icon indicating copy to clipboard operation
osx-sign copied to clipboard

MacOS x64 build failed while signing with Fatal JavaScript invalid size error with many extraResouces files/folders

Open KillerCodeMonkey opened this issue 1 year ago • 0 comments

I created an issue at electron-builder, but i debugged and invested time to nail it down and it seems it is an osx-sign issue:

Check: https://github.com/electron-userland/electron-builder/issues/8306

Long story short:

I have an angular app that i add as "extraResources" with electron builder to the electron app. There are many files in there, because i have a custom pdfjs version with all its files, e.g. many many cmaps.

Since osx-sign is going through all folder and files inside "Content" it reaches some limits and dies.

a little reproduction repo: https://github.com/fdk-app/electron-osx-sign-invalid-size-error its just an empty electron-vite project + the www-folder as extra resources. I added there only the assets of a library we use, which are more or less pdfjs, but i added the cmaps folder multiple times.

Signing dies directly after it starts - check the build github action at the repo.

remove some "cmaps" folders and it works.

The problem i see here is, that even i worked around in our production app for now, we will reach that point again because our angular app will grow as well.

Just a guess maybe it is that "isBinaryFile" check which is leading to that problem. it uses Buffer.alloc which allocs new space foreach file and since the walkfiles is running recursive and in parallel for each files it will easy explode.

https://github.com/electron/osx-sign/blob/main/src/util.ts#L153

BTW: this isBinaryFile library is running "stat" again.

A possible solution, but maybe breaks some other really really edge cases (some unknown file extensions/custom extensions or false/no extension) is to use some not that strict checks...

like just test file extensions: https://github.com/sindresorhus/is-binary-path

Or do not everything in parallel/run in batches this will slow down the signing a little bit, but maybe the garbage collector has the chance to clean things up in between.

Or batch and use isBinaryFile but pass the buffer on your own, so no additional stat call is done

KillerCodeMonkey avatar Jul 12 '24 05:07 KillerCodeMonkey