From 8104939980c04ec820b32aba63afb759b923d683 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Thu, 19 Mar 2026 23:44:57 +0300 Subject: [PATCH 1/2] src: handle null backing store in ArrayBufferViewContents::Read Fixes: https://github.com/nodejs/node/issues/62342 --- src/util-inl.h | 5 ++++- test/parallel/test-crypto-authenticated.js | 23 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/util-inl.h b/src/util-inl.h index f8cccfef6b65b3..a30d8be34f41d1 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -591,7 +591,10 @@ void ArrayBufferViewContents::Read(v8::Local abv) { static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment"); length_ = abv->ByteLength(); if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) { - data_ = static_cast(abv->Buffer()->Data()) + abv->ByteOffset(); + auto buf = abv->Buffer(); + data_ = buf->Data() != nullptr + ? static_cast(buf->Data()) + abv->ByteOffset() + : stack_storage_; } else { abv->CopyContents(stack_storage_, sizeof(stack_storage_)); data_ = stack_storage_; diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index e8fedf2d5d5072..9778ea548e81d7 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -772,3 +772,26 @@ for (const test of TEST_CASES) { decipher.final(); }, /Unsupported state or unable to authenticate data/); } + +// Refs: https://github.com/nodejs/node/issues/62342 +{ + const key = crypto.randomBytes(16); + const nonce = crypto.randomBytes(13); + + const cipher = crypto.createCipheriv('aes-128-ccm', key, nonce, { + authTagLength: 16, + }); + cipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 }); + cipher.update(new DataView(new ArrayBuffer(0))); + cipher.final(); + const tag = cipher.getAuthTag(); + assert.strictEqual(tag.length, 16); + + const decipher = crypto.createDecipheriv('aes-128-ccm', key, nonce, { + authTagLength: 16, + }); + decipher.setAuthTag(tag); + decipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 }); + decipher.update(new DataView(new ArrayBuffer(0))); + decipher.final(); +} From 53e837fe36cb0f7e0710f9868c0a18e85e9cce80 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Fri, 20 Mar 2026 16:44:29 +0300 Subject: [PATCH 2/2] Update util-inl.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: René --- src/util-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util-inl.h b/src/util-inl.h index a30d8be34f41d1..7d67cbe2a4b914 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -591,9 +591,9 @@ void ArrayBufferViewContents::Read(v8::Local abv) { static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment"); length_ = abv->ByteLength(); if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) { - auto buf = abv->Buffer(); - data_ = buf->Data() != nullptr - ? static_cast(buf->Data()) + abv->ByteOffset() + auto buf_data = abv->Buffer()->Data(); + data_ = buf_data != nullptr + ? static_cast(buf_data) + abv->ByteOffset() : stack_storage_; } else { abv->CopyContents(stack_storage_, sizeof(stack_storage_));