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: #62343Fixes: #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

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎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
},/Unsupportedstateorunabletoauthenticatedata/);
774774
}
775+
776+
// Refs: https://github.com/nodejs/node/issues/62342
777+
{
778+
constkey=crypto.randomBytes(16);
779+
constnonce=crypto.randomBytes(13);
780+
781+
constcipher=crypto.createCipheriv('aes-128-ccm',key,nonce,{
782+
authTagLength: 16,
783+
});
784+
cipher.setAAD(Buffer.alloc(0),{plaintextLength: 0});
785+
cipher.update(newDataView(newArrayBuffer(0)));
786+
cipher.final();
787+
consttag=cipher.getAuthTag();
788+
assert.strictEqual(tag.length,16);
789+
790+
constdecipher=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(newDataView(newArrayBuffer(0)));
796+
decipher.final();
797+
}

0 commit comments

Comments
 (0)