Repository navigation
Crypto issues on Ubuntu 22.04 - Assertion `errors->Empty()' failed #42919
Description
Version
v16.15.0
Platform
Linux 99eba3b487e3 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
crypto/crypto_cipher.h:262:v8::Maybe node::crypto::CipherJob::ToResult(v8::Localv8::Value, v8::Localv8::Value)
What steps will reproduce the bug?
Test Script: <some_dir>/test/cryptoTest.js
// Test - See if we can do a basic example with 22.04 and node v16.15.0
// https://stackoverflow.com/questions/25725596/use-window-crypto-in-nodejs-code
const crypto = require('crypto').webcrypto;
var test = async () => {
let iv = crypto.getRandomValues(new Uint8Array(16));
let key = crypto.getRandomValues(new Uint8Array(16));
let data = new Uint8Array(12345);
//crypto functions are wrapped in promises so we have to use await and make sure the function that
//contains this code is an async function
//encrypt function wants a cryptokey object
data[1] = 1;
const key_encoded = await crypto.subtle.importKey( "raw", key.buffer, 'AES-CTR' , false, ["encrypt", "decrypt"]);
try{
await crypto.subtle.encrypt(
{
name: "AES-CTR",
counter: iv,
length: 128
},
key_encoded,
data
).then((result) => {
console.log(result);
}).catch((err) => {
console.error(err);
});
}
catch(err){
console.error(err);
}
console.log("done.");
}
test();Steps to setup:
docker run -v $(pwd)/test/:/test/ -ti ubuntu:jammy /bin/bash
# --- in container ---
apt update
# install node v16.15.0
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
bash /tmp/nodesource_setup.sh
apt install nodejs
node -v
# 16.15.0
node cryptoTest.js
# .... errors ....How often does it reproduce? Is there a required condition?
Reproducible only on Ubuntu 22.04, confirmed via host OS hard install and in docker for ubuntu 22.04 Jammy
What is the expected behavior?
When run in 20.04 (host OS and docker confirmed)
❯ node cryptoTest.js
ArrayBuffer {
[Uint8Contents]: <2d ec 99 71 e3 a6 41 2e 4b 65 d4 f8 38 57 f3 4b b5 cb cd e4 ab b9 77 d8 b8 ba aa aa 04 f5 1b e8 3a ec 2e a8 87 a8 c2 90 9a 84 32 af 60 c8 e4 3d eb 36 3f 4f 70 34 10 3a a2 02 08 ac 24 97 c8 d2 51 60 ff a7 3b 1c 26 c3 0f 4f d5 54 50 6e ad fc 84 35 65 61 15 cb 20 7f bf eb cf 76 05 27 a2 59 08 6d 45 37 ... 12245 more bytes>,
byteLength: 12345
}
done.What do you see instead?
When run in 22.04 (host OS and docker confirmed)
root@99eba3b487e3:/test# node cryptoTest.js
node[3554]: ../src/crypto/crypto_cipher.h:262:v8::Maybe<bool> node::crypto::CipherJob<CipherTraits>::ToResult(v8::Local<v8::Value>*, v8::Local<v8::Value>*) [with CipherTraits = node::crypto::AESCipherTraits]: Assertion `errors->Empty()' failed.
1: 0xb09c10 node::Abort() [node]
2: 0xb09c8e [node]
3: 0xc3e0f9 [node]
4: 0xad4095 node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*, int)#2}::_FUN(uv_work_s*, int) [node]
5: 0x156015d [node]
6: 0x1564936 [node]
7: 0x1577064 [node]
8: 0x1565288 uv_run [node]
9: 0xa43dd5 node::SpinEventLoop(node::Environment*) [node]
10: 0xb4bdb6 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [node]
11: 0xacd592 node::Start(int, char**) [node]
12: 0x7fd500651d90 [/lib/x86_64-linux-gnu/libc.so.6]
13: 0x7fd500651e40 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
14: 0xa4067c [node]
Aborted (core dumped)
root@99eba3b487e3:/test# ^CAdditional information
A quick mini example is based off:
https://stackoverflow.com/questions/25725596/use-window-crypto-in-nodejs-code
This issue was found in production code dealing with subtle, decrypt. The toy example is just to make the issue more concrete and easier to test. We are seeing this issue with other methods, AES-CTR, AES-GCM
Activity
HiveTechDev commentedon Apr 29, 2022
potentially related (similar error output) #38883
targos commentedon Apr 30, 2022
@nodejs/crypto
bnoordhuis commentedon May 3, 2022
@Koulwa can you try with the node binary from https://nodejs.org/ instead of the nodesource build? edit: please post the stack trace it prints, assuming it also fails.
HiveTechDev commentedon May 9, 2022
Sure thing. Same setup as before (Docker 22.04 jammy)
Heres's that output.
bnoordhuis commentedon May 10, 2022
Thanks. This indeed seems to be related to #38883. The fix from #38913 was applied to the CBC and GCM code paths but not CTR.
This check looks defective to me:
node/src/crypto/crypto_cipher.h
Lines 261 to 262 in ec1c616
It's saying "EITHER we have output and no errors OR no output and one or more errors" but there can be both output and errors, e.g., if if the final block isn't properly padded.
@nodejs/crypto do you concur?
majherek commentedon Jun 3, 2022
any solution?
leviwolfe commentedon Jun 15, 2022
I ran into this error on previously working code and found this issue. @Koulwa's cryptoTest.js script unfortunately crashes with the same Assertion `errors->Empty()' error for me on Windows 10 with node v16.15.1. Here is my stack trace if it helps:
HiveTechDev commentedon Jul 14, 2022
Any update on this?
xkid1 commentedon Aug 22, 2022
I have the same issue ubuntu 22.04
node: 16
tniessen commentedon Aug 23, 2022
I haven't been able to reproduce this on Ubuntu 20.04 or Ubuntu 22.04. Could you please post the output of
node -vandnode -p process.versionsanduname -a, as well as code that demonstrates the problem?xkid1 commentedon Aug 27, 2022
Please see attached picture
bnoordhuis commentedon Aug 27, 2022
@xkid1 Please try again with the latest v16.x release.
xkid1 commentedon Aug 28, 2022
I will try node:16.17.0,
then wait for may feedback
xkid1 commentedon Aug 28, 2022
@bnoordhuis node 16.17.0 is now working
bnoordhuis commentedon Aug 28, 2022
Cool, good to hear. I'll close this then.
bnoordhuis commentedon Aug 28, 2022
Oh, @tniessen, what are your thoughts on #42919 (comment)?