mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
crypto: convert getRandomValues views
Apply Web IDL view conversion before checking the integer array type, including shared and resizable backing-buffer restrictions. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66237 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
1 parent
529bd18c1a
commit
6bfd3924ff
4 files changed
+34
-2
No files matched your search
@@ -2027,7 +2027,8 @@ function getRandomValues(array) {
|
||||
const prefix = "Failed to execute 'getRandomValues' on 'Crypto'";
|
||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||
|
||||
return ReflectApply(_getRandomValues, this, arguments);
|
||||
array = convertSubtleArgument(prefix, 'ArrayBufferView', array, 0);
|
||||
return _getRandomValues(array);
|
||||
}
|
||||
|
||||
ObjectDefineProperties(
|
||||
|
||||
@@ -904,6 +904,14 @@ function getViewedArrayBuffer(V) {
|
||||
TypedArrayPrototypeGetBuffer(V) : DataViewPrototypeGetBuffer(V);
|
||||
}
|
||||
|
||||
converters.ArrayBufferView = (V, options = kEmptyObject) => {
|
||||
if (!ArrayBufferIsView(V)) {
|
||||
throw makeException('is not an ArrayBufferView.', options);
|
||||
}
|
||||
validateBufferSourceBacking(getViewedArrayBuffer(V), options);
|
||||
return V;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates [AllowShared] and [AllowResizable] backing-store constraints.
|
||||
* @param {ArrayBuffer|SharedArrayBuffer} buffer Backing buffer.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
for (const buffer of [
|
||||
new SharedArrayBuffer(8),
|
||||
new SharedArrayBuffer(8, { maxByteLength: 16 }),
|
||||
new ArrayBuffer(8, { maxByteLength: 16 }),
|
||||
]) {
|
||||
for (const Type of [Uint8Array, Float32Array, DataView]) {
|
||||
assert.throws(() => crypto.getRandomValues(new Type(buffer)), TypeError);
|
||||
}
|
||||
}
|
||||
|
||||
assert.throws(() => crypto.getRandomValues(new Proxy(new Uint8Array(8), {})),
|
||||
TypeError);
|
||||
@@ -9,8 +9,11 @@ const { Buffer } = require('buffer');
|
||||
const assert = require('assert');
|
||||
const { crypto } = globalThis;
|
||||
|
||||
for (const value of [undefined, null, '', 1, {}, [], new ArrayBuffer(1)]) {
|
||||
assert.throws(() => crypto.getRandomValues(value), TypeError);
|
||||
}
|
||||
|
||||
[
|
||||
undefined, null, '', 1, {}, [],
|
||||
new Float32Array(1),
|
||||
new Float64Array(1),
|
||||
new DataView(new ArrayBuffer(1)),
|
||||
|
||||
Reference in new issue
Block a user