Skip to content

Commit 2e4d37e

Browse files
marco-ippolitotargos
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 9d6af61 commit 2e4d37e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/crypto/crypto_cipher.cc

Lines 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 &&

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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy