{"record":{"id":"160dacad0a88b5d2","repo":"usebruno/bruno","slug":"getrandomvalues-invalid-typed-array-properties","errorCode":null,"errorMessage":"getRandomValues: Invalid typed array properties","messagePattern":"getRandomValues: Invalid typed array properties","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js","lineNumber":34,"sourceCode":"    'Uint16Array',\n    'Int32Array',\n    'Uint32Array',\n    'Float32Array',\n    'Float64Array',\n    'BigInt64Array',\n    'BigUint64Array'\n  ]);\n\n  if (!obj || typeof obj !== 'object') {\n    throw new TypeError('getRandomValues: Invalid typed array object');\n  }\n\n  if (typeof obj.type !== 'string' || !allowedConstructors.has(obj.type)) {\n    throw new TypeError(`getRandomValues: Invalid or unsupported typed array type: ${obj.type}`);\n  }\n\n  if (!obj.array || typeof obj.length !== 'number') {\n    throw new TypeError('getRandomValues: Invalid typed array properties');\n  }\n\n  const ctor = globalThis[obj.type];\n  if (typeof ctor !== 'function') {\n    throw new TypeError(`getRandomValues: Constructor ${obj.type} is not available`);\n  }\n\n  return new ctor(obj.array, 0, obj.length);\n}\n\nmodule.exports = {\n  serializeTypedArray,\n  deserializeTypedArray\n};\n","sourceCodeStart":16,"sourceCodeEnd":49,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js#L16-L49","documentation":"Thrown by deserializeTypedArray when the serialized object has a valid `type` but is missing the `array` field or has a non-number `length`. Both must be present and correctly typed to reconstruct the typed array.","triggerScenarios":"A serialized payload that was partially constructed or mutated — e.g. { type: 'Uint8Array' } with no array, or { type: 'Uint8Array', array: [...], length: '16' } (length as string).","commonSituations":"Manually editing or trimming the serialized object; a bug in serializeTypedArray callers; JSON round-trip that converted length to a string.","solutions":["Do not construct the serialized shape by hand — produce it via serializeTypedArray.","If you must, ensure both fields are present: { type: 'Uint8Array', array: [...], length: <number> }.","Validate before passing: `typeof obj.length === 'number' && Array.isArray(obj.array)`."],"exampleFix":"// before — length is a string after JSON round-trip\nconst bad = JSON.parse('{\"type\":\"Uint8Array\",\"array\":[1,2],\"length\":\"2\"}');\ncrypto.getRandomValues(bad);\n\n// after\nconst bad = JSON.parse('{\"type\":\"Uint8Array\",\"array\":[1,2],\"length\":2}');\n// or rebuild via serializeTypedArray(new Uint8Array(2))","handlingStrategy":"validation","validationCode":"function assertSerialized(obj) {\n  if (!Array.isArray(obj.array) || typeof obj.length !== 'number') {\n    throw new TypeError('serialized typed array malformed');\n  }\n}","typeGuard":"const isSerializedTypedArray = (v) => v && typeof v === 'object' && Array.isArray(v.array) && typeof v.length === 'number';","tryCatchPattern":"try { crypto.getRandomValues(arr); }\ncatch (err) {\n  if (/Invalid typed array properties/.test(err.message)) {\n    crypto.getRandomValues(new Uint8Array(16));\n  } else throw err;\n}","preventionTips":["Let serializeTypedArray build the shape; never hand-roll it.","Be wary of JSON round-trips converting numeric fields to strings."],"tags":["bruno-js","quickjs","sandbox","crypto","webcrypto","validation"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}