diff --git a/src/util-inl.h b/src/util-inl.h index f8cccfef6b65b3..7d67cbe2a4b914 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_data = abv->Buffer()->Data(); + 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(); +}