Skip to content

Commit d490b17

Browse files
mertcanaltinaduh95
authored andcommitted
src: handle null backing store in ArrayBufferViewContents::Read
Fixes: #62342 src: handle null backing store in ArrayBufferViewContents::Read PR-URL: #62343 Fixes: #62342 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 180c150 commit d490b17

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/util-inl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> abv) {
591591
static_assert(sizeof(T) == 1, "Only supports one-byte data at the moment");
592592
length_ = abv->ByteLength();
593593
if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) {
594-
data_ = static_cast<T*>(abv->Buffer()->Data()) + abv->ByteOffset();
594+
auto buf_data = abv->Buffer()->Data();
595+
data_ = buf_data != nullptr ? static_cast<T*>(buf_data) + abv->ByteOffset()
596+
: stack_storage_;
595597
} else {
596598
abv->CopyContents(stack_storage_, sizeof(stack_storage_));
597599
data_ = stack_storage_;

test/parallel/test-crypto-authenticated.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,3 +772,26 @@ for (const test of TEST_CASES) {
772772
decipher.final();
773773
}, /Unsupported state or unable to authenticate data/);
774774
}
775+
776+
// Refs: https://github.com/nodejs/node/issues/62342
777+
{
778+
const key = crypto.randomBytes(16);
779+
const nonce = crypto.randomBytes(13);
780+
781+
const cipher = crypto.createCipheriv('aes-128-ccm', key, nonce, {
782+
authTagLength: 16,
783+
});
784+
cipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 });
785+
cipher.update(new DataView(new ArrayBuffer(0)));
786+
cipher.final();
787+
const tag = cipher.getAuthTag();
788+
assert.strictEqual(tag.length, 16);
789+
790+
const decipher = crypto.createDecipheriv('aes-128-ccm', key, nonce, {
791+
authTagLength: 16,
792+
});
793+
decipher.setAuthTag(tag);
794+
decipher.setAAD(Buffer.alloc(0), { plaintextLength: 0 });
795+
decipher.update(new DataView(new ArrayBuffer(0)));
796+
decipher.final();
797+
}

0 commit comments

Comments
 (0)