Closed
Description
- Version: 12.4.0
- Platform: Windows 10 x64 and Linux 4.4.0-042stab138.1
- Subsystem: crypto or deps
This code causes a segmentation fault in 12.4.0:
const crypto = require('crypto');
const fs = require('fs');
const myOwnCode = fs.createReadStream(__filename);
const copy = fs.createWriteStream(`${__filename}.copy`);
const hash = crypto.createHash('sha3-512');
myOwnCode.pipe(hash);
myOwnCode.pipe(copy).on('finish', () => {
hash.digest();
});
This seems to be caused by pipe
calling hash._flush
when end
is not set to false
. This code also causes a segmentation fault:
const crypto = require('crypto');
const hash = crypto.createHash('sha3-512');
hash._flush(() => console.log('Flushed'));
hash.digest();
This seems to be at least partially caused by the implementation of _flush
:
node/lib/internal/crypto/hash.js
Lines 54 to 57 in 908292c
It bypasses the this[kState][kFinalized]
safeguard:
node/lib/internal/crypto/hash.js
Lines 79 to 91 in 908292c
Note that this bug only happens when using SHA3, sha256
seems to be working just fine, so there might also be some weirdness in OpenSSL.
cc @mcollina @nodejs/crypto @nodejs/streams