"Segmentation fault: 11" on OSX 10.11.6 and XCode 8
node-scrypt 6.0.3 has been working fine for me until recently when I rebuilt my node_modules folder. I am now getting Segmentation fault errors when making scrypt calls.
The only change I can think of is that I installed Xcode 8 and am now seeing clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 message when installing.
I can replicate the problem when running the tests in the scrypt folder. The test crashes when making the var params = scrypt.paramsSync(1); call. Here is the output:
> [email protected] test /Users/me/test/node_modules/scrypt
> mocha tests/scrypt-tests.js
Scrypt Node Module Tests
Scrypt Params Function
Synchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a RangeError exception if maxtime argument is less than zero
✓ Will throw a TypeError exception if maxmem is not an integer
✓ Will throw a RangeError exception if maxmem is less than 0
✓ Will throw a RangeError exception if max_memfrac is not between 0.0 and 1.0
✓ Will throw a TypeError if any arguments are not numbers
Synchronous functionality with correct arguments
Segmentation fault: 11
Here is the output when using npm install to install scrypt:
npm WARN package.json [email protected] license should be a valid SPDX license expression
> [email protected] preinstall /Users/me/test/node_modules/scrypt
> node node-scrypt-preinstall.js
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
> [email protected] install /Users/me/test/node_modules/scrypt
> node-gyp rebuild
SOLINK_MODULE(target) Release/copied_files.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
CC(target) Release/obj.target/scrypt_wrapper/src/util/memlimit.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/keyderivation.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/pickparams.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/hash.o
LIBTOOL-STATIC Release/scrypt_wrapper.a
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/crypto/crypto_scrypt.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/crypto/crypto_scrypt_smix.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/util/warnp.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/alg/sha256.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/util/insecure_memzero.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/scryptenc/scryptenc_cpuperf.o
LIBTOOL-STATIC Release/scrypt_lib.a
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_common.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_params_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_params_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf-verify_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf-verify_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_hash_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_hash_async.o
CXX(target) Release/obj.target/scrypt/scrypt_node.o
SOLINK_MODULE(target) Release/scrypt.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
[email protected] node_modules/chai-as-promised
[email protected] node_modules/nan
[email protected] node_modules/chai
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])
[email protected] node_modules/mocha
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])
This might help you. I tried reinstalling and running the scrypt tests under node v6.8.0 (I was previously using v4.6.0) It crashes at the same place but the error message is a bit more informative:
dyld: lazy symbol binding failed: Symbol not found: _clock_getres
Referenced from: /Users/me/test/node_modules/scrypt/build/Release/scrypt.node
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _clock_getres
Referenced from: /Users/me/test/node_modules/scrypt/build/Release/scrypt.node
Expected in: /usr/lib/libSystem.B.dylib
Trace/BPT trap: 5
I'm also getting similar behaviour so would love to get some workarounds on this please
Hmmm - okay, I will take a look at it over the weekend...
While I do see the warning when using v6, compilation proceeds without error. Modules inherit this from node. AFAIK, as of v7 node links to libc++ instead of libstdc++. I suspect you'll see the same warning with other projects that use node-gyp (redis?) until you start using node v7 or Xcode 7. I don't see the warning when using node v7.
➜ *** git:(master) ✗ nvm use v6
Now using node v6.9.1 (npm v3.10.8)
➜ *** git:(master) ✗ cd node_modules/scrypt
➜ scrypt git:(master) ✗ npm i
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
> [email protected] preinstall ***/node_modules/scrypt
> node node-scrypt-preinstall.js
> [email protected] install ***/node_modules/scrypt
> node-gyp rebuild
SOLINK_MODULE(target) Release/copied_files.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
CC(target) Release/obj.target/scrypt_wrapper/src/util/memlimit.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/keyderivation.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/pickparams.o
CC(target) Release/obj.target/scrypt_wrapper/src/scryptwrapper/hash.o
LIBTOOL-STATIC Release/scrypt_wrapper.a
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/crypto/crypto_scrypt.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/crypto/crypto_scrypt_smix.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/util/warnp.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/alg/sha256.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/libcperciva/util/insecure_memzero.o
CC(target) Release/obj.target/scrypt_lib/scrypt/scrypt-1.2.0/lib/scryptenc/scryptenc_cpuperf.o
LIBTOOL-STATIC Release/scrypt_lib.a
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_common.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_params_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_params_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf-verify_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_kdf-verify_async.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_hash_sync.o
CXX(target) Release/obj.target/scrypt/src/node-boilerplate/scrypt_hash_async.o
CXX(target) Release/obj.target/scrypt/scrypt_node.o
SOLINK_MODULE(target) Release/scrypt.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
[email protected] ***/node_modules/scrypt
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
└── [email protected]
npm WARN [email protected] license should be a valid SPDX license expression
➜ scrypt git:(master) ✗ npm test
> [email protected] test ***/node_modules/scrypt
> mocha tests/scrypt-tests.js
Scrypt Node Module Tests
Scrypt Params Function
Synchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a RangeError exception if maxtime argument is less than zero
✓ Will throw a TypeError exception if maxmem is not an integer
✓ Will throw a RangeError exception if maxmem is less than 0
✓ Will throw a RangeError exception if max_memfrac is not between 0.0 and 1.0
✓ Will throw a TypeError if any arguments are not numbers
Synchronous functionality with correct arguments
✓ Should return a JSON object when only maxtime is defined
✓ Should return a JSON object when only maxtime and maxmem are defined
✓ Should return a JSON object when maxtime, maxmem and max_memfrac are defined
Asynchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a SyntaxError if no callback function is present
✓ Will throw a SyntaxError if callback function is the first argument present
✓ Will throw a RangeError exception if maxtime argument is less than zero
✓ Will throw a TypeError exception if maxmem is not an integer
✓ Will throw a RangeError exception if maxmem is less than 0
✓ Will throw a RangeError exception if max_memfrac is not between 0.0 and 1.0
✓ Will throw a TypeError if any arguments are not numbers
Asynchronous functionality with correct arguments
✓ Should return a JSON object when only maxtime is defined
✓ Should return a JSON object when only maxtime and maxmem are defined
✓ Should return a JSON object when maxtime, maxmem and max_memfrac are defined
Promise asynchronous functionality with correct arguments
✓ Should return a JSON object when only maxtime is defined
✓ Should return a JSON object when only maxtime and maxmem are defined
✓ Should return a JSON object when maxtime, maxmem and max_memfrac are defined
Scrypt KDF Function
Synchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw a TypeError if the Scrypt params object is incorrect
Synchronous functionality with correct arguments
✓ Will return a buffer object containing the KDF with a string input
Asynchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a SyntaxError if no callback function is present
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw a TypeError if the Scrypt params object is incorrect
Asynchronous functionality with correct arguments
✓ Will return a buffer object containing the KDF with a buffer input
Promise asynchronous functionality with correct arguments
✓ Will return a buffer object containing the KDF with a buffer input
Scrypt Hash Function
Create Hash
Synchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw a TypeError if the Scrypt params object is incorrect
✓ Will throw a TypeError if the hash length is not an integer
✓ Will throw a TypeError if the salt is not a string or a Buffer object
Synchronous functionality with correct arguments
✓ Will return a buffer object containing the hash with a string input
Asynchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a SyntaxError if no callback function is present
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw a TypeError if the Scrypt params object is incorrect
✓ Will throw a TypeError if the hash length is not an integer
✓ Will throw a TypeError if the salt is not a string or a Buffer object
Asynchronous functionality with correct arguments
✓ Will return a buffer object containing the hash with a string input
Promise asynchronous functionality with correct arguments
✓ Will return a buffer object containing the hash with a string input
Verify Hash
Synchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a TypeError if the KDF is not a string or a Buffer object
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw an Error if KDF buffer is not a valid scrypt-encrypted block
Synchronous functionality with correct arguments
✓ Will produce a boolean value (66ms)
Asynchronous functionality with incorrect arguments
✓ Will throw SyntexError exception if called without arguments
✓ Will throw a SyntaxError if no callback function is present
✓ Will throw a TypeError if the KDF is not a string or a Buffer object
✓ Will throw a TypeError if the key is not a string or a Buffer object
✓ Will throw an Error if KDF buffer is not a valid scrypt-encrypted block
Asynchronous functionality with correct arguments
✓ Will produce a boolean value (68ms)
Promise asynchronous functionality with correct arguments
✓ Will produce a boolean value (69ms)
Logic
Test vectors
Synchronous
✓ Vector 1: Will produce an identical vector to scrypt paper
✓ Vector 2: Will produce an identical vector to scrypt paper (46ms)
✓ Vector 3: Will produce an identical vector to scrypt paper (59ms)
Aynchronous
✓ Vector 1: Will produce an identical vector to scrypt paper
✓ Vector 2: Will produce an identical vector to scrypt paper (51ms)
✓ Vector 3: Will produce an identical vector to scrypt paper (58ms)
Kdf Logic
Synchronous
✓ Will use random salt to ensure no two KDFs are the same, even if the keys are identical (65ms)
✓ Will correctly verify hash as true if identical keys are used for kdf and verify (66ms)
✓ Will correctly verify hash as false if different keys are used for kdf and verify (66ms)
Asynchronous
✓ Will use random salt to ensure no two KDFs are the same, even if the keys are identical (67ms)
✓ Will correctly verify hash as true if identical keys are used for kdf and verify (69ms)
✓ Will correctly verify hash as false if different keys are used for kdf and verify (66ms)
Hash Logic
Synchronous
✓ Will be deterministic if salts are identical
Asynchronous
✓ Will be deterministic if salts are identical
73 passing (964ms)
I spent quite a lot of time looking into this 3 weeks back, and it looks like this is an issue affecting many modules where XCode 8 is running on El Capitan. The only fixes I found were to (a) downgrade Xcode 8 to Xcode 7, or (b) to upgrade to MacOS Sierra. I updated to Sierra and scrypt works fine now (tested under node 4.6.1 and 6.9.1).