src: handle null backing store in ArrayBufferViewContents::Read

Fixes: https://github.com/nodejs/node/issues/62342

src: handle null backing store in ArrayBufferViewContents::Read
PR-URL: https://github.com/nodejs/node/pull/62343
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Mert Can Altin authored and GitHub committed 2026-03-29 11:56:01 +00:00
1 parent cc967413c9
commit bdf75a6c4e
2 files changed
+26 -1

No files matched your search

+3 -1
View File
@@ -591,7 +591,9 @@ void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> 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<T*>(abv->Buffer()->Data()) + abv->ByteOffset();
auto buf_data = abv->Buffer()->Data();
data_ = buf_data != nullptr ? static_cast<T*>(buf_data) + abv->ByteOffset()
: stack_storage_;
} else {
abv->CopyContents(stack_storage_, sizeof(stack_storage_));
data_ = stack_storage_;
@@ -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();
}