Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fbf956

Browse filesBrowse files
marco-ippolitodanielleadams
authored andcommitted
crypto: fix CipherBase Update int32 overflow
PR-URL: #45769 Fixes: #45757 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent b5ad92f commit 2fbf956
Copy full SHA for 2fbf956

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_cipher.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_cipher.cc
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,11 @@ CipherBase::UpdateResult CipherBase::Update(
803803
if (kind_ == kDecipher && IsAuthenticatedMode())
804804
CHECK(MaybePassAuthTagToOpenSSL());
805805

806-
int buf_len = len + EVP_CIPHER_CTX_block_size(ctx_.get());
806+
const int block_size = EVP_CIPHER_CTX_block_size(ctx_.get());
807+
CHECK_GT(block_size, 0);
808+
if (len + block_size > INT_MAX) return kErrorState;
809+
int buf_len = len + block_size;
810+
807811
// For key wrapping algorithms, get output size by calling
808812
// EVP_CipherUpdate() with null output.
809813
if (kind_ == kCipher && mode == EVP_CIPH_WRAP_MODE &&
Collapse file

‎test/parallel/test-crypto-cipheriv-decipheriv.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-cipheriv-decipheriv.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,11 @@ for (let n = minIvLength; n < maxIvLength; n += 1) {
215215
() => crypto.createCipheriv('aes-128-ecb', Buffer.alloc(17), null),
216216
/Invalid key length/);
217217
}
218+
219+
{
220+
// https://github.com/nodejs/node/issues/45757
221+
// eslint-disable-next-line no-restricted-syntax
222+
assert.throws(() =>
223+
crypto.createCipheriv('aes-128-gcm', Buffer.alloc(16), Buffer.alloc(12))
224+
.update(Buffer.allocUnsafeSlow(2 ** 31 - 1)));
225+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.