Skip to content

Commit e46afa6

Browse files
Merge commit from fork
1 parent 5e07a67 commit e46afa6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/swift-planes-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"devalue": patch
3+
---
4+
5+
fix: validate input for typed arrays

src/parse.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ export function unflatten(parsed, revivers) {
126126
case 'BigInt64Array':
127127
case 'BigUint64Array': {
128128
const TypedArrayConstructor = globalThis[type];
129-
const typedArray = new TypedArrayConstructor(hydrate(value[1]));
129+
const buffer = hydrate(value[1]);
130+
if (!(buffer instanceof ArrayBuffer)) {
131+
throw new Error(`Invalid input, expected ArrayBuffer but got ${typeof buffer}`);
132+
}
133+
const typedArray = new TypedArrayConstructor(buffer);
130134

131135
hydrated[index] =
132136
value[2] !== undefined

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,11 @@ for (const [name, tests] of Object.entries(fixtures)) {
740740
}
741741

742742
const invalid = [
743+
{
744+
name: 'typed array with non-ArrayBuffer input',
745+
json: '[["Int8Array", 1], { "length": 2 }, 1000000000]',
746+
message: 'Invalid input, expected ArrayBuffer but got object'
747+
},
743748
{
744749
name: 'empty string',
745750
json: '',

0 commit comments

Comments
 (0)